@agile-team/mach-report 2.0.0 → 2.1.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 (77) hide show
  1. package/LICENSE +2 -4
  2. package/LICENSING.md +15 -0
  3. package/README.md +232 -76
  4. package/dist/ReportPreview-Dwdsyk9b.js +1558 -0
  5. package/dist/ReportPreview-VHAIfsz1.cjs +6 -0
  6. package/dist/index.cjs +5 -5
  7. package/dist/index.d.cts +738 -13
  8. package/dist/index.d.ts +738 -13
  9. package/dist/index.js +821 -631
  10. package/dist/pdf.cjs +47 -47
  11. package/dist/pdf.d.cts +155 -6
  12. package/dist/pdf.d.ts +155 -6
  13. package/dist/pdf.js +3542 -3466
  14. package/dist/plugin-Bl00j_CP.cjs +1 -0
  15. package/dist/plugin-DVScnZ4C.js +25 -0
  16. package/dist/report-params-BB85g7mg.js +10 -0
  17. package/dist/report-params-D1NeY-eR.cjs +1 -0
  18. package/dist/sql.cjs +65 -64
  19. package/dist/sql.d.cts +109 -5
  20. package/dist/sql.d.ts +109 -5
  21. package/dist/sql.js +7947 -7922
  22. package/dist/style.css +1 -1
  23. package/dist/vue/async.d.cts +769 -320
  24. package/dist/vue/async.d.ts +769 -320
  25. package/dist/vue/index.d.cts +1321 -14
  26. package/dist/vue/index.d.ts +1321 -14
  27. package/dist/vue-async.cjs +1 -1
  28. package/dist/vue-async.js +11 -12
  29. package/dist/vue.cjs +1 -1
  30. package/dist/vue.js +129 -49
  31. package/dist/xlsx.cjs +20 -20
  32. package/dist/xlsx.d.cts +2292 -5
  33. package/dist/xlsx.d.ts +2292 -5
  34. package/dist/xlsx.js +5452 -5443
  35. package/package.json +6 -2
  36. package/dist/ReportPreview-Cr0IH1Rz.cjs +0 -6
  37. package/dist/ReportPreview-DwknBgsJ.js +0 -1266
  38. package/dist/builder/template-builder.d.ts +0 -69
  39. package/dist/defaults.d.ts +0 -23
  40. package/dist/format.d.ts +0 -48
  41. package/dist/layout/paginate.d.ts +0 -97
  42. package/dist/layout/textwrap.d.ts +0 -36
  43. package/dist/pdf/font-loader.d.ts +0 -6
  44. package/dist/pdf/index.d.ts +0 -2
  45. package/dist/pdf/render-pdf.d.ts +0 -25
  46. package/dist/plugin-Cj3c2wJc.cjs +0 -1
  47. package/dist/plugin-DJf_6_fl.js +0 -18
  48. package/dist/render/canvas.d.ts +0 -76
  49. package/dist/render/dom.d.ts +0 -10
  50. package/dist/render/grid-geometry.d.ts +0 -41
  51. package/dist/render/style.d.ts +0 -33
  52. package/dist/render/window.d.ts +0 -23
  53. package/dist/schema/render-plan.d.ts +0 -88
  54. package/dist/schema/validate.d.ts +0 -15
  55. package/dist/sql/ast-check.d.ts +0 -14
  56. package/dist/sql/compile.d.ts +0 -31
  57. package/dist/sql/expr.d.ts +0 -21
  58. package/dist/sql/index.d.ts +0 -4
  59. package/dist/sql/tokenizer.d.ts +0 -25
  60. package/dist/units.d.ts +0 -11
  61. package/dist/vue/ReportParamPanel.d.ts +0 -19
  62. package/dist/vue/ReportPreview.d.ts +0 -200
  63. package/dist/vue/ReportToolbar.d.ts +0 -42
  64. package/dist/vue/adapters.d.ts +0 -34
  65. package/dist/vue/composables/useHighlight.d.ts +0 -8
  66. package/dist/vue/composables/usePageWindow.d.ts +0 -25
  67. package/dist/vue/composables/usePrintExport.d.ts +0 -40
  68. package/dist/vue/composables/useReportSearch.d.ts +0 -73
  69. package/dist/vue/composables/useZoom.d.ts +0 -15
  70. package/dist/vue/config.d.ts +0 -108
  71. package/dist/vue/controller.d.ts +0 -29
  72. package/dist/vue/errors.d.ts +0 -16
  73. package/dist/vue/injection-keys.d.ts +0 -14
  74. package/dist/vue/local-adapter.d.ts +0 -11
  75. package/dist/vue/pdf-exporter.d.ts +0 -13
  76. package/dist/vue/plugin.d.ts +0 -332
  77. package/dist/xlsx/render-xlsx.d.ts +0 -20
package/dist/index.js CHANGED
@@ -1,90 +1,91 @@
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 { h as ie, R as pe, D as Q, w as Z, L as ee, i as He, r as q, m as Re, a as V, b as Me, c as Y, d as te, p as K, e as Ne, f as we, g as Be, P as X } from "./style-DnmtG7Gl.js";
2
+ import { C as St, j as vt, k as Pt, M as Tt, S as xt, l as $t, n as kt, o as Et, q as Ct, s as At, t as Ht } from "./style-DnmtG7Gl.js";
3
+ import { r as Le } from "./grid-geometry-Bs8QXz1X.js";
4
+ import { g as ze } from "./report-params-BB85g7mg.js";
5
+ function Fe(e) {
5
6
  const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
6
7
  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;
8
+ const r = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
9
+ return Number.isNaN(r.getTime()) ? null : r;
9
10
  }
10
- const o = new Date(e);
11
- return Number.isNaN(o.getTime()) ? null : o;
11
+ const n = new Date(e);
12
+ return Number.isNaN(n.getTime()) ? null : n;
12
13
  }
13
- function Q(e, t) {
14
+ function re(e, t) {
14
15
  return e.toLocaleString("en-US", {
15
16
  minimumFractionDigits: t,
16
17
  maximumFractionDigits: t
17
18
  });
18
19
  }
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()));
20
+ function De(e, t) {
21
+ const n = (r) => String(r).padStart(2, "0");
22
+ 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
23
  }
23
- function Re(e, t, o) {
24
- return o != null ? t ? Q(e, o) : e.toFixed(o) : t ? Q(e) : String(e);
24
+ function We(e, t, n) {
25
+ return n != null ? t ? re(e, n) : e.toFixed(n) : t ? re(e) : String(e);
25
26
  }
26
- function ee(e) {
27
+ function oe(e) {
27
28
  const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
28
29
  return Number.isFinite(t) ? t : null;
29
30
  }
30
- function fe(e, t) {
31
+ function be(e, t) {
31
32
  if (e == null || e === "" || !t) return String(e ?? "");
32
33
  switch (t.kind) {
33
34
  case "number": {
34
- const o = ee(e);
35
- return o == null ? String(e) : Re(o, t.thousands === !0, t.digits);
35
+ const n = oe(e);
36
+ return n == null ? String(e) : We(n, t.thousands === !0, t.digits);
36
37
  }
37
38
  case "percent": {
38
- const o = ee(e);
39
- return o == null ? String(e) : `${Q(o * 100, t.digits ?? 2)}%`;
39
+ const n = oe(e);
40
+ return n == null ? String(e) : `${re(n * 100, t.digits ?? 2)}%`;
40
41
  }
41
42
  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);
43
+ const n = t.pattern ?? "YYYY-MM-DD", r = e instanceof Date ? e : Fe(String(e));
44
+ return r ? De(r, n) : String(e);
44
45
  }
45
46
  default:
46
47
  return String(e);
47
48
  }
48
49
  }
49
- function Be(e, t) {
50
- const o = e[t.field];
51
- if (o == null || o === "") return !1;
50
+ function je(e, t) {
51
+ const n = e[t.field];
52
+ if (n == null || n === "") return !1;
52
53
  if (typeof t.value == "number") {
53
- const a = ee(o);
54
- if (a == null) return !1;
54
+ const i = oe(n);
55
+ if (i == null) return !1;
55
56
  switch (t.op) {
56
57
  case ">":
57
- return a > t.value;
58
+ return i > t.value;
58
59
  case ">=":
59
- return a >= t.value;
60
+ return i >= t.value;
60
61
  case "<":
61
- return a < t.value;
62
+ return i < t.value;
62
63
  case "<=":
63
- return a <= t.value;
64
+ return i <= t.value;
64
65
  case "==":
65
- return a === t.value;
66
+ return i === t.value;
66
67
  case "!=":
67
- return a !== t.value;
68
+ return i !== t.value;
68
69
  }
69
70
  }
70
- const n = String(o), r = String(t.value);
71
+ const r = String(n), o = String(t.value);
71
72
  switch (t.op) {
72
73
  case "==":
73
- return n === r;
74
+ return r === o;
74
75
  case "!=":
75
- return n !== r;
76
+ return r !== o;
76
77
  case ">":
77
- return n > r;
78
+ return r > o;
78
79
  case ">=":
79
- return n >= r;
80
+ return r >= o;
80
81
  case "<":
81
- return n < r;
82
+ return r < o;
82
83
  case "<=":
83
- return n <= r;
84
+ return r <= o;
84
85
  }
85
86
  return !1;
86
87
  }
87
- const ze = /* @__PURE__ */ new Set([
88
+ const Oe = /* @__PURE__ */ new Set([
88
89
  "text",
89
90
  "image",
90
91
  "barcode",
@@ -94,87 +95,89 @@ const ze = /* @__PURE__ */ new Set([
94
95
  "rect",
95
96
  "ellipse"
96
97
  ]);
97
- function D(e) {
98
+ function _(e) {
98
99
  return typeof e == "object" && e !== null && !Array.isArray(e);
99
100
  }
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)}` });
101
+ function _e(e, t, n, r) {
102
+ const o = e[t];
103
+ (typeof o != "number" || !Number.isFinite(o)) && r.push({ path: `${n}.${t}`, message: `应为有限数字,实际 ${JSON.stringify(o)}` });
103
104
  }
104
- function ue(e, t, o, n = []) {
105
- if (!D(e)) {
106
- o.push({ path: t, message: "组件应为对象" });
105
+ function ye(e, t, n, r = []) {
106
+ if (!_(e)) {
107
+ n.push({ path: t, message: "组件应为对象" });
107
108
  return;
108
109
  }
109
- const r = e.kind;
110
- typeof r != "string" ? o.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : ze.has(r) || n.push({
110
+ const o = e.kind;
111
+ typeof o != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : Oe.has(o) || r.push({
111
112
  path: `${t}.kind`,
112
- message: `未知组件类型 ${JSON.stringify(r)},将以兜底方式渲染`
113
+ message: `未知组件类型 ${JSON.stringify(o)},将以兜底方式渲染`
113
114
  });
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: "行应为数组" });
115
+ for (const s of ["leftMm", "topMm", "widthMm", "heightMm"])
116
+ _e(e, s, t, n);
117
+ typeof e.leftMm == "number" && e.leftMm < -100 && n.push({ path: `${t}.leftMm`, message: "几何数值异常(leftMm<-100)" });
118
+ for (const s of ["widthMm", "heightMm"])
119
+ typeof e[s] == "number" && e[s] < 0 && n.push({ path: `${t}.${s}`, message: "组件尺寸不能为负数" });
120
+ const i = e.grid;
121
+ i !== void 0 && (!_(i) || !Array.isArray(i.cells) ? n.push({ path: `${t}.grid.cells`, message: "grid.cells 应为二维数组" }) : i.cells.forEach((s, l) => {
122
+ if (!Array.isArray(s)) {
123
+ n.push({ path: `${t}.grid.cells.${l}`, message: "行应为数组" });
121
124
  return;
122
125
  }
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);
126
+ s.forEach((d, h) => {
127
+ d != null && _(d) && Array.isArray(d.children) && d.children.forEach((m, c) => {
128
+ ye(m, `${t}.grid.cells.${l}.${h}.children.${c}`, n, r);
126
129
  });
127
130
  });
128
131
  }));
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 应为数组" }));
132
+ const a = e.richParagraphs;
133
+ a !== void 0 && (Array.isArray(a) ? a.forEach((s, l) => {
134
+ (!_(s) || !Array.isArray(s.segments)) && n.push({ path: `${t}.richParagraphs.${l}`, message: "段落缺少 segments 数组" });
135
+ }) : n.push({ path: `${t}.richParagraphs`, message: "richParagraphs 应为数组" }));
133
136
  }
134
- function Fe(e, t, o, n = []) {
135
- if (!D(e)) {
136
- o.push({ path: t, message: "页应为对象" });
137
+ function Ie(e, t, n, r = []) {
138
+ if (!_(e)) {
139
+ n.push({ path: t, message: "页应为对象" });
137
140
  return;
138
141
  }
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
- );
142
+ const o = e.pageWidthMm, i = e.pageHeightMm;
143
+ (typeof o != "number" || !(o > 0 && o < 3e3)) && n.push({ path: `${t}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof i != "number" || !(i > 0 && i < 5e3)) && n.push({ path: `${t}.pageHeightMm`, message: `页高非法: ${JSON.stringify(i)}` });
144
+ const a = e.components;
145
+ Array.isArray(a) ? Array.isArray(a) && a.forEach(
146
+ (s, l) => ye(s, `${t}.components.${l}`, n, r)
147
+ ) : n.push({ path: `${t}.components`, message: "components 应为数组" });
145
148
  }
146
- function De(e) {
147
- const t = [], o = [], n = D(e) ? e.pages : void 0;
148
- if (!Array.isArray(n))
149
+ function Se(e) {
150
+ const t = [], n = [], r = _(e) ? e.pages : void 0;
151
+ if (!Array.isArray(r))
149
152
  t.push({
150
153
  path: "$.pages",
151
154
  message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
152
155
  });
153
156
  else {
154
- n.forEach((a, l) => Fe(a, `$.pages.${l}`, t, o)), n.length > 2e3 && o.push({
157
+ r.forEach((i, a) => Ie(i, `$.pages.${a}`, t, n)), r.length > 2e3 && n.push({
155
158
  path: "$.pages",
156
- message: `页数异常大(${n.length} 页),渲染与打印耗时可能显著增加`
159
+ message: `页数异常大(${r.length} 页),渲染与打印耗时可能显著增加`
157
160
  });
158
- const r = n.reduce(
159
- (a, l) => a + (D(l) && Array.isArray(l.components) ? l.components.length : 0),
161
+ const o = r.reduce(
162
+ (i, a) => i + (_(a) && Array.isArray(a.components) ? a.components.length : 0),
160
163
  0
161
164
  );
162
- r > 5e4 && o.push({
165
+ o > 5e4 && n.push({
163
166
  path: "$.pages",
164
- message: `组件总数异常大(${r} 个),可能触发浏览器性能限制`
167
+ message: `组件总数异常大(${o} 个),可能触发浏览器性能限制`
165
168
  });
166
169
  }
167
- return { ok: t.length === 0, errors: t, warnings: o };
170
+ return { ok: t.length === 0, errors: t, warnings: n };
168
171
  }
169
- function nt(e) {
170
- const t = De(e);
172
+ function dt(e) {
173
+ const t = Se(e);
171
174
  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}`);
175
+ const n = t.errors.slice(0, 3).map((r) => `${r.path}: ${r.message}`).join("; ");
176
+ throw new Error(`渲染计划校验失败(${t.errors.length} 处): ${n}`);
174
177
  }
175
178
  return e.pages;
176
179
  }
177
- function de(e) {
180
+ function fe(e) {
178
181
  return {
179
182
  widthMm: e.widthMm,
180
183
  heightMm: e.heightMm,
@@ -185,14 +188,14 @@ function de(e) {
185
188
  components: []
186
189
  };
187
190
  }
188
- function _e(e, t) {
191
+ function Ge(e, t) {
189
192
  return t.heightMm - (e.marginBottomMm ?? t.marginBottomMm);
190
193
  }
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
+ function Ye(e, t) {
195
+ const r = (e.fontSizePt ?? Q) * ee * 25.4 / 72, o = (e.paddingMm ?? 1) * 2;
196
+ return Math.max(e.rowHeightMm ?? 0, t * r + o);
194
197
  }
195
- function pe(e) {
198
+ function ve(e) {
196
199
  if (e == null) return "";
197
200
  if (typeof e == "string") return e;
198
201
  if (typeof e == "number") return String(e);
@@ -204,239 +207,257 @@ function pe(e) {
204
207
  return String(e);
205
208
  }
206
209
  }
207
- 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) => ({
210
+ function qe(e, t) {
211
+ const n = e.fontSizePt ?? Q, r = e.paddingMm ?? 1, o = e.columns.map(
212
+ (g) => ({ fontSize: n, align: "left", verticalAlign: "middle", ...g.style })
213
+ ), i = e.columns.map(
214
+ (g) => ({
215
+ fontSize: n,
212
216
  bold: e.headerBold ?? !0,
213
217
  align: "center",
214
218
  verticalAlign: "middle",
215
219
  backgroundColor: e.headerBackgroundColor,
216
- ...s.style || {}
220
+ ...g.style || {}
217
221
  })
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 },
222
+ ), a = e.columns.map((g) => g.header), s = a.map(
223
+ (g, f) => Z(
224
+ g,
225
+ e.columns[f].widthMm - r * 2,
226
+ { fontSizePt: n, bold: e.headerBold ?? !0 },
223
227
  t
224
228
  )
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 };
229
+ ), l = Math.max(...s.map((g) => g.length), 1), d = Ye(e, l), h = a.map((g, f) => ({
230
+ text: g,
231
+ style: i[f]
232
+ })), m = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, c = e.columns.map((g) => g.widthMm);
229
233
  return {
230
- fontSizePt: o,
231
- paddingMm: n,
232
- cellStyles: r,
233
- borderStyle: h,
234
- headerHeightMm: c,
235
- headerGrid: { cells: [m], rowHeightsMm: [c] },
234
+ fontSizePt: n,
235
+ paddingMm: r,
236
+ cellStyles: o,
237
+ borderStyle: m,
238
+ headerHeightMm: d,
239
+ headerGrid: {
240
+ cells: [h],
241
+ colWidthsMm: c,
242
+ rowHeightsMm: [d]
243
+ },
244
+ colWidthsMm: c,
236
245
  columns: e.columns
237
246
  };
238
247
  }
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]);
248
+ function ge(e, t, n) {
249
+ const r = e.columns, o = new Array(r.length);
250
+ let i = 1;
251
+ for (let h = 0; h < r.length; h++) {
252
+ const m = r[h];
253
+ o[h] = m.format ? be(t[m.field], m.format) : ve(t[m.field]);
245
254
  }
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,
255
+ const a = new Array(r.length);
256
+ for (let h = 0; h < r.length; h++) {
257
+ const m = Z(
258
+ o[h],
259
+ r[h].widthMm - e.paddingMm * 2,
251
260
  { fontSizePt: e.fontSizePt },
252
- o
261
+ n
253
262
  );
254
- l[m] = h, h.length > a && (a = h.length);
263
+ a[h] = m, m.length > i && (i = m.length);
255
264
  }
256
- const i = e.fontSizePt * K * 25.4 / 72, d = Math.max(
265
+ const s = e.fontSizePt * ee * 25.4 / 72, l = Math.max(
257
266
  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 };
267
+ i * s + e.paddingMm * 2
268
+ ), d = new Array(r.length);
269
+ for (let h = 0; h < r.length; h++) {
270
+ const m = r[h];
271
+ let c = e.cellStyles[h];
272
+ if (m.rules) {
273
+ for (const g of m.rules)
274
+ if (je(t, g.when)) {
275
+ c = { ...c ?? {}, ...g.style };
267
276
  break;
268
277
  }
269
278
  }
270
- c[m] = { text: r[m], style: s };
279
+ d[h] = { text: o[h], style: c };
271
280
  }
272
- return { grid: { cells: [c], rowHeightsMm: [d] }, heightMm: d };
281
+ return {
282
+ grid: { cells: [d], colWidthsMm: e.colWidthsMm, rowHeightsMm: [l] },
283
+ heightMm: l
284
+ };
273
285
  }
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 = [];
278
- 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
286
+ function Ve(e, t, n = {}) {
287
+ const r = typeof n == "number" ? { mmPerRow: n } : n, o = r.mmPerRow ?? 0, i = r.measurer ?? ie, a = [], s = [];
288
+ let l = 0;
289
+ const d = (m) => `${m}_${(++l).toString(36)}`, h = [];
290
+ for (const m of e.pages) {
291
+ const c = fe(m), g = () => Ge(m, c), f = c.marginTopMm, y = [], P = () => {
292
+ if (s.push({
293
+ pageWidthMm: c.widthMm,
294
+ pageHeightMm: c.heightMm,
295
+ marginTopMm: c.marginTopMm,
296
+ marginBottomMm: c.marginBottomMm,
297
+ marginLeftMm: c.marginLeftMm,
298
+ marginRightMm: c.marginRightMm,
299
+ components: c.components
288
300
  }), y.length > 0) {
289
- const P = i.length;
290
- for (const b of y) {
301
+ const x = s.length;
302
+ for (const M of y) {
291
303
  const v = {
292
- ...b,
293
- text: String(b.text ?? "").replace(/\{page\}/g, String(P))
304
+ ...M,
305
+ text: String(M.text ?? "").replace(/\{page\}/g, String(x))
294
306
  };
295
- i[i.length - 1].components.push(v), v.text.includes("{totalPages}") && m.push(v);
307
+ s[s.length - 1].components.push(v), v.text.includes("{totalPages}") && h.push(v);
296
308
  }
297
309
  }
298
310
  };
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);
311
+ for (const x of m.components) {
312
+ if (x.kind !== "list") {
313
+ if (x.kind === "text" && typeof x.text == "string") {
314
+ const b = x.text;
315
+ if (b.includes("{page}") || b.includes("{totalPages}")) {
316
+ y.push(x);
305
317
  continue;
306
318
  }
307
319
  }
308
- s.components.push(P);
320
+ c.components.push(x);
309
321
  continue;
310
322
  }
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
- }, _ = {
323
+ const M = x, v = t[M.dataset];
324
+ Array.isArray(v) || a.push(`数据集 ${M.dataset} 未提供数据,列表 ${M.id ?? ""} 输出为空`);
325
+ const u = Array.isArray(v) ? v : [], T = M.columns.reduce((b, p) => b + p.widthMm, 0), I = T > M.widthMm ? M.widthMm / T : 1, E = I === 1 ? M : { ...M, columns: M.columns.map((b) => ({ ...b, widthMm: b.widthMm * I })) }, $ = {
326
+ ...qe(E, i),
327
+ rowHeightFloorMm: E.rowHeightMm ?? 0
328
+ }, G = {
317
329
  kind: "rect",
318
- leftMm: b.leftMm,
330
+ leftMm: M.leftMm,
319
331
  topMm: 0,
320
- widthMm: b.widthMm,
332
+ widthMm: M.widthMm,
321
333
  heightMm: $.headerHeightMm,
322
334
  grid: $.headerGrid,
323
- nid: c("listh"),
335
+ nid: d("listh"),
324
336
  style: $.borderStyle
325
337
  };
326
- let u = b.topMm;
327
- const A = (p, M) => {
328
- p.components.push({ ..._, topMm: M });
338
+ let w = M.topMm;
339
+ const H = (b, p) => {
340
+ b.components.push({ ...G, topMm: p });
329
341
  };
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;
342
+ H(c, w), w += $.headerHeightMm + o;
343
+ const B = (b) => {
344
+ if (w + b > g()) {
345
+ P();
346
+ const p = fe(m);
347
+ c.components = p.components, c.heightMm = p.heightMm, E.headerEveryPage !== !1 ? (H(c, M.topMm), w = M.topMm + $.headerHeightMm) : w = f;
336
348
  }
337
- }, w = (p, M, T) => {
338
- R(M), s.components.push({
349
+ }, S = (b, p, k) => {
350
+ const C = E.headerEveryPage !== !1 ? M.topMm + $.headerHeightMm : f, z = g() - C;
351
+ p > z && a.push(
352
+ `列表 ${M.id ?? M.dataset} 行高 ${p.toFixed(2)}mm 超出单页可用高度 ${z.toFixed(2)}mm,预览与打印可能截断内容`
353
+ ), B(p), c.components.push({
339
354
  kind: "rect",
340
- leftMm: b.leftMm,
341
- topMm: u,
342
- widthMm: b.widthMm,
343
- heightMm: M,
344
- grid: p,
345
- nid: c(T),
355
+ leftMm: M.leftMm,
356
+ topMm: w,
357
+ widthMm: M.widthMm,
358
+ heightMm: p,
359
+ grid: b,
360
+ nid: d(k),
346
361
  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 });
362
+ }), w += p;
363
+ }, R = () => ge($, {}, i).heightMm, A = (b, p, k, C) => {
364
+ const z = [], de = Math.max(1, Math.min(C, E.columns.length)), me = { fontSize: $.fontSizePt, ...k };
365
+ z.push({ text: b, colSpan: de, style: { bold: !0, ...me } });
366
+ for (let ne = de; ne < E.columns.length; ne++) {
367
+ const Ae = E.columns[ne];
368
+ z.push({ text: p.get(Ae.field) ?? "", style: me });
354
369
  }
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);
370
+ const Ce = $.fontSizePt * ee * 25.4 / 72, he = Math.max($.rowHeightFloorMm, Ce + $.paddingMm * 2);
371
+ return {
372
+ grid: { cells: [z], colWidthsMm: $.colWidthsMm, rowHeightsMm: [he] },
373
+ heightMm: he
374
+ };
375
+ }, j = (b, p) => {
376
+ let k = 0;
377
+ for (const C of b) {
378
+ const z = typeof C[p] == "number" ? C[p] : Number(C[p]);
379
+ Number.isFinite(z) && (k += z);
362
380
  }
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]);
381
+ return k;
382
+ }, U = (b, p) => {
383
+ const k = E.columns.find((C) => C.field === p);
384
+ return be(j(b, p), k?.format ?? { kind: "number", thousands: !0 });
385
+ }, L = E.groupBy, le = (b) => {
386
+ const p = E.columns.findIndex((k) => b.includes(k.field));
387
+ return p > 0 ? p : 1;
388
+ }, J = [];
389
+ if (L) {
390
+ const b = /* @__PURE__ */ new Map();
391
+ for (const p of u) {
392
+ const k = ve(p[L.field]), C = b.get(k);
393
+ C ? C.push(p) : b.set(k, [p]);
373
394
  }
374
- for (const [M, T] of p) {
375
- O.push({
395
+ for (const [p, k] of b) {
396
+ J.push({
376
397
  kind: "groupHeader",
377
- label: (B.headerTemplate ?? "{value}").replace(/\{value\}/g, M)
398
+ label: (L.headerTemplate ?? "{value}").replace(/\{value\}/g, p)
378
399
  });
379
- for (const x of T) O.push({ kind: "row", row: x });
380
- B.subtotal && B.subtotal.length > 0 && O.push({
400
+ for (const C of k) J.push({ kind: "row", row: C });
401
+ L.subtotal && L.subtotal.length > 0 && J.push({
381
402
  kind: "subtotal",
382
- label: B.subtotalLabel ?? "小计",
383
- rows: T
403
+ label: L.subtotalLabel ?? "小计",
404
+ rows: k
384
405
  });
385
406
  }
386
407
  } 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,
408
+ for (const b of u) J.push({ kind: "row", row: b });
409
+ const ce = R();
410
+ for (const b of J)
411
+ if (b.kind === "row") {
412
+ const p = ge($, b.row, i);
413
+ S(p.grid, p.heightMm, "listr");
414
+ } else if (b.kind === "groupHeader") {
415
+ const p = A(
416
+ b.label,
396
417
  /* @__PURE__ */ new Map(),
397
- B?.headerStyle ?? {},
398
- k.columns.length
418
+ L?.headerStyle ?? {},
419
+ E.columns.length
399
420
  );
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
421
+ L?.keepWithNext !== !1 && w + p.heightMm + ce > g() && B(p.heightMm + ce), S(p.grid, p.heightMm, "listg");
422
+ } else if (b.kind === "subtotal") {
423
+ const p = /* @__PURE__ */ new Map();
424
+ for (const C of L.subtotal ?? []) p.set(C, U(b.rows, C));
425
+ const k = A(
426
+ b.label,
427
+ p,
428
+ L?.subtotalStyle ?? {},
429
+ le(L.subtotal ?? [])
409
430
  );
410
- w(T.grid, T.heightMm, "listst");
431
+ S(k.grid, k.heightMm, "listst");
411
432
  }
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));
417
- const x = C(
418
- p?.label ?? "合计",
419
- T,
420
- p?.style ?? {},
421
- re
433
+ if (E.grandTotal) {
434
+ const b = typeof E.grandTotal == "object" ? E.grandTotal : void 0, p = b?.fields ?? L?.subtotal ?? [];
435
+ if (p.length > 0) {
436
+ const k = /* @__PURE__ */ new Map();
437
+ for (const z of p) k.set(z, U(u, z));
438
+ const C = A(
439
+ b?.label ?? "合计",
440
+ k,
441
+ b?.style ?? {},
442
+ le(p)
422
443
  );
423
- w(x.grid, x.heightMm, "listgt");
444
+ S(C.grid, C.heightMm, "listgt");
424
445
  } else
425
- l.push(`列表 ${b.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
446
+ a.push(`列表 ${M.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
426
447
  }
427
448
  }
428
- E();
449
+ P();
429
450
  }
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)));
451
+ for (const m of h) {
452
+ const c = m.text;
453
+ typeof c == "string" && c.includes("{totalPages}") && (m.text = c.replace(/\{totalPages\}/g, String(s.length)));
433
454
  }
434
455
  return {
435
- plan: { schemaVersion: xe, pages: i },
436
- warnings: l
456
+ plan: { schemaVersion: pe, pages: s },
457
+ warnings: a
437
458
  };
438
459
  }
439
- const je = {
460
+ const Je = {
440
461
  root: "mr-root",
441
462
  page: "mr-page",
442
463
  comp: "mr-comp",
@@ -454,404 +475,404 @@ const je = {
454
475
  unknown: "mr-unknown"
455
476
  };
456
477
  function N(e, t) {
457
- return t?.classNames?.[e] ?? je[e];
478
+ return t?.classNames?.[e] ?? Je[e];
458
479
  }
459
- class z {
480
+ class F {
460
481
  constructor() {
461
482
  this.props = [];
462
483
  }
463
- add(t, o) {
464
- return o == null || o === !1 || o === "" ? this : (this.props.push([t, String(o)]), this);
484
+ add(t, n) {
485
+ return n == null || n === !1 || n === "" ? this : (this.props.push([t, String(n)]), this);
465
486
  }
466
- mm(t, o, n, r = 2) {
467
- return this.add(t, `${I(Ce(o, n), r)}px`);
487
+ mm(t, n, r, o = 2) {
488
+ return this.add(t, `${q(Re(n, r), o)}px`);
468
489
  }
469
490
  toString() {
470
491
  let t = "";
471
- for (const [o, n] of this.props)
472
- t += `${o}:${n};`;
492
+ for (const [n, r] of this.props)
493
+ t += `${n}:${r};`;
473
494
  return t;
474
495
  }
475
496
  applyTo(t) {
476
- const o = this.toString();
477
- o && (t.style.cssText = o);
497
+ const n = this.toString();
498
+ n && (t.style.cssText = n);
478
499
  }
479
500
  }
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`);
501
+ function Pe(e, t, n) {
502
+ const r = t.style || {};
503
+ e.add("color", r.color).add("background-color", r.backgroundColor).add("font-family", r.fontFamily).add("font-weight", r.bold ? "700" : void 0).add("font-style", r.italic ? "italic" : void 0).add("text-decoration", r.underline ? "underline" : void 0).add("letter-spacing", r.letterSpacing != null ? `${r.letterSpacing}pt` : void 0).add("opacity", r.opacity != null ? String(r.opacity) : void 0).add("transform", r.rotateDeg ? `rotate(${r.rotateDeg}deg)` : void 0);
504
+ const o = V(r, n);
505
+ e.add("font-size", `${q(o.fontSizePx, 2)}px`);
485
506
  }
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);
507
+ function Ue(e, t, n, r, o) {
508
+ const i = o.createElement("table");
509
+ if (i.className = N("grid", r), new F().add("width", "100%").add("height", "100%").add("border-collapse", "collapse").add("table-layout", e.colWidthsMm ? "fixed" : "auto").applyTo(i), e.colWidthsMm) {
510
+ const d = o.createElement("colgroup");
511
+ for (const h of e.colWidthsMm) {
512
+ const m = o.createElement("col");
513
+ new F().mm("width", h, n).applyTo(m), d.appendChild(m);
493
514
  }
494
- a.appendChild(c);
515
+ i.appendChild(d);
495
516
  }
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`);
517
+ const a = te(t.style), s = Y(t.style), l = a.inner ? `${q(s.widthPt * n / 72, 2)}px solid ${s.color}` : "";
518
+ return e.cells.forEach((d, h) => {
519
+ const m = o.createElement("tr");
520
+ m.className = N("row", r), e.rowHeightsMm?.[h] != null && new F().mm("height", e.rowHeightsMm[h], n).applyTo(m), (d || []).forEach((c) => {
521
+ const g = o.createElement("td");
522
+ g.className = N("cell", r), c?.colSpan && (g.colSpan = c.colSpan), c?.rowSpan && (g.rowSpan = c.rowSpan);
523
+ const f = new F();
524
+ if (l && f.add("border", l), c?.style) {
525
+ const y = c.style;
526
+ f.add("text-align", y.align).add("vertical-align", y.verticalAlign).add("background-color", y.backgroundColor).add("color", y.color).add("font-weight", y.bold ? "700" : void 0), f.add("font-size", `${q(V(y, n).fontSizePx, 2)}px`);
506
527
  }
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;
528
+ if (f.applyTo(g), c?.text != null && (g.textContent = c.text), c?.children?.length)
529
+ for (const y of c.children)
530
+ g.appendChild(Te(y, n, r, o));
531
+ m.appendChild(g);
532
+ }), i.appendChild(m);
533
+ }), i;
513
534
  }
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(
535
+ function Ke(e, t, n, r) {
536
+ const o = r.createElement("div");
537
+ o.className = N("text", n);
538
+ const i = e.style || {}, a = new F().add("text-align", i.align).add("display", "flex").add("flex-direction", "column").add(
518
539
  "justify-content",
519
- a.verticalAlign === "middle" ? "center" : a.verticalAlign === "bottom" ? "flex-end" : "flex-start"
540
+ i.verticalAlign === "middle" ? "center" : i.verticalAlign === "bottom" ? "flex-end" : "flex-start"
520
541
  ).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);
542
+ if (Pe(a, e, t), a.applyTo(o), Me(e)) {
543
+ const s = r.createElement("div");
544
+ s.className = N("rich", n);
545
+ for (const l of e.richParagraphs) {
546
+ const d = r.createElement("div");
547
+ d.className = N("paragraph", n), new F().add("text-align", l.align).add("line-height", l.lineHeight != null ? String(l.lineHeight) : void 0).mm("margin-top", l.spaceBeforeMm ?? 0, t).mm("margin-bottom", l.spaceAfterMm ?? 0, t).mm("text-indent", l.indentMm ?? 0, t).applyTo(d);
548
+ for (const m of l.segments || []) {
549
+ const c = r.createElement("span");
550
+ if (c.className = N("segment", n), c.textContent = m.kind === "field" ? m.field ?? "" : m.text ?? "", m.style) {
551
+ const g = new F().add("color", m.style.color).add("font-weight", m.style.bold ? "700" : void 0);
552
+ g.add("font-size", `${q(V(m.style, t).fontSizePx, 2)}px`), g.applyTo(c);
532
553
  }
533
- c.appendChild(s);
554
+ d.appendChild(c);
534
555
  }
535
- i.appendChild(c);
556
+ s.appendChild(d);
536
557
  }
537
- return r.appendChild(i), r;
558
+ return o.appendChild(s), o;
538
559
  }
539
560
  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);
561
+ const s = r.createElement("div");
562
+ s.className = N("lines", n), i.lineHeight != null && new F().add("line-height", String(i.lineHeight)).applyTo(s);
563
+ for (const l of e.lines) {
564
+ const d = r.createElement("div");
565
+ d.className = N("line", n), d.textContent = l, s.appendChild(d);
545
566
  }
546
- return r.appendChild(i), r;
567
+ return o.appendChild(s), o;
547
568
  }
548
- return r.textContent = e.text ?? "", r;
569
+ return o.textContent = e.text ?? "", o;
549
570
  }
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;
571
+ function Xe(e, t, n) {
572
+ const r = n.createElement("img");
573
+ return r.className = N("image", t), r.src = e.imageData, new F().add("width", "100%").add("height", "100%").add("object-fit", "contain").add("display", "block").applyTo(r), r.alt = e.kind, r;
553
574
  }
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;
575
+ function ue(e, t, n, r) {
576
+ const o = r.createElement("div");
577
+ o.className = N("shape", n);
578
+ const i = e.style || {}, a = Y(i), s = te(i), l = `${q(a.widthPt * t / 72, 2)}px solid ${a.color}`, d = new F();
579
+ return e.grid || e.kind === "rect" ? (s.top && d.add("border-top", l), s.right && d.add("border-right", l), s.bottom && d.add("border-bottom", l), s.left && d.add("border-left", l)) : e.kind === "ellipse" ? (s.inner && d.add("border", l).add("border-radius", "50%"), i.backgroundColor && d.add("background-color", i.backgroundColor)) : e.kind === "line" && d.add("height", "0").add("border-top", l), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(o), o;
559
580
  }
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;
581
+ function Te(e, t, n, r) {
582
+ const o = r.createElement("div");
583
+ o.className = `${N("comp", n)} mr-kind-${e.kind}`;
584
+ const i = new F().add("position", "absolute").mm("left", e.leftMm, t).mm("top", e.topMm, t).mm("width", e.widthMm, t).mm("height", e.heightMm, t).add("box-sizing", "border-box");
585
+ if (Pe(i, e, t), i.applyTo(o), He(e))
586
+ return o.appendChild(Xe(e, n, r)), o;
566
587
  if (e.kind === "text")
567
- return r.appendChild(Ye(e, t, o, n)), r;
588
+ return o.appendChild(Ke(e, t, n, r)), o;
568
589
  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;
590
+ const s = ue(e, t, n, r);
591
+ return s.appendChild(Ue(e.grid, e, t, n, r)), o.appendChild(s), o;
571
592
  }
572
593
  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;
594
+ return o.appendChild(ue(e, t, n, r)), o;
595
+ const a = r.createElement("div");
596
+ return a.className = N("unknown", n), a.textContent = e.fallbackText ?? "", o.appendChild(a), o;
576
597
  }
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;
598
+ function Qe(e, t, n, r) {
599
+ const o = r.createElement("div");
600
+ o.className = N("page", n), new F().add("position", "relative").mm("width", e.pageWidthMm, t).mm("height", e.pageHeightMm, t).add("background-color", "#fff").add("overflow", "hidden").add("box-sizing", "border-box").applyTo(o);
601
+ for (const i of e.components)
602
+ o.appendChild(Te(i, t, n, r));
603
+ return o;
583
604
  }
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;
605
+ function mt(e, t, n = {}) {
606
+ const r = n.dpi ?? 96, o = t.createElement("div");
607
+ return o.className = N("root", n), o.dataset.schemaVersion = e.schemaVersion, e.pages.forEach((i) => {
608
+ o.appendChild(Qe(i, r, n, t));
609
+ }), o;
589
610
  }
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)
611
+ function Ze(e) {
612
+ const { pageHeightsPx: t, viewportHeightPx: n, scrollTopPx: r, overscan: o = 1, gapPx: i = 0 } = e, a = t.length;
613
+ if (a === 0)
593
614
  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;
615
+ const s = Math.max(0, i), l = new Array(a + 1);
616
+ l[0] = 0;
617
+ for (let u = 0; u < a; u++)
618
+ l[u + 1] = l[u] + Math.max(0, t[u] ?? 0) + s;
619
+ const d = l[a], h = Math.max(0, r);
620
+ let m = 0, c = 0, g = a - 1;
621
+ for (; c <= g; ) {
622
+ const u = c + g >> 1;
623
+ l[u] <= h ? (m = u, c = u + 1) : g = u - 1;
603
624
  }
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);
625
+ const f = Math.max(0, Math.min(a - 1, m - o)), y = l[m] + Math.max(0, n);
626
+ let P = a - 1;
627
+ for (c = 0, g = a - 1; c <= g; ) {
628
+ const u = c + g >> 1;
629
+ l[u + 1] < y ? c = u + 1 : (P = u, g = u - 1);
609
630
  }
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 };
631
+ const x = Math.min(a - 1, P + o), M = l[f], v = Math.max(0, d - l[x + 1]);
632
+ return { start: f, end: x, padTopPx: M, padBottomPx: v };
612
633
  }
613
- const ne = 96 / 25.4;
614
- function we(e, t = 96) {
615
- const o = t / 96 * ne;
634
+ const ae = 96 / 25.4;
635
+ function xe(e, t = 96) {
636
+ const n = t / 96 * ae;
616
637
  return {
617
- widthPx: Math.max(1, Math.round(e.pageWidthMm * o)),
618
- heightPx: Math.max(1, Math.round(e.pageHeightMm * o))
638
+ widthPx: Math.max(1, Math.round(e.pageWidthMm * n)),
639
+ heightPx: Math.max(1, Math.round(e.pageHeightMm * n))
619
640
  };
620
641
  }
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)
642
+ function et(e, t, n) {
643
+ const r = document.createElement("canvas"), { widthPx: o, heightPx: i } = xe(e, n);
644
+ r.width = Math.round(o * t), r.height = Math.round(i * t), r.style.width = `${o}px`, r.style.height = `${i}px`;
645
+ const a = r.getContext("2d");
646
+ if (!a)
626
647
  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 };
648
+ return a.scale(t, t), a.fillStyle = "#ffffff", a.fillRect(0, 0, o, i), { canvas: r, ctx: a };
628
649
  }
629
- function it(e, t = 96) {
630
- return j(e, t).fontSizePx;
650
+ function ht(e, t = 96) {
651
+ return V(e, t).fontSizePx;
631
652
  }
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) => {
653
+ function $e(e, t, n, r, o, i, a, s = "top") {
654
+ e.font = `${t.bold ? "bold " : ""}${t.fontSizePx}px ${a}`, e.fillStyle = t.color, e.textBaseline = "alphabetic";
655
+ const l = t.fontSizePx * t.lineHeight, d = t.text === "" ? [""] : t.text.split(`
656
+ `), h = d.length * l;
657
+ let m = r;
658
+ s === "middle" ? m = r + (i - h) / 2 : s === "bottom" && (m = r + i - h), d.forEach((c, g) => {
638
659
  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);
660
+ const f = t.align === "center" ? n + o / 2 : t.align === "right" ? n + o : n;
661
+ e.fillText(c, f, m + g * l + t.fontSizePx * 0.8, o);
641
662
  }), e.textAlign = "left";
642
663
  }
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;
664
+ function tt(e, t, n, r, o, i, a, s, l, d, h) {
665
+ const m = Le(t, i / s, a / s), c = te(n.style), g = Y(n.style);
666
+ for (const f of m.cells) {
667
+ const y = f.cell.style?.backgroundColor;
647
668
  y && (e.fillStyle = y, e.fillRect(
648
- n + g.xMm * i,
649
- r + g.yMm * i,
650
- g.widthMm * i,
651
- g.heightMm * i
669
+ r + f.xMm * s,
670
+ o + f.yMm * s,
671
+ f.widthMm * s,
672
+ f.heightMm * s
652
673
  ));
653
674
  }
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();
675
+ if (c.inner) {
676
+ e.strokeStyle = g.color, e.lineWidth = K(g.widthPt, l);
677
+ for (const f of m.edges)
678
+ e.beginPath(), f.kind === "v" ? (e.moveTo(r + f.pos * s, o + f.from * s), e.lineTo(r + f.pos * s, o + f.to * s)) : (e.moveTo(r + f.from * s, o + f.pos * s), e.lineTo(r + f.to * s, o + f.pos * s)), e.stroke();
679
+ e.beginPath(), c.top && (e.moveTo(r, o), e.lineTo(r + i, o)), c.right && (e.moveTo(r + i, o), e.lineTo(r + i, o + a)), c.bottom && (e.moveTo(r + i, o + a), e.lineTo(r, o + a)), c.left && (e.moveTo(r, o + a), e.lineTo(r, o)), e.stroke();
659
680
  }
660
- for (const g of h.cells) {
661
- const y = typeof g.cell.text == "string" ? g.cell.text : "";
681
+ for (const f of m.cells) {
682
+ const y = typeof f.cell.text == "string" ? f.cell.text : "";
662
683
  if (!y) continue;
663
- const E = g.cell.style, P = E?.fontSize ?? J, b = U(
684
+ const P = f.cell.style, x = P?.fontSize ?? Q, M = Z(
664
685
  y,
665
- g.widthMm - 1,
666
- { fontSizePt: P },
667
- m
686
+ f.widthMm - 1,
687
+ { fontSizePt: x },
688
+ h
668
689
  ).join(`
669
690
  `);
670
- ye(
691
+ $e(
671
692
  e,
672
693
  {
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
694
+ text: M,
695
+ fontSizePx: V(P, l).fontSizePx,
696
+ bold: P?.bold ?? !1,
697
+ color: P?.color ?? we(n.style, Be),
698
+ align: P?.align ?? "left",
699
+ lineHeight: ee
679
700
  },
680
- n + (g.xMm + 0.5) * i,
681
- r + g.yMm * i,
682
- Math.max(0, (g.widthMm - 1) * i),
683
- g.heightMm * i,
684
- c,
685
- E?.verticalAlign ?? "middle"
701
+ r + (f.xMm + 0.5) * s,
702
+ o + f.yMm * s,
703
+ Math.max(0, (f.widthMm - 1) * s),
704
+ f.heightMm * s,
705
+ d,
706
+ P?.verticalAlign ?? "middle"
686
707
  );
687
708
  }
688
709
  }
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 ?? {};
710
+ function ke(e, t, n, r, o, i) {
711
+ const a = t.leftMm * n, s = t.topMm * n, l = t.widthMm * n, d = t.heightMm * n, h = t.style ?? {};
691
712
  if (t.grid) {
692
- Ue(e, t.grid, t, l, i, d, c, o, n, r, a);
713
+ tt(e, t.grid, t, a, s, l, d, n, r, o, i);
693
714
  return;
694
715
  }
695
716
  switch (t.kind) {
696
717
  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(`
718
+ const m = h.fontSize ?? Q, c = Me(t) ? t.richParagraphs.map((g) => (g.segments ?? []).map((f) => f.text ?? f.field ?? "").join("")).join(`
698
719
  `) : Array.isArray(t.lines) && t.lines.length > 0 ? t.lines.join(`
699
- `) : U(t.text ?? "", t.widthMm, { fontSizePt: h }, a).join(`
720
+ `) : Z(t.text ?? "", t.widthMm, { fontSizePt: m }, i).join(`
700
721
  `);
701
- ye(
722
+ $e(
702
723
  e,
703
724
  {
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)
725
+ text: c,
726
+ fontSizePx: V(h, r).fontSizePx,
727
+ bold: h.bold ?? !1,
728
+ color: we(h),
729
+ align: h.align ?? "left",
730
+ lineHeight: Ne(h)
710
731
  },
732
+ a,
733
+ s,
711
734
  l,
712
- i,
713
735
  d,
714
- c,
715
- r,
716
- m.verticalAlign
736
+ o,
737
+ h.verticalAlign
717
738
  );
718
739
  break;
719
740
  }
720
741
  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());
742
+ const m = Y(h), c = te(h);
743
+ h.backgroundColor && (e.fillStyle = h.backgroundColor, e.fillRect(a, s, l, d)), c.inner && (e.strokeStyle = m.color, e.lineWidth = K(m.widthPt, r), e.beginPath(), c.top && (e.moveTo(a, s), e.lineTo(a + l, s)), c.right && (e.moveTo(a + l, s), e.lineTo(a + l, s + d)), c.bottom && (e.moveTo(a + l, s + d), e.lineTo(a, s + d)), c.left && (e.moveTo(a, s + d), e.lineTo(a, s)), e.stroke());
723
744
  break;
724
745
  }
725
746
  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();
747
+ const m = Y({ ...h, borderColor: h.lineColor ?? h.borderColor });
748
+ e.strokeStyle = m.color, e.lineWidth = K(m.widthPt, r), e.beginPath(), e.moveTo(a, s + d / 2), e.lineTo(a + l, s + d / 2), e.stroke();
728
749
  break;
729
750
  }
730
751
  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();
752
+ const m = Y(h);
753
+ e.strokeStyle = m.color, e.lineWidth = K(m.widthPt, r), h.backgroundColor && (e.fillStyle = h.backgroundColor, e.beginPath(), e.ellipse(a + l / 2, s + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.fill()), e.beginPath(), e.ellipse(a + l / 2, s + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.stroke();
733
754
  break;
734
755
  }
735
756
  }
736
757
  }
737
- async function st(e, t = {}) {
758
+ async function ft(e, t = {}) {
738
759
  if (typeof document > "u")
739
760
  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(
761
+ const { format: n = "png", quality: r = 0.92, ...o } = t, { canvases: i } = nt(e, o), a = n === "jpeg" ? "image/jpeg" : "image/png", s = [];
762
+ for (const l of i)
763
+ s.push(
743
764
  await new Promise(
744
- (c) => d.toBlob((m) => c(m), l, n)
745
- ) ?? new Blob([], { type: l })
765
+ (d) => l.toBlob((h) => d(h), a, r)
766
+ ) ?? new Blob([], { type: a })
746
767
  );
747
- return { blobs: i };
768
+ return { blobs: s };
748
769
  }
749
- function Ke(e, t = {}) {
770
+ function nt(e, t = {}) {
750
771
  if (typeof document > "u")
751
772
  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);
773
+ const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), r = t.dpi ?? 96, o = r / 96 * ae, i = t.fontFamily ?? '"Microsoft YaHei", sans-serif', a = t.measurer ?? ie, s = Math.max(0, t.start ?? 0), l = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1), d = [];
774
+ for (let h = s; h <= l; h++) {
775
+ const m = e.pages[h], { canvas: c, ctx: g } = et(m, n, r);
776
+ for (const f of m.components)
777
+ ke(g, f, o, r, i, a);
778
+ d.push(c);
758
779
  }
759
- return { canvases: c };
780
+ return { canvases: d };
760
781
  }
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);
782
+ function gt(e, t = {}) {
783
+ const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), r = t.dpi ?? 96, o = r / 96 * ae, i = t.fontFamily ?? '"Microsoft YaHei", sans-serif', a = t.measurer ?? ie, s = t.overscan ?? 1, l = t.gapPx ?? 18, d = t.pagesPerFrame ?? 1, h = e.pages.map((w) => w.pageHeightMm * o), m = Math.max(1, ...e.pages.map((w) => w.pageWidthMm * o)), c = { start: 0, end: -1 };
784
+ let g = null, f = null, y = null, P = null, x = [], M = 0, v = [];
785
+ function u() {
786
+ const w = g;
787
+ w.innerHTML = "", f = document.createElement("div"), f.style.cssText = `width:${m}px;margin:0 auto;`, y = document.createElement("div"), P = document.createElement("div"), f.appendChild(y), x = [];
788
+ const H = Math.min(e.pages.length, 3 + s * 2);
789
+ for (let B = 0; B < H; B++) {
790
+ const S = document.createElement("div");
791
+ S.style.cssText = `margin:0 auto ${l}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, f.appendChild(S), x.push(S);
771
792
  }
772
- g.appendChild(E), u.appendChild(g);
793
+ f.appendChild(P), w.appendChild(f);
773
794
  }
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`;
795
+ function T(w, H) {
796
+ const B = e.pages[H], { widthPx: S, heightPx: R } = xe(B, r);
797
+ let A = w.firstElementChild;
798
+ (!A || A.tagName !== "CANVAS") && (A = document.createElement("canvas"), w.innerHTML = "", w.appendChild(A)), A.width = Math.round(S * n), A.height = Math.round(R * n), A.style.width = `${S}px`, A.style.height = `${R}px`;
799
+ const j = A.getContext("2d");
800
+ if (j) {
801
+ j.setTransform(1, 0, 0, 1, 0, 0), j.scale(n, n), j.fillStyle = "#ffffff", j.fillRect(0, 0, S, R);
802
+ for (const U of B.components)
803
+ ke(j, U, o, r, i, a);
804
+ A.dataset.canvasPage = String(H), w.style.height = `${R}px`, w.style.width = `${S}px`;
784
805
  }
785
806
  }
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`;
807
+ function I(w) {
808
+ c.start = w.start, c.end = w.end, y.style.height = `${w.start * l + h.slice(0, w.start).reduce((S, R) => S + R, 0)}px`;
809
+ const H = e.pages.length - 1 - w.end;
810
+ P.style.height = `${H * l + h.slice(w.end + 1).reduce((S, R) => S + R, 0)}px`;
811
+ const B = w.end - w.start + 1;
812
+ x.forEach((S, R) => {
813
+ if (R < B) {
814
+ S.style.display = "";
815
+ const A = w.start + R;
816
+ S.style.height = `${h[A] ?? 0}px`;
796
817
  } else
797
- w.style.display = "none";
818
+ S.style.display = "none";
798
819
  }), v = [];
799
- for (let w = u.start; w <= u.end; w++) {
800
- const H = P[w - u.start];
801
- if (!H) continue;
802
- H.firstElementChild?.dataset?.canvasPage !== String(w) && v.push(w);
820
+ for (let S = w.start; S <= w.end; S++) {
821
+ const R = x[S - w.start];
822
+ if (!R) continue;
823
+ R.firstElementChild?.dataset?.canvasPage !== String(S) && v.push(S);
803
824
  }
804
- k();
825
+ E();
805
826
  }
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);
827
+ function E() {
828
+ M || v.length === 0 || (M = requestAnimationFrame(() => {
829
+ M = 0;
830
+ let w = Math.max(1, d);
831
+ for (; v.length > 0 && w-- > 0; ) {
832
+ const H = v.shift(), B = x[H - c.start];
833
+ B && T(B, H);
813
834
  }
814
- v.length > 0 && k();
835
+ v.length > 0 && E();
815
836
  }));
816
837
  }
817
838
  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
839
+ M || (M = requestAnimationFrame(() => {
840
+ M = 0;
841
+ const w = g, H = Ze({
842
+ pageHeightsPx: h,
843
+ viewportHeightPx: w.clientHeight,
844
+ scrollTopPx: w.scrollTop,
845
+ overscan: s,
846
+ gapPx: l
826
847
  });
827
- A.start !== s.start || A.end !== s.end ? G(A) : k();
848
+ H.start !== c.start || H.end !== c.end ? I(H) : E();
828
849
  }));
829
850
  }
830
- let _ = null;
851
+ let G = null;
831
852
  return {
832
- attach(u) {
853
+ attach(w) {
833
854
  if (typeof document > "u")
834
855
  throw new Error("createCanvasPager 需要浏览器环境(SSR 请在客户端钩子中调用 attach)");
835
- f = u, S(), u.addEventListener("scroll", $, { passive: !0 }), typeof ResizeObserver < "u" && (_ = new ResizeObserver(() => $()), _.observe(u)), $();
856
+ g = w, u(), w.addEventListener("scroll", $, { passive: !0 }), typeof ResizeObserver < "u" && (G = new ResizeObserver(() => $()), G.observe(w)), $();
836
857
  },
837
858
  destroy() {
838
- b && cancelAnimationFrame(b), b = 0, _?.disconnect(), _ = null, f?.removeEventListener("scroll", $), v = [], g?.remove(), f = null;
859
+ M && cancelAnimationFrame(M), M = 0, G?.disconnect(), G = null, g?.removeEventListener("scroll", $), v = [], f?.remove(), g = null;
839
860
  },
840
861
  window() {
841
- return { ...s };
862
+ return { ...c };
842
863
  }
843
864
  };
844
865
  }
845
- function Xe(e, t, o) {
846
- let n, r;
866
+ function Ee(e, t, n) {
867
+ let r, o;
847
868
  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 };
869
+ const i = X[e];
870
+ if (!i) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(X).join("/")})`);
871
+ r = i.widthMm, o = i.heightMm;
872
+ } else typeof e == "number" ? (r = e, o = t ?? 297) : (r = e.widthMm, o = e.heightMm);
873
+ return n ? { widthMm: o, heightMm: r } : { widthMm: r, heightMm: o };
853
874
  }
854
- class Ze {
875
+ class rt {
855
876
  constructor() {
856
877
  this.pages = [], this.pending = null, this.templateParams = void 0;
857
878
  }
@@ -878,20 +899,20 @@ class Ze {
878
899
  * - 数字:.page(210, 297)(第三参数兼容旧 margins 对象或新 options)
879
900
  * - 对象:.page({ widthMm: 210, heightMm: 297 })
880
901
  */
881
- page(t = "a4", o = {}, n) {
902
+ page(t = "a4", n = {}, r) {
882
903
  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(
904
+ const i = r != null && !("margins" in r) && !("landscape" in r) && ("marginTopMm" in r || "marginBottomMm" in r || "marginLeftMm" in r || "marginRightMm" in r) ? { margins: r } : typeof n == "number" ? r ?? {} : n, { widthMm: a, heightMm: s } = Ee(
884
905
  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
906
+ typeof n == "number" ? n : void 0,
907
+ i.landscape
908
+ ), l = i.margins ?? {};
909
+ return this.pending = new ot(this, {
910
+ widthMm: a,
911
+ heightMm: s,
912
+ marginTopMm: l.marginTopMm ?? 10,
913
+ marginBottomMm: l.marginBottomMm ?? 10,
914
+ marginLeftMm: l.marginLeftMm ?? 10,
915
+ marginRightMm: l.marginRightMm ?? 10
895
916
  }), this.pending;
896
917
  }
897
918
  collect() {
@@ -903,62 +924,62 @@ class Ze {
903
924
  return this.templateParams ? { params: this.templateParams, pages: this.pages } : { pages: this.pages };
904
925
  }
905
926
  }
906
- class Qe {
907
- constructor(t, o) {
908
- this.parent = t, this.page = o, this.components = [];
927
+ class ot {
928
+ constructor(t, n) {
929
+ this.parent = t, this.page = n, this.components = [];
909
930
  }
910
- text(t, o = {}, n = {}) {
931
+ text(t, n = {}, r = {}) {
911
932
  return this.components.push({
912
933
  kind: "text",
913
- leftMm: o.leftMm ?? 0,
914
- topMm: o.topMm ?? 0,
915
- widthMm: o.widthMm ?? 60,
916
- heightMm: o.heightMm ?? 8,
934
+ leftMm: n.leftMm ?? 0,
935
+ topMm: n.topMm ?? 0,
936
+ widthMm: n.widthMm ?? 60,
937
+ heightMm: n.heightMm ?? 8,
917
938
  text: t,
918
- style: n
939
+ style: r
919
940
  }), this;
920
941
  }
921
- list(t, o, n, r = {}) {
942
+ list(t, n, r, o = {}) {
922
943
  return this.components.push({
923
944
  kind: "list",
924
- leftMm: o.leftMm ?? 10,
925
- topMm: o.topMm ?? 30,
926
- widthMm: o.widthMm ?? 180,
945
+ leftMm: n.leftMm ?? 10,
946
+ topMm: n.topMm ?? 30,
947
+ widthMm: n.widthMm ?? 180,
927
948
  dataset: t,
928
- columns: n,
929
- ...r
949
+ columns: r,
950
+ ...o
930
951
  }), this;
931
952
  }
932
- rect(t, o = {}) {
933
- return this.components.push({ kind: "rect", ...t, style: o }), this;
953
+ rect(t, n = {}) {
954
+ return this.components.push({ kind: "rect", ...t, style: n }), this;
934
955
  }
935
- line(t, o, n, r = {}) {
956
+ line(t, n, r, o = {}) {
936
957
  return this.components.push({
937
958
  kind: "line",
938
959
  leftMm: t,
939
- topMm: o,
940
- widthMm: n,
960
+ topMm: n,
961
+ widthMm: r,
941
962
  heightMm: 0.5,
942
- style: r
963
+ style: o
943
964
  }), this;
944
965
  }
945
- barcode(t, o) {
966
+ barcode(t, n) {
946
967
  return this.components.push({
947
968
  kind: "barcode",
948
- leftMm: o.leftMm ?? 0,
949
- topMm: o.topMm ?? 0,
950
- widthMm: o.widthMm ?? 40,
951
- heightMm: o.heightMm ?? 12,
969
+ leftMm: n.leftMm ?? 0,
970
+ topMm: n.topMm ?? 0,
971
+ widthMm: n.widthMm ?? 40,
972
+ heightMm: n.heightMm ?? 12,
952
973
  fallbackText: t
953
974
  }), this;
954
975
  }
955
- qrcode(t, o, n, r) {
976
+ qrcode(t, n, r, o) {
956
977
  return this.components.push({
957
978
  kind: "qrcode",
958
- leftMm: n,
959
- topMm: r,
960
- widthMm: o,
961
- heightMm: o,
979
+ leftMm: r,
980
+ topMm: o,
981
+ widthMm: n,
982
+ heightMm: n,
962
983
  fallbackText: t
963
984
  }), this;
964
985
  }
@@ -972,60 +993,229 @@ class Qe {
972
993
  return this.done().build();
973
994
  }
974
995
  }
975
- function lt() {
976
- return new Ze();
996
+ function ut() {
997
+ return new rt();
998
+ }
999
+ function D(e, t, n = !1) {
1000
+ if (!Number.isFinite(e) || (n ? e < 0 : e <= 0))
1001
+ throw new Error(`${t} 必须是有限${n ? "非负" : "正"}数`);
1002
+ }
1003
+ function pt(e) {
1004
+ if (!e || typeof e != "object")
1005
+ throw new Error("标准明细模板需要 options 对象");
1006
+ if (!Array.isArray(e.columns) || e.columns.length === 0)
1007
+ throw new Error("columns 至少需要一列");
1008
+ const t = e.paper === void 0 ? "a4" : e.paper;
1009
+ if (typeof t != "string" && (typeof t != "object" || t === null) || e.landscape !== void 0 && typeof e.landscape != "boolean")
1010
+ throw new Error("paper 必须是纸张预设名或 { widthMm, heightMm } 对象,landscape 必须是布尔值");
1011
+ if (typeof t == "string" && !Object.prototype.hasOwnProperty.call(X, t))
1012
+ throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(X).join("/")})`);
1013
+ const { widthMm: n, heightMm: r } = Ee(t, void 0, e.landscape);
1014
+ if (D(n, "纸张 widthMm"), D(r, "纸张 heightMm"), e.margins !== void 0 && (!e.margins || typeof e.margins != "object" || Array.isArray(e.margins)))
1015
+ throw new Error("margins 必须是页边距对象");
1016
+ const o = e.margins ?? {}, i = {
1017
+ marginTopMm: o.marginTopMm === void 0 ? 10 : o.marginTopMm,
1018
+ marginBottomMm: o.marginBottomMm === void 0 ? 10 : o.marginBottomMm,
1019
+ marginLeftMm: o.marginLeftMm === void 0 ? 10 : o.marginLeftMm,
1020
+ marginRightMm: o.marginRightMm === void 0 ? 10 : o.marginRightMm
1021
+ };
1022
+ for (const [u, T] of Object.entries(i)) D(T, u, !0);
1023
+ const a = n - i.marginLeftMm - i.marginRightMm, s = r - i.marginTopMm - i.marginBottomMm;
1024
+ if (a <= 0 || s <= 0)
1025
+ throw new Error("页边距占满纸张,必须保留正的可用宽度和高度");
1026
+ const l = e.dataset === void 0 ? "detail" : e.dataset;
1027
+ if (typeof l != "string" || !l.trim())
1028
+ throw new Error("dataset 必须是非空字符串");
1029
+ if (e.title !== void 0 && typeof e.title != "string")
1030
+ throw new Error("title 必须是字符串");
1031
+ const d = e.titleHeightMm === void 0 ? 10 : e.titleHeightMm, h = e.titleGapMm === void 0 ? 4 : e.titleGapMm;
1032
+ D(d, "titleHeightMm"), D(h, "titleGapMm", !0);
1033
+ const m = e.title !== void 0 && e.title.length > 0, c = m ? d + h : 0;
1034
+ if (c >= s)
1035
+ throw new Error("标题高度与间距占满页面,必须为表格保留可用高度");
1036
+ if (e.listOptions !== void 0 && (!e.listOptions || typeof e.listOptions != "object" || Array.isArray(e.listOptions)))
1037
+ throw new Error("listOptions 必须是列表配置对象");
1038
+ const g = e.listOptions ?? {};
1039
+ for (const u of ["fontSizePt", "rowHeightMm", "paddingMm"]) {
1040
+ const T = g[u];
1041
+ T !== void 0 && D(T, `listOptions.${u}`, u === "paddingMm");
1042
+ }
1043
+ let f = 0, y = 0;
1044
+ for (const [u, T] of e.columns.entries()) {
1045
+ if (!T || typeof T.header != "string" || typeof T.field != "string" || !T.field.trim())
1046
+ throw new Error(`columns[${u}] 需要字符串 header 与非空 field`);
1047
+ T.flex !== void 0 && D(T.flex, `columns[${u}].flex`), T.widthMm !== void 0 ? (D(T.widthMm, `columns[${u}].widthMm`), f += T.widthMm) : y = Math.max(y, T.flex ?? 1);
1048
+ }
1049
+ if (f > a)
1050
+ throw new Error(`固定列宽 ${f}mm 超出页面可用宽度 ${a}mm`);
1051
+ const P = a - f;
1052
+ if (y > 0 && P <= 0)
1053
+ throw new Error("固定列占满页面可用宽度,自动列需要正的剩余宽度");
1054
+ const x = y > 0 ? e.columns.reduce((u, T) => u + (T.widthMm === void 0 ? (T.flex ?? 1) / y : 0), 0) : 0, M = e.columns.map(({ widthMm: u, flex: T, ...I }, E) => {
1055
+ const $ = u ?? P * ((T ?? 1) / y) / x;
1056
+ return D($, `columns[${E}] 分配后的 widthMm`), { ...I, widthMm: $ };
1057
+ }), v = { widthMm: n, heightMm: r, ...i, components: [] };
1058
+ return m && v.components.push({
1059
+ kind: "text",
1060
+ text: e.title,
1061
+ leftMm: i.marginLeftMm,
1062
+ topMm: i.marginTopMm,
1063
+ widthMm: a,
1064
+ heightMm: d,
1065
+ style: { fontSize: 16, bold: !0, align: "center", verticalAlign: "middle", ...e.titleStyle }
1066
+ }), v.components.push({
1067
+ ...g,
1068
+ kind: "list",
1069
+ dataset: l,
1070
+ columns: M,
1071
+ leftMm: i.marginLeftMm,
1072
+ topMm: i.marginTopMm + c,
1073
+ widthMm: y > 0 ? a : f
1074
+ }), e.params === void 0 ? { pages: [v] } : { params: e.params, pages: [v] };
1075
+ }
1076
+ function Mt(e) {
1077
+ if (!("mapData" in e)) return e;
1078
+ const { load: t, mapData: n, ...r } = e;
1079
+ return { ...r, load: async (o) => {
1080
+ const i = await t(o);
1081
+ O(o.signal);
1082
+ try {
1083
+ return n(i, o);
1084
+ } catch (a) {
1085
+ throw new W("validate", `报表 ${o.reportId} 数据映射失败`, a);
1086
+ }
1087
+ } };
1088
+ }
1089
+ class W extends Error {
1090
+ constructor(t, n, r) {
1091
+ super(n), this.name = "ReportSourceError", this.code = t, this.cause = r;
1092
+ }
1093
+ }
1094
+ function se(e) {
1095
+ const t = new Error("报表加载已取消");
1096
+ return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
1097
+ }
1098
+ function O(e) {
1099
+ if (e?.aborted) throw se(e);
1100
+ }
1101
+ function it(e, t) {
1102
+ return t ? new Promise((n, r) => {
1103
+ const o = () => t.removeEventListener("abort", i), i = () => {
1104
+ o(), r(se(t));
1105
+ };
1106
+ t.addEventListener("abort", i, { once: !0 }), t.aborted && i(), Promise.resolve(e).then(
1107
+ (a) => {
1108
+ o(), n(a);
1109
+ },
1110
+ (a) => {
1111
+ o(), r(a);
1112
+ }
1113
+ );
1114
+ }) : Promise.resolve(e);
1115
+ }
1116
+ function at(e, t) {
1117
+ if (!e || typeof e != "object" || Array.isArray(e))
1118
+ throw new W("validate", `报表 ${t} 的数据集应为对象`);
1119
+ for (const [n, r] of Object.entries(e))
1120
+ if (!Array.isArray(r) || r.some((o) => !o || typeof o != "object" || Array.isArray(o)))
1121
+ throw new W("validate", `报表 ${t} 的数据集 ${n} 应为对象数组`);
1122
+ }
1123
+ function wt(e, t = {}) {
1124
+ function n(o) {
1125
+ const i = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
1126
+ if (!i) throw new W("config", `未注册报表 ${o}`);
1127
+ return i;
1128
+ }
1129
+ return Object.assign(async ({ reportIds: o, params: i, signal: a, onWarning: s }) => {
1130
+ if (O(a), o.length === 0) throw new W("config", "缺少报表 ID");
1131
+ const l = o.map(n), d = [], h = [];
1132
+ for (const [f, y] of l.entries()) {
1133
+ O(a);
1134
+ const P = o[f], x = { reportId: P, params: { ...i }, signal: a };
1135
+ let M;
1136
+ try {
1137
+ M = await it(y.load ? y.load(x) : y.datasets ?? {}, a);
1138
+ } catch (u) {
1139
+ throw a?.aborted ? se(a) : u instanceof W ? u : new W("fetch", `报表 ${P} 取数失败:${u instanceof Error ? u.message : String(u)}`, u);
1140
+ }
1141
+ O(a), at(M, P);
1142
+ let v;
1143
+ try {
1144
+ v = Ve(y.template, M, y.pagination);
1145
+ } catch (u) {
1146
+ throw new W("validate", `报表 ${P} 排版失败:${u instanceof Error ? u.message : String(u)}`, u);
1147
+ }
1148
+ for (const u of v.plan.pages) d.push(u);
1149
+ h.push(...v.warnings.map((u) => `${P}: ${u}`));
1150
+ }
1151
+ O(a);
1152
+ const m = { schemaVersion: pe, pages: d }, c = Se(m);
1153
+ if (!c.ok)
1154
+ throw new W("validate", `渲染计划校验失败:${c.errors.slice(0, 3).map((f) => `${f.path}: ${f.message}`).join("; ")}`);
1155
+ h.push(...c.warnings.map((f) => `${f.path}: ${f.message}`));
1156
+ const g = s ?? t.onWarning ?? ((f) => console.warn("[mach-report]", f));
1157
+ for (const f of h)
1158
+ O(a), g(f);
1159
+ return O(a), m;
1160
+ }, {
1161
+ getParamDefs: (o) => ze(e, o)
1162
+ });
977
1163
  }
978
1164
  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,
1165
+ St as CSS_DPI,
1166
+ vt as DEFAULT_BORDER_PT,
1167
+ Q as DEFAULT_FONT_PT,
1168
+ Pt as DEFAULT_STROKE_COLOR,
1169
+ Be as DEFAULT_TEXT_COLOR,
1170
+ ee as LINE_HEIGHT,
1171
+ Tt as MM_PER_INCH,
1172
+ X as PAPER_SIZES,
1173
+ ot as PageBuilder,
1174
+ pe as RENDER_PLAN_SCHEMA_VERSION,
1175
+ W as ReportSourceError,
1176
+ xt as SCHEMA_VERSION_MACH,
1177
+ rt as TemplateBuilder,
1178
+ dt as assertRenderPlan,
1179
+ $t as charWidthEm,
993
1180
  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,
1029
- De as validateRenderPlan,
1030
- U as wrapText
1181
+ Ze as computePageWindow,
1182
+ kt as createCanvasMeasurer,
1183
+ gt as createCanvasPager,
1184
+ Et as createHeuristicMeasurer,
1185
+ wt as createReportSource,
1186
+ pt as createTableTemplate,
1187
+ ut as createTemplate,
1188
+ Mt as defineReport,
1189
+ je as evalStyleRule,
1190
+ be as formatValue,
1191
+ ie as heuristicMeasurer,
1192
+ He as isImageBackedComponent,
1193
+ Me as isRichText,
1194
+ xe as measurePageSizePx,
1195
+ Ct as measureTextMm,
1196
+ Re as mmToPx,
1197
+ At as mmToPxFactor,
1198
+ Ve as paginateTemplate,
1199
+ Fe as parseDateLocal,
1200
+ ht as planFontSizePx,
1201
+ K as ptToPx,
1202
+ Ht as pxToMm,
1203
+ Te as renderComponent,
1204
+ Qe as renderPage,
1205
+ mt as renderPlan,
1206
+ nt as renderPlanToCanvas,
1207
+ ft as renderPlanToImages,
1208
+ te as resolveBoxBorders,
1209
+ V as resolveFontSize,
1210
+ Le as resolveGridLayout,
1211
+ Ne as resolveLineHeight,
1212
+ Ee as resolvePaper,
1213
+ Y as resolveStroke,
1214
+ we as resolveTextColor,
1215
+ q as round,
1216
+ oe as toNumber,
1217
+ ye as validateComponent,
1218
+ Ie as validatePage,
1219
+ Se as validateRenderPlan,
1220
+ Z as wrapText
1031
1221
  };