@agile-team/mach-report 1.2.2 → 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 (88) hide show
  1. package/LICENSE +2 -4
  2. package/LICENSING.md +15 -0
  3. package/README.md +240 -92
  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 -14
  8. package/dist/index.d.ts +738 -14
  9. package/dist/index.js +858 -805
  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-CFZ-HE2s.cjs +3 -0
  23. package/dist/{style-6ihHKVCM.js → style-DnmtG7Gl.js} +69 -81
  24. package/dist/style.css +1 -1
  25. package/dist/vue/async.d.cts +769 -335
  26. package/dist/vue/async.d.ts +769 -335
  27. package/dist/vue/index.d.cts +1321 -14
  28. package/dist/vue/index.d.ts +1321 -14
  29. package/dist/vue-async.cjs +1 -1
  30. package/dist/vue-async.js +11 -12
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.js +130 -50
  33. package/dist/xlsx.cjs +20 -20
  34. package/dist/xlsx.d.cts +2292 -5
  35. package/dist/xlsx.d.ts +2292 -5
  36. package/dist/xlsx.js +5452 -5443
  37. package/package.json +7 -13
  38. package/dist/ReportPreview-CJLvkTVn.cjs +0 -6
  39. package/dist/ReportPreview-mZiGtf0L.js +0 -1231
  40. package/dist/builder/template-builder.d.ts +0 -69
  41. package/dist/compat/jh4j-template.d.ts +0 -12
  42. package/dist/defaults.d.ts +0 -27
  43. package/dist/format.d.ts +0 -48
  44. package/dist/layout/paginate.d.ts +0 -97
  45. package/dist/layout/textwrap.d.ts +0 -36
  46. package/dist/manager/api.d.ts +0 -45
  47. package/dist/manager/index.d.ts +0 -2
  48. package/dist/manager/types.d.ts +0 -50
  49. package/dist/manager.cjs +0 -1
  50. package/dist/manager.d.cts +0 -5
  51. package/dist/manager.d.ts +0 -5
  52. package/dist/manager.js +0 -104
  53. package/dist/pdf/font-loader.d.ts +0 -6
  54. package/dist/pdf/index.d.ts +0 -2
  55. package/dist/pdf/render-pdf.d.ts +0 -25
  56. package/dist/plugin-C4qpbdMJ.cjs +0 -1
  57. package/dist/plugin-DcmAPK_K.js +0 -85
  58. package/dist/render/canvas.d.ts +0 -76
  59. package/dist/render/dom.d.ts +0 -10
  60. package/dist/render/grid-geometry.d.ts +0 -41
  61. package/dist/render/style.d.ts +0 -33
  62. package/dist/render/window.d.ts +0 -23
  63. package/dist/schema/render-plan.d.ts +0 -96
  64. package/dist/schema/validate.d.ts +0 -15
  65. package/dist/sql/ast-check.d.ts +0 -14
  66. package/dist/sql/compile.d.ts +0 -31
  67. package/dist/sql/expr.d.ts +0 -21
  68. package/dist/sql/index.d.ts +0 -4
  69. package/dist/sql/tokenizer.d.ts +0 -25
  70. package/dist/style-Xq08-IsV.cjs +0 -3
  71. package/dist/units.d.ts +0 -11
  72. package/dist/vue/ReportParamPanel.d.ts +0 -19
  73. package/dist/vue/ReportPreview.d.ts +0 -209
  74. package/dist/vue/ReportToolbar.d.ts +0 -42
  75. package/dist/vue/adapters.d.ts +0 -40
  76. package/dist/vue/composables/useHighlight.d.ts +0 -8
  77. package/dist/vue/composables/usePageWindow.d.ts +0 -25
  78. package/dist/vue/composables/usePrintExport.d.ts +0 -40
  79. package/dist/vue/composables/useReportSearch.d.ts +0 -73
  80. package/dist/vue/composables/useZoom.d.ts +0 -15
  81. package/dist/vue/config.d.ts +0 -108
  82. package/dist/vue/controller.d.ts +0 -29
  83. package/dist/vue/errors.d.ts +0 -16
  84. package/dist/vue/injection-keys.d.ts +0 -14
  85. package/dist/vue/local-adapter.d.ts +0 -12
  86. package/dist/vue/pdf-exporter.d.ts +0 -13
  87. package/dist/vue/plugin.d.ts +0 -354
  88. package/dist/xlsx/render-xlsx.d.ts +0 -20
package/dist/index.js CHANGED
@@ -1,90 +1,91 @@
1
- import { h as ot, R as Et, D as X, w as Z, L as Q, i as At, r as G, m as $t, a as V, b as ut, c as O, d as tt, p as K, e as Ht, f as pt, g as Nt, P as ht } from "./style-6ihHKVCM.js";
2
- import { C as ye, j as we, k as Se, M as Te, S as xe, l as ke, n as ve, o as Pe, q as Ce, s as Ee, t as Ae, u as $e, v as He, x as Ne } from "./style-6ihHKVCM.js";
3
- import { r as Rt } from "./grid-geometry-Bs8QXz1X.js";
4
- function Bt(t) {
5
- const e = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(t.trim());
6
- if (e) {
7
- const n = new Date(Number(e[1]), Number(e[2]) - 1, Number(e[3]));
8
- return Number.isNaN(n.getTime()) ? null : n;
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) {
6
+ const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
7
+ if (t) {
8
+ const r = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
9
+ return Number.isNaN(r.getTime()) ? null : r;
9
10
  }
10
- const r = new Date(t);
11
- return Number.isNaN(r.getTime()) ? null : r;
11
+ const n = new Date(e);
12
+ return Number.isNaN(n.getTime()) ? null : n;
12
13
  }
13
- function nt(t, e) {
14
- return t.toLocaleString("en-US", {
15
- minimumFractionDigits: e,
16
- maximumFractionDigits: e
14
+ function re(e, t) {
15
+ return e.toLocaleString("en-US", {
16
+ minimumFractionDigits: t,
17
+ maximumFractionDigits: t
17
18
  });
18
19
  }
19
- function Lt(t, e) {
20
- const r = (n) => String(n).padStart(2, "0");
21
- return e.replace(/YYYY/g, String(t.getFullYear())).replace(/MM/g, r(t.getMonth() + 1)).replace(/DD/g, r(t.getDate())).replace(/hh/g, r(t.getHours())).replace(/mm/g, r(t.getMinutes())).replace(/ss/g, r(t.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 Ft(t, e, r) {
24
- return r != null ? e ? nt(t, r) : t.toFixed(r) : e ? nt(t) : String(t);
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 rt(t) {
27
- const e = typeof t == "number" ? t : Number(String(t).replace(/,/g, ""));
28
- return Number.isFinite(e) ? e : null;
27
+ function oe(e) {
28
+ const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
29
+ return Number.isFinite(t) ? t : null;
29
30
  }
30
- function Mt(t, e) {
31
- if (t == null || t === "" || !e) return String(t ?? "");
32
- switch (e.kind) {
31
+ function be(e, t) {
32
+ if (e == null || e === "" || !t) return String(e ?? "");
33
+ switch (t.kind) {
33
34
  case "number": {
34
- const r = rt(t);
35
- return r == null ? String(t) : Ft(r, e.thousands === !0, e.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 r = rt(t);
39
- return r == null ? String(t) : `${nt(r * 100, e.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 r = e.pattern ?? "YYYY-MM-DD", n = t instanceof Date ? t : Bt(String(t));
43
- return n ? Lt(n, r) : String(t);
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
- return String(t);
47
+ return String(e);
47
48
  }
48
49
  }
49
- function zt(t, e) {
50
- const r = t[e.field];
51
- if (r == null || r === "") return !1;
52
- if (typeof e.value == "number") {
53
- const a = rt(r);
54
- if (a == null) return !1;
55
- switch (e.op) {
50
+ function je(e, t) {
51
+ const n = e[t.field];
52
+ if (n == null || n === "") return !1;
53
+ if (typeof t.value == "number") {
54
+ const i = oe(n);
55
+ if (i == null) return !1;
56
+ switch (t.op) {
56
57
  case ">":
57
- return a > e.value;
58
+ return i > t.value;
58
59
  case ">=":
59
- return a >= e.value;
60
+ return i >= t.value;
60
61
  case "<":
61
- return a < e.value;
62
+ return i < t.value;
62
63
  case "<=":
63
- return a <= e.value;
64
+ return i <= t.value;
64
65
  case "==":
65
- return a === e.value;
66
+ return i === t.value;
66
67
  case "!=":
67
- return a !== e.value;
68
+ return i !== t.value;
68
69
  }
69
70
  }
70
- const n = String(r), o = String(e.value);
71
- switch (e.op) {
71
+ const r = String(n), o = String(t.value);
72
+ switch (t.op) {
72
73
  case "==":
73
- return n === o;
74
+ return r === o;
74
75
  case "!=":
75
- return n !== o;
76
+ return r !== o;
76
77
  case ">":
77
- return n > o;
78
+ return r > o;
78
79
  case ">=":
79
- return n >= o;
80
+ return r >= o;
80
81
  case "<":
81
- return n < o;
82
+ return r < o;
82
83
  case "<=":
83
- return n <= o;
84
+ return r <= o;
84
85
  }
85
86
  return !1;
86
87
  }
87
- const Dt = /* @__PURE__ */ new Set([
88
+ const Oe = /* @__PURE__ */ new Set([
88
89
  "text",
89
90
  "image",
90
91
  "barcode",
@@ -94,349 +95,369 @@ const Dt = /* @__PURE__ */ new Set([
94
95
  "rect",
95
96
  "ellipse"
96
97
  ]);
97
- function I(t) {
98
- return typeof t == "object" && t !== null && !Array.isArray(t);
98
+ function _(e) {
99
+ return typeof e == "object" && e !== null && !Array.isArray(e);
99
100
  }
100
- function _t(t, e, r, n) {
101
- const o = t[e];
102
- o != null && (typeof o != "number" || !Number.isFinite(o)) && n.push({ path: `${r}.${e}`, message: `应为有限数字,实际 ${JSON.stringify(o)}` });
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 bt(t, e, r, n = []) {
105
- if (!I(t)) {
106
- r.push({ path: e, message: "组件应为对象" });
105
+ function ye(e, t, n, r = []) {
106
+ if (!_(e)) {
107
+ n.push({ path: t, message: "组件应为对象" });
107
108
  return;
108
109
  }
109
- const o = t.kind;
110
- typeof o != "string" ? r.push({ path: `${e}.kind`, message: "组件缺少 kind 字符串" }) : Dt.has(o) || n.push({
111
- path: `${e}.kind`,
110
+ const o = e.kind;
111
+ typeof o != "string" ? n.push({ path: `${t}.kind`, message: "组件缺少 kind 字符串" }) : Oe.has(o) || r.push({
112
+ path: `${t}.kind`,
112
113
  message: `未知组件类型 ${JSON.stringify(o)},将以兜底方式渲染`
113
114
  });
114
- for (const i of ["leftMm", "topMm", "widthMm", "heightMm"])
115
- _t(t, i, e, r);
116
- t.leftMm != null && t.widthMm != null && (t.leftMm < -100 || t.widthMm < 0) && r.push({ path: e, message: "几何数值异常(leftMm<-100 或 widthMm<0)" });
117
- const a = t.grid;
118
- a !== void 0 && (!I(a) || !Array.isArray(a.cells) ? r.push({ path: `${e}.grid.cells`, message: "grid.cells 应为二维数组" }) : a.cells.forEach((i, c) => {
119
- if (!Array.isArray(i)) {
120
- r.push({ path: `${e}.grid.cells.${c}`, 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((d, h) => {
124
- d != null && I(d) && Array.isArray(d.children) && d.children.forEach((m, l) => {
125
- bt(m, `${e}.grid.cells.${c}.${h}.children.${l}`, r, 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 s = t.richParagraphs;
130
- s !== void 0 && (Array.isArray(s) ? s.forEach((i, c) => {
131
- (!I(i) || !Array.isArray(i.segments)) && r.push({ path: `${e}.richParagraphs.${c}`, message: "段落缺少 segments 数组" });
132
- }) : r.push({ path: `${e}.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 Wt(t, e, r, n = []) {
135
- if (!I(t)) {
136
- r.push({ path: e, message: "页应为对象" });
137
+ function Ie(e, t, n, r = []) {
138
+ if (!_(e)) {
139
+ n.push({ path: t, message: "页应为对象" });
137
140
  return;
138
141
  }
139
- const o = t.pageWidthMm, a = t.pageHeightMm;
140
- (typeof o != "number" || !(o > 0 && o < 3e3)) && r.push({ path: `${e}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof a != "number" || !(a > 0 && a < 5e3)) && r.push({ path: `${e}.pageHeightMm`, message: `页高非法: ${JSON.stringify(a)}` });
141
- const s = t.components;
142
- s !== void 0 && !Array.isArray(s) ? r.push({ path: `${e}.components`, message: "components 应为数组" }) : Array.isArray(s) && s.forEach(
143
- (i, c) => bt(i, `${e}.components.${c}`, r, 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 It(t) {
147
- const e = [], r = [], n = I(t) ? t.pages : void 0;
148
- if (!Array.isArray(n))
149
- e.push({
149
+ function Se(e) {
150
+ const t = [], n = [], r = _(e) ? e.pages : void 0;
151
+ if (!Array.isArray(r))
152
+ t.push({
150
153
  path: "$.pages",
151
- message: t == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
154
+ message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
152
155
  });
153
156
  else {
154
- n.forEach((a, s) => Wt(a, `$.pages.${s}`, e, r)), n.length > 2e3 && r.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 o = n.reduce(
159
- (a, s) => a + (I(s) && Array.isArray(s.components) ? s.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
- o > 5e4 && r.push({
165
+ o > 5e4 && n.push({
163
166
  path: "$.pages",
164
167
  message: `组件总数异常大(${o} 个),可能触发浏览器性能限制`
165
168
  });
166
169
  }
167
- return { ok: e.length === 0, errors: e, warnings: r };
170
+ return { ok: t.length === 0, errors: t, warnings: n };
168
171
  }
169
- function ce(t) {
170
- const e = It(t);
171
- if (!e.ok) {
172
- const r = e.errors.slice(0, 3).map((n) => `${n.path}: ${n.message}`).join("; ");
173
- throw new Error(`渲染计划校验失败(${e.errors.length} 处): ${r}`);
172
+ function dt(e) {
173
+ const t = Se(e);
174
+ if (!t.ok) {
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
- return t.pages;
178
+ return e.pages;
176
179
  }
177
- function mt(t) {
180
+ function fe(e) {
178
181
  return {
179
- widthMm: t.widthMm,
180
- heightMm: t.heightMm,
181
- marginTopMm: t.marginTopMm ?? 0,
182
- marginBottomMm: t.marginBottomMm ?? 0,
183
- marginLeftMm: t.marginLeftMm ?? 0,
184
- marginRightMm: t.marginRightMm ?? 0,
182
+ widthMm: e.widthMm,
183
+ heightMm: e.heightMm,
184
+ marginTopMm: e.marginTopMm ?? 0,
185
+ marginBottomMm: e.marginBottomMm ?? 0,
186
+ marginLeftMm: e.marginLeftMm ?? 0,
187
+ marginRightMm: e.marginRightMm ?? 0,
185
188
  components: []
186
189
  };
187
190
  }
188
- function jt(t, e) {
189
- return e.heightMm - (t.marginBottomMm ?? e.marginBottomMm);
191
+ function Ge(e, t) {
192
+ return t.heightMm - (e.marginBottomMm ?? t.marginBottomMm);
190
193
  }
191
- function Ot(t, e) {
192
- const n = (t.fontSizePt ?? X) * Q * 25.4 / 72, o = (t.paddingMm ?? 1) * 2;
193
- return Math.max(t.rowHeightMm ?? 0, e * n + o);
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 yt(t) {
196
- if (t == null) return "";
197
- if (typeof t == "string") return t;
198
- if (typeof t == "number") return String(t);
199
- if (typeof t == "boolean") return t ? "是" : "否";
200
- if (t instanceof Date) return t.toISOString().slice(0, 10);
198
+ function ve(e) {
199
+ if (e == null) return "";
200
+ if (typeof e == "string") return e;
201
+ if (typeof e == "number") return String(e);
202
+ if (typeof e == "boolean") return e ? "是" : "否";
203
+ if (e instanceof Date) return e.toISOString().slice(0, 10);
201
204
  try {
202
- return JSON.stringify(t);
205
+ return JSON.stringify(e);
203
206
  } catch {
204
- return String(t);
207
+ return String(e);
205
208
  }
206
209
  }
207
- function Gt(t, e) {
208
- const r = t.fontSizePt ?? X, n = t.paddingMm ?? 1, o = t.columns.map(
209
- (l) => l.style ? { align: "left", verticalAlign: "middle", ...l.style } : { align: "left", verticalAlign: "middle" }
210
- ), a = t.columns.map(
211
- (l) => ({
212
- bold: t.headerBold ?? !0,
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,
216
+ bold: e.headerBold ?? !0,
213
217
  align: "center",
214
218
  verticalAlign: "middle",
215
- backgroundColor: t.headerBackgroundColor,
216
- ...l.style || {}
219
+ backgroundColor: e.headerBackgroundColor,
220
+ ...g.style || {}
217
221
  })
218
- ), s = t.columns.map((l) => l.header), i = s.map(
219
- (l, f) => Z(
220
- l,
221
- t.columns[f].widthMm - n * 2,
222
- { fontSizePt: r, bold: t.headerBold ?? !0 },
223
- e
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 },
227
+ t
224
228
  )
225
- ), c = Math.max(...i.map((l) => l.length), 1), d = Ot(t, c), h = s.map((l, f) => ({
226
- text: l,
227
- style: a[f]
228
- })), m = t.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: r,
231
- paddingMm: n,
234
+ fontSizePt: n,
235
+ paddingMm: r,
232
236
  cellStyles: o,
233
237
  borderStyle: m,
234
238
  headerHeightMm: d,
235
- headerGrid: { cells: [h], rowHeightsMm: [d] },
236
- columns: t.columns
239
+ headerGrid: {
240
+ cells: [h],
241
+ colWidthsMm: c,
242
+ rowHeightsMm: [d]
243
+ },
244
+ colWidthsMm: c,
245
+ columns: e.columns
237
246
  };
238
247
  }
239
- function gt(t, e, r) {
240
- const n = t.columns, o = new Array(n.length);
241
- let a = 1;
242
- for (let h = 0; h < n.length; h++) {
243
- const m = n[h];
244
- o[h] = m.format ? Mt(e[m.field], m.format) : yt(e[m.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 s = new Array(n.length);
247
- for (let h = 0; h < n.length; h++) {
255
+ const a = new Array(r.length);
256
+ for (let h = 0; h < r.length; h++) {
248
257
  const m = Z(
249
258
  o[h],
250
- n[h].widthMm - t.paddingMm * 2,
251
- { fontSizePt: t.fontSizePt },
252
- r
259
+ r[h].widthMm - e.paddingMm * 2,
260
+ { fontSizePt: e.fontSizePt },
261
+ n
253
262
  );
254
- s[h] = m, m.length > a && (a = m.length);
263
+ a[h] = m, m.length > i && (i = m.length);
255
264
  }
256
- const i = t.fontSizePt * Q * 25.4 / 72, c = Math.max(
257
- t.rowHeightFloorMm,
258
- a * i + t.paddingMm * 2
259
- ), d = new Array(n.length);
260
- for (let h = 0; h < n.length; h++) {
261
- const m = n[h];
262
- let l = t.cellStyles[h];
265
+ const s = e.fontSizePt * ee * 25.4 / 72, l = Math.max(
266
+ e.rowHeightFloorMm,
267
+ i * s + e.paddingMm * 2
268
+ ), d = new Array(r.length);
269
+ for (let h = 0; h < r.length; h++) {
270
+ const m = r[h];
271
+ let c = e.cellStyles[h];
263
272
  if (m.rules) {
264
- for (const f of m.rules)
265
- if (zt(e, f.when)) {
266
- l = { ...l ?? {}, ...f.style };
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
- d[h] = { text: o[h], style: l };
279
+ d[h] = { text: o[h], style: c };
271
280
  }
272
- return { grid: { cells: [d], rowHeightsMm: [c] }, heightMm: c };
281
+ return {
282
+ grid: { cells: [d], colWidthsMm: e.colWidthsMm, rowHeightsMm: [l] },
283
+ heightMm: l
284
+ };
273
285
  }
274
- function de(t, e, r = {}) {
275
- const n = typeof r == "number" ? { mmPerRow: r } : r, o = n.mmPerRow ?? 0, a = n.measurer ?? ot, s = [], i = [];
276
- let c = 0;
277
- const d = (m) => `${m}_${(++c).toString(36)}`, h = [];
278
- for (const m of t.pages) {
279
- const l = mt(m), f = () => jt(m, l), g = l.marginTopMm, w = [], A = () => {
280
- if (i.push({
281
- pageWidthMm: l.widthMm,
282
- pageHeightMm: l.heightMm,
283
- marginTopMm: l.marginTopMm,
284
- marginBottomMm: l.marginBottomMm,
285
- marginLeftMm: l.marginLeftMm,
286
- marginRightMm: l.marginRightMm,
287
- components: l.components
288
- }), w.length > 0) {
289
- const x = i.length;
290
- for (const b of w) {
291
- const P = {
292
- ...b,
293
- text: String(b.text ?? "").replace(/\{page\}/g, String(x))
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
300
+ }), y.length > 0) {
301
+ const x = s.length;
302
+ for (const M of y) {
303
+ const v = {
304
+ ...M,
305
+ text: String(M.text ?? "").replace(/\{page\}/g, String(x))
294
306
  };
295
- i[i.length - 1].components.push(P), P.text.includes("{totalPages}") && h.push(P);
307
+ s[s.length - 1].components.push(v), v.text.includes("{totalPages}") && h.push(v);
296
308
  }
297
309
  }
298
310
  };
299
311
  for (const x of m.components) {
300
312
  if (x.kind !== "list") {
301
313
  if (x.kind === "text" && typeof x.text == "string") {
302
- const p = x.text;
303
- if (p.includes("{page}") || p.includes("{totalPages}")) {
304
- w.push(x);
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
- l.components.push(x);
320
+ c.components.push(x);
309
321
  continue;
310
322
  }
311
- const b = x, P = e[b.dataset];
312
- Array.isArray(P) || s.push(`数据集 ${b.dataset} 未提供数据,列表 ${b.id ?? ""} 输出为空`);
313
- const S = Array.isArray(P) ? P : [], q = b.columns.reduce((p, M) => p + M.widthMm, 0), J = q > b.widthMm ? b.widthMm / q : 1, k = J === 1 ? b : { ...b, columns: b.columns.map((p) => ({ ...p, widthMm: p.widthMm * J })) }, $ = {
314
- ...Gt(k, a),
315
- rowHeightFloorMm: k.rowHeightMm ?? 0
316
- }, j = {
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
335
  nid: d("listh"),
324
336
  style: $.borderStyle
325
337
  };
326
- let u = b.topMm;
327
- const H = (p, M) => {
328
- p.components.push({ ...j, topMm: M });
338
+ let w = M.topMm;
339
+ const H = (b, p) => {
340
+ b.components.push({ ...G, topMm: p });
329
341
  };
330
- H(l, u), u += $.headerHeightMm + o;
331
- const L = (p) => {
332
- if (u + p > f()) {
333
- A();
334
- const M = mt(m);
335
- l.components = M.components, l.heightMm = M.heightMm, k.headerEveryPage !== !1 ? (H(l, 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
- }, y = (p, M, T) => {
338
- L(M), l.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: d(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
- }, N = () => gt($, {}, a).heightMm, C = (p, M, T, v) => {
349
- const D = [], ct = Math.max(1, Math.min(v, k.columns.length));
350
- D.push({ text: p, colSpan: ct, style: { bold: !0, ...T } });
351
- for (let et = ct; et < k.columns.length; et++) {
352
- const Ct = k.columns[et];
353
- D.push({ text: M.get(Ct.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 Pt = $.fontSizePt * Q * 25.4 / 72, dt = Math.max($.rowHeightFloorMm, Pt + $.paddingMm * 2);
356
- return { grid: { cells: [D], rowHeightsMm: [dt] }, heightMm: dt };
357
- }, _ = (p, M) => {
358
- let T = 0;
359
- for (const v of p) {
360
- const D = typeof v[M] == "number" ? v[M] : Number(v[M]);
361
- Number.isFinite(D) && (T += D);
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
- }, U = (p, M) => {
365
- const T = k.columns.find((v) => v.field === M);
366
- return Mt(_(p, M), T?.format ?? { kind: "number", thousands: !0 });
367
- }, F = k.groupBy, vt = typeof k.grandTotal == "object" && k.grandTotal.fields || F?.subtotal || [], st = k.columns.findIndex((p) => vt.includes(p.field)), at = st > 0 ? st : 1, Y = [];
368
- if (F) {
369
- const p = /* @__PURE__ */ new Map();
370
- for (const M of S) {
371
- const T = yt(M[F.field]), v = p.get(T);
372
- v ? v.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
- Y.push({
395
+ for (const [p, k] of b) {
396
+ J.push({
376
397
  kind: "groupHeader",
377
- label: (F.headerTemplate ?? "{value}").replace(/\{value\}/g, M)
398
+ label: (L.headerTemplate ?? "{value}").replace(/\{value\}/g, p)
378
399
  });
379
- for (const v of T) Y.push({ kind: "row", row: v });
380
- F.subtotal && F.subtotal.length > 0 && Y.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: F.subtotalLabel ?? "小计",
383
- rows: T
403
+ label: L.subtotalLabel ?? "小计",
404
+ rows: k
384
405
  });
385
406
  }
386
407
  } else
387
- for (const p of S) Y.push({ kind: "row", row: p });
388
- const lt = N();
389
- for (const p of Y)
390
- if (p.kind === "row") {
391
- const M = gt($, p.row, a);
392
- y(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
- F?.headerStyle ?? {},
398
- k.columns.length
418
+ L?.headerStyle ?? {},
419
+ E.columns.length
399
420
  );
400
- F?.keepWithNext !== !1 && u + M.heightMm + lt > f() && L(M.heightMm + lt), y(M.grid, M.heightMm, "listg");
401
- } else if (p.kind === "subtotal") {
402
- const M = /* @__PURE__ */ new Map();
403
- for (const v of F.subtotal ?? []) M.set(v, U(p.rows, v));
404
- const T = C(
405
- p.label,
406
- M,
407
- F?.subtotalStyle ?? {},
408
- at
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
- y(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 ?? F?.subtotal ?? [];
414
- if (M.length > 0) {
415
- const T = /* @__PURE__ */ new Map();
416
- for (const D of M) T.set(D, U(S, D));
417
- const v = C(
418
- p?.label ?? "合计",
419
- T,
420
- p?.style ?? {},
421
- at
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
- y(v.grid, v.heightMm, "listgt");
444
+ S(C.grid, C.heightMm, "listgt");
424
445
  } else
425
- s.push(`列表 ${b.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
446
+ a.push(`列表 ${M.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
426
447
  }
427
448
  }
428
- A();
449
+ P();
429
450
  }
430
451
  for (const m of h) {
431
- const l = m.text;
432
- typeof l == "string" && l.includes("{totalPages}") && (m.text = l.replace(/\{totalPages\}/g, String(i.length)));
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: Et, pages: i },
436
- warnings: s
456
+ plan: { schemaVersion: pe, pages: s },
457
+ warnings: a
437
458
  };
438
459
  }
439
- const Vt = {
460
+ const Je = {
440
461
  root: "mr-root",
441
462
  page: "mr-page",
442
463
  comp: "mr-comp",
@@ -453,264 +474,264 @@ const Vt = {
453
474
  cell: "mr-cell",
454
475
  unknown: "mr-unknown"
455
476
  };
456
- function B(t, e) {
457
- return e?.classNames?.[t] ?? Vt[t];
477
+ function N(e, t) {
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(e, r) {
464
- return r == null || r === !1 || r === "" ? this : (this.props.push([e, String(r)]), this);
484
+ add(t, n) {
485
+ return n == null || n === !1 || n === "" ? this : (this.props.push([t, String(n)]), this);
465
486
  }
466
- mm(e, r, n, o = 2) {
467
- return this.add(e, `${G($t(r, n), o)}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
- let e = "";
471
- for (const [r, n] of this.props)
472
- e += `${r}:${n};`;
473
- return e;
491
+ let t = "";
492
+ for (const [n, r] of this.props)
493
+ t += `${n}:${r};`;
494
+ return t;
474
495
  }
475
- applyTo(e) {
476
- const r = this.toString();
477
- r && (e.style.cssText = r);
496
+ applyTo(t) {
497
+ const n = this.toString();
498
+ n && (t.style.cssText = n);
478
499
  }
479
500
  }
480
- function wt(t, e, r) {
481
- const n = e.style || {};
482
- t.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 o = V(n, r);
484
- t.add("font-size", `${G(o.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 Yt(t, e, r, n, o) {
487
- const a = o.createElement("table");
488
- if (a.className = B("grid", n), new z().add("width", "100%").add("height", "100%").add("border-collapse", "collapse").add("table-layout", t.colWidthsMm ? "fixed" : "auto").applyTo(a), t.colWidthsMm) {
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) {
489
510
  const d = o.createElement("colgroup");
490
- for (const h of t.colWidthsMm) {
511
+ for (const h of e.colWidthsMm) {
491
512
  const m = o.createElement("col");
492
- new z().mm("width", h, r).applyTo(m), d.appendChild(m);
513
+ new F().mm("width", h, n).applyTo(m), d.appendChild(m);
493
514
  }
494
- a.appendChild(d);
515
+ i.appendChild(d);
495
516
  }
496
- const s = tt(e.style), i = O(e.style), c = s.inner ? `${G(i.widthPt * r / 72, 2)}px solid ${i.color}` : "";
497
- return t.cells.forEach((d, h) => {
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) => {
498
519
  const m = o.createElement("tr");
499
- m.className = B("row", n), t.rowHeightsMm?.[h] != null && new z().mm("height", t.rowHeightsMm[h], r).applyTo(m), (d || []).forEach((l) => {
500
- const f = o.createElement("td");
501
- f.className = B("cell", n), l?.colSpan && (f.colSpan = l.colSpan), l?.rowSpan && (f.rowSpan = l.rowSpan);
502
- const g = new z();
503
- if (c && g.add("border", c), l?.style) {
504
- const w = l.style;
505
- g.add("text-align", w.align).add("vertical-align", w.verticalAlign).add("background-color", w.backgroundColor).add("color", w.color).add("font-weight", w.bold ? "700" : void 0), g.add("font-size", `${G(V(w, r).fontSizePx, 2)}px`);
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), l?.text != null && (f.textContent = l.text), l?.children?.length)
508
- for (const w of l.children)
509
- f.appendChild(St(w, r, n, o));
510
- m.appendChild(f);
511
- }), a.appendChild(m);
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 qt(t, e, r, n) {
515
- const o = n.createElement("div");
516
- o.className = B("text", r);
517
- const a = t.style || {}, s = 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 (wt(s, t, e), s.applyTo(o), ut(t)) {
522
- const i = n.createElement("div");
523
- i.className = B("rich", r);
524
- for (const c of t.richParagraphs) {
525
- const d = n.createElement("div");
526
- d.className = B("paragraph", r), new z().add("text-align", c.align).add("line-height", c.lineHeight != null ? String(c.lineHeight) : void 0).mm("margin-top", c.spaceBeforeMm ?? 0, e).mm("margin-bottom", c.spaceAfterMm ?? 0, e).mm("text-indent", c.indentMm ?? 0, e).applyTo(d);
527
- for (const m of c.segments || []) {
528
- const l = n.createElement("span");
529
- if (l.className = B("segment", r), l.textContent = m.kind === "field" ? m.field ?? "" : m.text ?? "", m.style) {
530
- const f = new z().add("color", m.style.color).add("font-weight", m.style.bold ? "700" : void 0);
531
- f.add("font-size", `${G(V(m.style, e).fontSizePx, 2)}px`), f.applyTo(l);
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
- d.appendChild(l);
554
+ d.appendChild(c);
534
555
  }
535
- i.appendChild(d);
556
+ s.appendChild(d);
536
557
  }
537
- return o.appendChild(i), o;
558
+ return o.appendChild(s), o;
538
559
  }
539
- if (Array.isArray(t.lines) && t.lines.length > 0) {
540
- const i = n.createElement("div");
541
- i.className = B("lines", r), a.lineHeight != null && new z().add("line-height", String(a.lineHeight)).applyTo(i);
542
- for (const c of t.lines) {
543
- const d = n.createElement("div");
544
- d.className = B("line", r), d.textContent = c, i.appendChild(d);
560
+ if (Array.isArray(e.lines) && e.lines.length > 0) {
561
+ const s = r.createElement("div");
562
+ s.className = N("lines", n), i.lineHeight != null && new F().add("line-height", String(i.lineHeight)).applyTo(s);
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 o.appendChild(i), o;
567
+ return o.appendChild(s), o;
547
568
  }
548
- return o.textContent = t.text ?? "", o;
569
+ return o.textContent = e.text ?? "", o;
549
570
  }
550
- function Jt(t, e, r) {
551
- const n = r.createElement("img");
552
- return n.className = B("image", e), n.src = t.imageData, new z().add("width", "100%").add("height", "100%").add("object-fit", "contain").add("display", "block").applyTo(n), n.alt = t.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 ft(t, e, r, n) {
555
- const o = n.createElement("div");
556
- o.className = B("shape", r);
557
- const a = t.style || {}, s = O(a), i = tt(a), c = `${G(s.widthPt * e / 72, 2)}px solid ${s.color}`, d = new z();
558
- return t.grid || t.kind === "rect" ? (i.top && d.add("border-top", c), i.right && d.add("border-right", c), i.bottom && d.add("border-bottom", c), i.left && d.add("border-left", c)) : t.kind === "ellipse" ? (i.inner && d.add("border", c).add("border-radius", "50%"), a.backgroundColor && d.add("background-color", a.backgroundColor)) : t.kind === "line" && d.add("height", "0").add("border-top", c), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(o), o;
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 St(t, e, r, n) {
561
- const o = n.createElement("div");
562
- o.className = `${B("comp", r)} mr-kind-${t.kind}`;
563
- const a = new z().add("position", "absolute").mm("left", t.leftMm, e).mm("top", t.topMm, e).mm("width", t.widthMm, e).mm("height", t.heightMm, e).add("box-sizing", "border-box");
564
- if (wt(a, t, e), a.applyTo(o), At(t))
565
- return o.appendChild(Jt(t, r, n)), o;
566
- if (t.kind === "text")
567
- return o.appendChild(qt(t, e, r, n)), o;
568
- if (t.grid) {
569
- const i = ft(t, e, r, n);
570
- return i.appendChild(Yt(t.grid, t, e, r, n)), o.appendChild(i), o;
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;
587
+ if (e.kind === "text")
588
+ return o.appendChild(Ke(e, t, n, r)), o;
589
+ if (e.grid) {
590
+ const s = ue(e, t, n, r);
591
+ return s.appendChild(Ue(e.grid, e, t, n, r)), o.appendChild(s), o;
571
592
  }
572
- if (t.kind === "line" || t.kind === "rect" || t.kind === "ellipse" || t.kind === "chart")
573
- return o.appendChild(ft(t, e, r, n)), o;
574
- const s = n.createElement("div");
575
- return s.className = B("unknown", r), s.textContent = t.fallbackText ?? "", o.appendChild(s), o;
593
+ if (e.kind === "line" || e.kind === "rect" || e.kind === "ellipse" || e.kind === "chart")
594
+ return o.appendChild(ue(e, t, n, r)), o;
595
+ const a = r.createElement("div");
596
+ return a.className = N("unknown", n), a.textContent = e.fallbackText ?? "", o.appendChild(a), o;
576
597
  }
577
- function Ut(t, e, r, n) {
578
- const o = n.createElement("div");
579
- o.className = B("page", r), new z().add("position", "relative").mm("width", t.pageWidthMm, e).mm("height", t.pageHeightMm, e).add("background-color", "#fff").add("overflow", "hidden").add("box-sizing", "border-box").applyTo(o);
580
- for (const a of t.components)
581
- o.appendChild(St(a, e, r, n));
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));
582
603
  return o;
583
604
  }
584
- function he(t, e, r = {}) {
585
- const n = r.dpi ?? 96, o = e.createElement("div");
586
- return o.className = B("root", r), o.dataset.schemaVersion = t.schemaVersion, t.pages.forEach((a) => {
587
- o.appendChild(Ut(a, n, r, e));
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));
588
609
  }), o;
589
610
  }
590
- function Kt(t) {
591
- const { pageHeightsPx: e, viewportHeightPx: r, scrollTopPx: n, overscan: o = 1, gapPx: a = 0 } = t, s = e.length;
592
- if (s === 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), c = new Array(s + 1);
595
- c[0] = 0;
596
- for (let S = 0; S < s; S++)
597
- c[S + 1] = c[S] + Math.max(0, e[S] ?? 0) + i;
598
- const d = c[s], h = Math.max(0, n);
599
- let m = 0, l = 0, f = s - 1;
600
- for (; l <= f; ) {
601
- const S = l + f >> 1;
602
- c[S] <= h ? (m = S, l = 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(s - 1, m - o)), w = c[m] + Math.max(0, r);
605
- let A = s - 1;
606
- for (l = 0, f = s - 1; l <= f; ) {
607
- const S = l + f >> 1;
608
- c[S + 1] < w ? l = S + 1 : (A = 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 x = Math.min(s - 1, A + o), b = c[g], P = Math.max(0, d - c[x + 1]);
611
- return { start: g, end: x, padTopPx: b, padBottomPx: P };
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 it = 96 / 25.4;
614
- function Tt(t, e = 96) {
615
- const r = e / 96 * it;
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(t.pageWidthMm * r)),
618
- heightPx: Math.max(1, Math.round(t.pageHeightMm * r))
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 Xt(t, e, r) {
622
- const n = document.createElement("canvas"), { widthPx: o, heightPx: a } = Tt(t, r);
623
- n.width = Math.round(o * e), n.height = Math.round(a * e), n.style.width = `${o}px`, n.style.height = `${a}px`;
624
- const s = n.getContext("2d");
625
- if (!s)
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 s.scale(e, e), s.fillStyle = "#ffffff", s.fillRect(0, 0, o, a), { canvas: n, ctx: s };
648
+ return a.scale(t, t), a.fillStyle = "#ffffff", a.fillRect(0, 0, o, i), { canvas: r, ctx: a };
628
649
  }
629
- function me(t, e = 96) {
630
- return V(t, e).fontSizePx;
650
+ function ht(e, t = 96) {
651
+ return V(e, t).fontSizePx;
631
652
  }
632
- function xt(t, e, r, n, o, a, s, i = "top") {
633
- t.font = `${e.bold ? "bold " : ""}${e.fontSizePx}px ${s}`, t.fillStyle = e.color, t.textBaseline = "alphabetic";
634
- const c = e.fontSizePx * e.lineHeight, d = e.text === "" ? [""] : e.text.split(`
635
- `), h = d.length * c;
636
- let m = n;
637
- i === "middle" ? m = n + (a - h) / 2 : i === "bottom" && (m = n + a - h), d.forEach((l, f) => {
638
- t.textAlign = e.align === "center" ? "center" : e.align === "right" ? "right" : "left";
639
- const g = e.align === "center" ? r + o / 2 : e.align === "right" ? r + o : r;
640
- t.fillText(l, g, m + f * c + e.fontSizePx * 0.8, o);
641
- }), t.textAlign = "left";
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) => {
659
+ e.textAlign = t.align === "center" ? "center" : t.align === "right" ? "right" : "left";
660
+ const f = t.align === "center" ? n + o / 2 : t.align === "right" ? n + o : n;
661
+ e.fillText(c, f, m + g * l + t.fontSizePx * 0.8, o);
662
+ }), e.textAlign = "left";
642
663
  }
643
- function Zt(t, e, r, n, o, a, s, i, c, d, h) {
644
- const m = Rt(e, a / i, s / i), l = tt(r.style), f = O(r.style);
645
- for (const g of m.cells) {
646
- const w = g.cell.style?.backgroundColor;
647
- w && (t.fillStyle = w, t.fillRect(
648
- n + g.xMm * i,
649
- o + g.yMm * i,
650
- g.widthMm * i,
651
- g.heightMm * i
664
+ function tt(e, t, n, r, o, i, a, s, l, d, h) {
665
+ const m = Le(t, i / s, a / s), c = te(n.style), g = Y(n.style);
666
+ for (const f of m.cells) {
667
+ const y = f.cell.style?.backgroundColor;
668
+ y && (e.fillStyle = y, e.fillRect(
669
+ r + f.xMm * s,
670
+ o + f.yMm * s,
671
+ f.widthMm * s,
672
+ f.heightMm * s
652
673
  ));
653
674
  }
654
- if (l.inner) {
655
- t.strokeStyle = f.color, t.lineWidth = K(f.widthPt, c);
656
- for (const g of m.edges)
657
- t.beginPath(), g.kind === "v" ? (t.moveTo(n + g.pos * i, o + g.from * i), t.lineTo(n + g.pos * i, o + g.to * i)) : (t.moveTo(n + g.from * i, o + g.pos * i), t.lineTo(n + g.to * i, o + g.pos * i)), t.stroke();
658
- t.beginPath(), l.top && (t.moveTo(n, o), t.lineTo(n + a, o)), l.right && (t.moveTo(n + a, o), t.lineTo(n + a, o + s)), l.bottom && (t.moveTo(n + a, o + s), t.lineTo(n, o + s)), l.left && (t.moveTo(n, o + s), t.lineTo(n, o)), t.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 m.cells) {
661
- const w = typeof g.cell.text == "string" ? g.cell.text : "";
662
- if (!w) continue;
663
- const A = g.cell.style, x = A?.fontSize ?? X, b = Z(
664
- w,
665
- g.widthMm - 1,
681
+ for (const f of m.cells) {
682
+ const y = typeof f.cell.text == "string" ? f.cell.text : "";
683
+ if (!y) continue;
684
+ const P = f.cell.style, x = P?.fontSize ?? Q, M = Z(
685
+ y,
686
+ f.widthMm - 1,
666
687
  { fontSizePt: x },
667
688
  h
668
689
  ).join(`
669
690
  `);
670
- xt(
671
- t,
691
+ $e(
692
+ e,
672
693
  {
673
- text: b,
674
- fontSizePx: V(A, c).fontSizePx,
675
- bold: A?.bold ?? !1,
676
- color: A?.color ?? pt(r.style, Nt),
677
- align: A?.align ?? "left",
678
- lineHeight: Q
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
- o + g.yMm * i,
682
- Math.max(0, (g.widthMm - 1) * i),
683
- g.heightMm * i,
701
+ r + (f.xMm + 0.5) * s,
702
+ o + f.yMm * s,
703
+ Math.max(0, (f.widthMm - 1) * s),
704
+ f.heightMm * s,
684
705
  d,
685
- A?.verticalAlign ?? "middle"
706
+ P?.verticalAlign ?? "middle"
686
707
  );
687
708
  }
688
709
  }
689
- function kt(t, e, r, n, o, a) {
690
- const s = e.leftMm * r, i = e.topMm * r, c = e.widthMm * r, d = e.heightMm * r, h = e.style ?? {};
691
- if (e.grid) {
692
- Zt(t, e.grid, e, s, i, c, d, r, n, o, a);
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 ?? {};
712
+ if (t.grid) {
713
+ tt(e, t.grid, t, a, s, l, d, n, r, o, i);
693
714
  return;
694
715
  }
695
- switch (e.kind) {
716
+ switch (t.kind) {
696
717
  case "text": {
697
- const m = h.fontSize ?? X, l = ut(e) ? e.richParagraphs.map((f) => (f.segments ?? []).map((g) => g.text ?? g.field ?? "").join("")).join(`
698
- `) : Array.isArray(e.lines) && e.lines.length > 0 ? e.lines.join(`
699
- `) : Z(e.text ?? "", e.widthMm, { fontSizePt: m }, a).join(`
718
+ const m = h.fontSize ?? Q, c = Me(t) ? t.richParagraphs.map((g) => (g.segments ?? []).map((f) => f.text ?? f.field ?? "").join("")).join(`
719
+ `) : Array.isArray(t.lines) && t.lines.length > 0 ? t.lines.join(`
720
+ `) : Z(t.text ?? "", t.widthMm, { fontSizePt: m }, i).join(`
700
721
  `);
701
- xt(
702
- t,
722
+ $e(
723
+ e,
703
724
  {
704
- text: l,
705
- fontSizePx: V(h, n).fontSizePx,
725
+ text: c,
726
+ fontSizePx: V(h, r).fontSizePx,
706
727
  bold: h.bold ?? !1,
707
- color: pt(h),
728
+ color: we(h),
708
729
  align: h.align ?? "left",
709
- lineHeight: Ht(h)
730
+ lineHeight: Ne(h)
710
731
  },
732
+ a,
711
733
  s,
712
- i,
713
- c,
734
+ l,
714
735
  d,
715
736
  o,
716
737
  h.verticalAlign
@@ -718,273 +739,140 @@ function kt(t, e, r, n, o, a) {
718
739
  break;
719
740
  }
720
741
  case "rect": {
721
- const m = O(h), l = tt(h);
722
- h.backgroundColor && (t.fillStyle = h.backgroundColor, t.fillRect(s, i, c, d)), l.inner && (t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), t.beginPath(), l.top && (t.moveTo(s, i), t.lineTo(s + c, i)), l.right && (t.moveTo(s + c, i), t.lineTo(s + c, i + d)), l.bottom && (t.moveTo(s + c, i + d), t.lineTo(s, i + d)), l.left && (t.moveTo(s, i + d), t.lineTo(s, i)), t.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 m = O({ ...h, borderColor: h.lineColor ?? h.borderColor });
727
- t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), t.beginPath(), t.moveTo(s, i + d / 2), t.lineTo(s + c, i + d / 2), t.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 m = O(h);
732
- t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), h.backgroundColor && (t.fillStyle = h.backgroundColor, t.beginPath(), t.ellipse(s + c / 2, i + d / 2, c / 2, d / 2, 0, 0, Math.PI * 2), t.fill()), t.beginPath(), t.ellipse(s + c / 2, i + d / 2, c / 2, d / 2, 0, 0, Math.PI * 2), t.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 ge(t, e = {}) {
758
+ async function ft(e, t = {}) {
738
759
  if (typeof document > "u")
739
760
  throw new Error("renderPlanToImages 需要浏览器环境(SSR/Node 请在客户端钩子中调用)");
740
- const { format: r = "png", quality: n = 0.92, ...o } = e, { canvases: a } = Qt(t, o), s = r === "jpeg" ? "image/jpeg" : "image/png", i = [];
741
- for (const c 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
- (d) => c.toBlob((h) => d(h), s, n)
745
- ) ?? new Blob([], { type: s })
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 Qt(t, e = {}) {
770
+ function nt(e, t = {}) {
750
771
  if (typeof document > "u")
751
772
  throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");
752
- const r = e.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), n = e.dpi ?? 96, o = n / 96 * it, a = e.fontFamily ?? '"Microsoft YaHei", sans-serif', s = e.measurer ?? ot, i = Math.max(0, e.start ?? 0), c = Math.min(t.pages.length - 1, e.end ?? t.pages.length - 1), d = [];
753
- for (let h = i; h <= c; h++) {
754
- const m = t.pages[h], { canvas: l, ctx: f } = Xt(m, r, n);
755
- for (const g of m.components)
756
- kt(f, g, o, n, a, s);
757
- d.push(l);
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
780
  return { canvases: d };
760
781
  }
761
- function fe(t, e = {}) {
762
- const r = e.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), n = e.dpi ?? 96, o = n / 96 * it, a = e.fontFamily ?? '"Microsoft YaHei", sans-serif', s = e.measurer ?? ot, i = e.overscan ?? 1, c = e.gapPx ?? 18, d = e.pagesPerFrame ?? 1, h = t.pages.map((u) => u.pageHeightMm * o), m = Math.max(1, ...t.pages.map((u) => u.pageWidthMm * o)), l = { start: 0, end: -1 };
763
- let f = null, g = null, w = null, A = null, x = [], b = 0, P = [];
764
- function S() {
765
- const u = f;
766
- u.innerHTML = "", g = document.createElement("div"), g.style.cssText = `width:${m}px;margin:0 auto;`, w = document.createElement("div"), A = document.createElement("div"), g.appendChild(w), x = [];
767
- const H = Math.min(t.pages.length, 3 + i * 2);
768
- for (let L = 0; L < H; L++) {
769
- const y = document.createElement("div");
770
- y.style.cssText = `margin:0 auto ${c}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, g.appendChild(y), x.push(y);
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(A), u.appendChild(g);
793
+ f.appendChild(P), w.appendChild(f);
773
794
  }
774
- function q(u, H) {
775
- const L = t.pages[H], { widthPx: y, heightPx: N } = Tt(L, n);
776
- let C = u.firstElementChild;
777
- (!C || C.tagName !== "CANVAS") && (C = document.createElement("canvas"), u.innerHTML = "", u.appendChild(C)), C.width = Math.round(y * r), C.height = Math.round(N * r), C.style.width = `${y}px`, C.style.height = `${N}px`;
778
- const _ = C.getContext("2d");
779
- if (_) {
780
- _.setTransform(1, 0, 0, 1, 0, 0), _.scale(r, r), _.fillStyle = "#ffffff", _.fillRect(0, 0, y, N);
781
- for (const U of L.components)
782
- kt(_, U, o, n, a, s);
783
- C.dataset.canvasPage = String(H), u.style.height = `${N}px`, u.style.width = `${y}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 J(u) {
787
- l.start = u.start, l.end = u.end, w.style.height = `${u.start * c + h.slice(0, u.start).reduce((y, N) => y + N, 0)}px`;
788
- const H = t.pages.length - 1 - u.end;
789
- A.style.height = `${H * c + h.slice(u.end + 1).reduce((y, N) => y + N, 0)}px`;
790
- const L = u.end - u.start + 1;
791
- x.forEach((y, N) => {
792
- if (N < L) {
793
- y.style.display = "";
794
- const C = u.start + N;
795
- y.style.height = `${h[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
- y.style.display = "none";
798
- }), P = [];
799
- for (let y = u.start; y <= u.end; y++) {
800
- const N = x[y - u.start];
801
- if (!N) continue;
802
- N.firstElementChild?.dataset?.canvasPage !== String(y) && P.push(y);
818
+ S.style.display = "none";
819
+ }), v = [];
820
+ for (let S = w.start; S <= w.end; S++) {
821
+ const R = x[S - w.start];
822
+ if (!R) continue;
823
+ R.firstElementChild?.dataset?.canvasPage !== String(S) && v.push(S);
803
824
  }
804
- k();
825
+ E();
805
826
  }
806
- function k() {
807
- b || P.length === 0 || (b = requestAnimationFrame(() => {
808
- b = 0;
809
- let u = Math.max(1, d);
810
- for (; P.length > 0 && u-- > 0; ) {
811
- const H = P.shift(), L = x[H - l.start];
812
- L && q(L, H);
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
- P.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, H = Kt({
839
+ M || (M = requestAnimationFrame(() => {
840
+ M = 0;
841
+ const w = g, H = Ze({
821
842
  pageHeightsPx: h,
822
- viewportHeightPx: u.clientHeight,
823
- scrollTopPx: u.scrollTop,
824
- overscan: i,
825
- gapPx: c
843
+ viewportHeightPx: w.clientHeight,
844
+ scrollTopPx: w.scrollTop,
845
+ overscan: s,
846
+ gapPx: l
826
847
  });
827
- H.start !== l.start || H.end !== l.end ? J(H) : k();
848
+ H.start !== c.start || H.end !== c.end ? I(H) : E();
828
849
  }));
829
850
  }
830
- let j = 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" && (j = new ResizeObserver(() => $()), j.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, j?.disconnect(), j = null, f?.removeEventListener("scroll", $), P = [], 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 { ...l };
862
+ return { ...c };
842
863
  }
843
864
  };
844
865
  }
845
- function E(t, e) {
846
- return typeof t == "number" && Number.isFinite(t) ? t : e;
847
- }
848
- function R(t, e = "") {
849
- return typeof t == "string" ? t : e;
850
- }
851
- function W(t) {
852
- return typeof t == "object" && t !== null && !Array.isArray(t);
853
- }
854
- function te(t) {
855
- return t === "Center" ? "center" : t === "Right" ? "right" : "left";
856
- }
857
- function ee(t) {
858
- return t === "Center" ? "middle" : t === "Bottom" ? "bottom" : "top";
859
- }
860
- function ne(t) {
861
- const e = parseFloat(R(t.FontSize, "10.5"));
862
- return {
863
- fontSize: Number.isFinite(e) ? e : 10.5,
864
- fontFamily: R(t.FontFamily, "黑体") || void 0,
865
- bold: R(t.FontWeight) === "bold" || void 0,
866
- italic: R(t.FontStyle) === "italic" || void 0,
867
- underline: t.Underline === !0 || void 0,
868
- color: R(t.FontColor) || void 0,
869
- backgroundColor: R(t.BackgroundColor) || void 0,
870
- align: te(R(t.HorAlignment, "Left")),
871
- verticalAlign: ee(R(t.VertAlignment, "Top")),
872
- lineHeight: (() => {
873
- const r = parseFloat(R(t.RowSpace, "1"));
874
- return Number.isFinite(r) && r !== 1 ? r : void 0;
875
- })(),
876
- borderColor: R(t.BorderColor) || void 0,
877
- borderTop: t.BorderTop !== !1,
878
- borderRight: t.BorderRight !== !1,
879
- borderBottom: t.BorderBottom !== !1,
880
- borderLeft: t.BorderLeft !== !1
881
- };
882
- }
883
- function re(t, e) {
884
- const r = R(t.uitype), n = {
885
- kind: "text",
886
- leftMm: E(t.left, 0),
887
- topMm: E(t.top, 0),
888
- widthMm: E(t.width, 40),
889
- heightMm: E(t.height, 8),
890
- nid: R(t.nid) || void 0,
891
- style: ne(t)
892
- };
893
- switch (r) {
894
- case "text": {
895
- n.kind = "text";
896
- const o = t.Text ?? t.text ?? t.Value;
897
- n.text = o == null ? "" : String(o);
898
- const a = t.Lines ?? t.lines;
899
- return Array.isArray(a) && (n.lines = a.map((s) => String(s))), n;
900
- }
901
- case "richtext":
902
- return n.kind = "text", n.text = R(t.Text), e.push(`富文本 ${n.nid ?? ""} 导入为纯文本(版式细节可能损失)`), n;
903
- case "image":
904
- case "barcode":
905
- case "qrcode":
906
- case "chart":
907
- return n.kind = r === "image" ? "image" : r, n.fallbackText = `[${r}]`, e.push(`图片类组件 ${n.nid ?? ""} 需运行时数据(imageData),已导入为占位`), n;
908
- case "table": {
909
- n.kind = "rect";
910
- const o = t.Cells ?? t.cells;
911
- if (Array.isArray(o)) {
912
- const a = {
913
- cells: o.map(
914
- (s) => Array.isArray(s) ? s.map((i) => ({
915
- text: W(i) ? R(i.Text ?? i.text) : "",
916
- colSpan: W(i) ? E(i.ColSpan, 1) : 1
917
- })) : []
918
- )
919
- };
920
- n.grid = a;
921
- } else
922
- n.fallbackText = "[table]", e.push(`表格 ${n.nid ?? ""} 缺少 Cells,导入为空框`);
923
- return n;
924
- }
925
- case "subreport":
926
- return e.push(`子报表 ${n.nid ?? ""} 暂不支持导入,已跳过`), null;
927
- default:
928
- return R(t.ShapeType) === "hline" || r === "hline" || r === "vline" ? (n.kind = "line", n) : r === "rect" || r === "oval" || r === "shape" ? (n.kind = r === "oval" ? "ellipse" : "rect", n) : (e.push(`未知组件类型 ${r},已跳过`), null);
929
- }
866
+ function Ee(e, t, n) {
867
+ let r, o;
868
+ if (typeof e == "string") {
869
+ const i = X[e];
870
+ if (!i) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(X).join("/")})`);
871
+ r = i.widthMm, o = i.heightMm;
872
+ } else typeof e == "number" ? (r = e, o = t ?? 297) : (r = e.widthMm, o = e.heightMm);
873
+ return n ? { widthMm: o, heightMm: r } : { widthMm: r, heightMm: o };
930
874
  }
931
- function ue(t) {
932
- const e = [];
933
- let r = null;
934
- if (typeof t == "string")
935
- try {
936
- const d = JSON.parse(t);
937
- W(d) && (r = d);
938
- } catch {
939
- return {
940
- template: { pages: [] },
941
- warnings: ["content 不是合法 JSON"]
942
- };
943
- }
944
- else W(t) && (r = t);
945
- if (!r)
946
- return { template: { pages: [] }, warnings: ["content 为空"] };
947
- const n = W(r.GlobalConfig) ? r.GlobalConfig : {}, o = E(n.paperWidthMm, 210), a = E(n.paperHeightMm, 297), s = {
948
- top: E(n.marginTop, 10),
949
- bottom: E(n.marginBottom, 10),
950
- left: E(n.marginLeft, 10),
951
- right: E(n.marginRight, 10)
952
- }, i = Array.isArray(r.children) ? r.children.filter((d) => W(d) && R(d.uitype) === "page") : [];
953
- i.length === 0 && e.push("content 中没有 uitype=page 的页节点");
954
- const c = i.map((d) => {
955
- const h = d, m = Array.isArray(h.children) ? h.children : [], l = [];
956
- for (const f of m) {
957
- if (!W(f)) continue;
958
- const g = re(f, e);
959
- g && l.push(g);
960
- }
961
- return {
962
- widthMm: E(h.width, o),
963
- heightMm: E(h.DesignHeight, a),
964
- marginTopMm: E(h.MarginTop, s.top),
965
- marginBottomMm: E(h.MarginBottom, s.bottom),
966
- marginLeftMm: E(h.MarginLeft, s.left),
967
- marginRightMm: E(h.MarginRight, s.right),
968
- components: l
969
- };
970
- });
971
- return c.length === 0 && (e.push("转换结果为空页,已回退一张空白页"), c.push({
972
- widthMm: o,
973
- heightMm: a,
974
- ...s,
975
- components: []
976
- })), { template: { pages: c }, warnings: e };
977
- }
978
- function oe(t, e, r) {
979
- let n, o;
980
- if (typeof t == "string") {
981
- const a = ht[t];
982
- if (!a) throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(ht).join("/")})`);
983
- n = a.widthMm, o = a.heightMm;
984
- } else typeof t == "number" ? (n = t, o = e ?? 297) : (n = t.widthMm, o = t.heightMm);
985
- return r ? { widthMm: o, heightMm: n } : { widthMm: n, heightMm: o };
986
- }
987
- class ie {
875
+ class rt {
988
876
  constructor() {
989
877
  this.pages = [], this.pending = null, this.templateParams = void 0;
990
878
  }
@@ -1002,8 +890,8 @@ class ie {
1002
890
  * .build();
1003
891
  * ```
1004
892
  */
1005
- params(e) {
1006
- return this.templateParams = e, this;
893
+ params(t) {
894
+ return this.templateParams = t, this;
1007
895
  }
1008
896
  /**
1009
897
  * 新建页。纸张支持三种写法:
@@ -1011,20 +899,20 @@ class ie {
1011
899
  * - 数字:.page(210, 297)(第三参数兼容旧 margins 对象或新 options)
1012
900
  * - 对象:.page({ widthMm: 210, heightMm: 297 })
1013
901
  */
1014
- page(e = "a4", r = {}, n) {
902
+ page(t = "a4", n = {}, r) {
1015
903
  this.collect();
1016
- 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: s, heightMm: i } = oe(
1017
- e,
1018
- typeof r == "number" ? r : void 0,
1019
- a.landscape
1020
- ), c = a.margins ?? {};
1021
- return this.pending = new se(this, {
1022
- widthMm: s,
1023
- heightMm: i,
1024
- marginTopMm: c.marginTopMm ?? 10,
1025
- marginBottomMm: c.marginBottomMm ?? 10,
1026
- marginLeftMm: c.marginLeftMm ?? 10,
1027
- marginRightMm: c.marginRightMm ?? 10
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(
905
+ t,
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
1028
916
  }), this.pending;
1029
917
  }
1030
918
  collect() {
@@ -1036,63 +924,63 @@ class ie {
1036
924
  return this.templateParams ? { params: this.templateParams, pages: this.pages } : { pages: this.pages };
1037
925
  }
1038
926
  }
1039
- class se {
1040
- constructor(e, r) {
1041
- this.parent = e, this.page = r, this.components = [];
927
+ class ot {
928
+ constructor(t, n) {
929
+ this.parent = t, this.page = n, this.components = [];
1042
930
  }
1043
- text(e, r = {}, n = {}) {
931
+ text(t, n = {}, r = {}) {
1044
932
  return this.components.push({
1045
933
  kind: "text",
1046
- leftMm: r.leftMm ?? 0,
1047
- topMm: r.topMm ?? 0,
1048
- widthMm: r.widthMm ?? 60,
1049
- heightMm: r.heightMm ?? 8,
1050
- text: e,
1051
- style: n
934
+ leftMm: n.leftMm ?? 0,
935
+ topMm: n.topMm ?? 0,
936
+ widthMm: n.widthMm ?? 60,
937
+ heightMm: n.heightMm ?? 8,
938
+ text: t,
939
+ style: r
1052
940
  }), this;
1053
941
  }
1054
- list(e, r, n, o = {}) {
942
+ list(t, n, r, o = {}) {
1055
943
  return this.components.push({
1056
944
  kind: "list",
1057
- leftMm: r.leftMm ?? 10,
1058
- topMm: r.topMm ?? 30,
1059
- widthMm: r.widthMm ?? 180,
1060
- dataset: e,
1061
- columns: n,
945
+ leftMm: n.leftMm ?? 10,
946
+ topMm: n.topMm ?? 30,
947
+ widthMm: n.widthMm ?? 180,
948
+ dataset: t,
949
+ columns: r,
1062
950
  ...o
1063
951
  }), this;
1064
952
  }
1065
- rect(e, r = {}) {
1066
- return this.components.push({ kind: "rect", ...e, style: r }), this;
953
+ rect(t, n = {}) {
954
+ return this.components.push({ kind: "rect", ...t, style: n }), this;
1067
955
  }
1068
- line(e, r, n, o = {}) {
956
+ line(t, n, r, o = {}) {
1069
957
  return this.components.push({
1070
958
  kind: "line",
1071
- leftMm: e,
1072
- topMm: r,
1073
- widthMm: n,
959
+ leftMm: t,
960
+ topMm: n,
961
+ widthMm: r,
1074
962
  heightMm: 0.5,
1075
963
  style: o
1076
964
  }), this;
1077
965
  }
1078
- barcode(e, r) {
966
+ barcode(t, n) {
1079
967
  return this.components.push({
1080
968
  kind: "barcode",
1081
- leftMm: r.leftMm ?? 0,
1082
- topMm: r.topMm ?? 0,
1083
- widthMm: r.widthMm ?? 40,
1084
- heightMm: r.heightMm ?? 12,
1085
- fallbackText: e
969
+ leftMm: n.leftMm ?? 0,
970
+ topMm: n.topMm ?? 0,
971
+ widthMm: n.widthMm ?? 40,
972
+ heightMm: n.heightMm ?? 12,
973
+ fallbackText: t
1086
974
  }), this;
1087
975
  }
1088
- qrcode(e, r, n, o) {
976
+ qrcode(t, n, r, o) {
1089
977
  return this.components.push({
1090
978
  kind: "qrcode",
1091
- leftMm: n,
979
+ leftMm: r,
1092
980
  topMm: o,
1093
- widthMm: r,
1094
- heightMm: r,
1095
- fallbackText: e
981
+ widthMm: n,
982
+ heightMm: n,
983
+ fallbackText: t
1096
984
  }), this;
1097
985
  }
1098
986
  buildPage() {
@@ -1105,64 +993,229 @@ class se {
1105
993
  return this.done().build();
1106
994
  }
1107
995
  }
1108
- function pe() {
1109
- return new ie();
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
+ });
1110
1163
  }
1111
1164
  export {
1112
- ye as CSS_DPI,
1113
- we as DEFAULT_BORDER_PT,
1114
- X as DEFAULT_FONT_PT,
1115
- Se as DEFAULT_STROKE_COLOR,
1116
- Nt as DEFAULT_TEXT_COLOR,
1117
- Q as LINE_HEIGHT,
1118
- Te as MM_PER_INCH,
1119
- ht as PAPER_SIZES,
1120
- se as PageBuilder,
1121
- Et as RENDER_PLAN_SCHEMA_VERSION,
1122
- xe as SCHEMA_VERSION_JH4J,
1123
- ke as SCHEMA_VERSION_LOCAL,
1124
- ve as SCHEMA_VERSION_MACH,
1125
- ie as TemplateBuilder,
1126
- ce as assertRenderPlan,
1127
- Pe as charWidthEm,
1128
- B as classOf,
1129
- Kt as computePageWindow,
1130
- Ce as createCanvasMeasurer,
1131
- fe as createCanvasPager,
1132
- Ee as createHeuristicMeasurer,
1133
- pe as createTemplate,
1134
- zt as evalStyleRule,
1135
- Mt as formatValue,
1136
- ot as heuristicMeasurer,
1137
- ue as importJh4jTemplateContent,
1138
- At as isImageBackedComponent,
1139
- ut as isRichText,
1140
- Tt as measurePageSizePx,
1141
- Ae as measureTextMm,
1142
- $t as mmToPx,
1143
- $e as mmToPxFactor,
1144
- de as paginateTemplate,
1145
- Bt as parseDateLocal,
1146
- me as planFontSizePx,
1165
+ St as CSS_DPI,
1166
+ vt as DEFAULT_BORDER_PT,
1167
+ Q as DEFAULT_FONT_PT,
1168
+ Pt as DEFAULT_STROKE_COLOR,
1169
+ Be as DEFAULT_TEXT_COLOR,
1170
+ ee as LINE_HEIGHT,
1171
+ Tt as MM_PER_INCH,
1172
+ X as PAPER_SIZES,
1173
+ ot as PageBuilder,
1174
+ pe as RENDER_PLAN_SCHEMA_VERSION,
1175
+ W as ReportSourceError,
1176
+ xt as SCHEMA_VERSION_MACH,
1177
+ rt as TemplateBuilder,
1178
+ dt as assertRenderPlan,
1179
+ $t as charWidthEm,
1180
+ N as classOf,
1181
+ Ze as computePageWindow,
1182
+ kt as createCanvasMeasurer,
1183
+ gt as createCanvasPager,
1184
+ Et as createHeuristicMeasurer,
1185
+ wt as createReportSource,
1186
+ pt as createTableTemplate,
1187
+ ut as createTemplate,
1188
+ Mt as defineReport,
1189
+ je as evalStyleRule,
1190
+ be as formatValue,
1191
+ ie as heuristicMeasurer,
1192
+ He as isImageBackedComponent,
1193
+ Me as isRichText,
1194
+ xe as measurePageSizePx,
1195
+ Ct as measureTextMm,
1196
+ Re as mmToPx,
1197
+ At as mmToPxFactor,
1198
+ Ve as paginateTemplate,
1199
+ Fe as parseDateLocal,
1200
+ ht as planFontSizePx,
1147
1201
  K as ptToPx,
1148
- He as pxToMm,
1149
- St as renderComponent,
1150
- Ut as renderPage,
1151
- he as renderPlan,
1152
- Qt as renderPlanToCanvas,
1153
- ge as renderPlanToImages,
1154
- tt as resolveBoxBorders,
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,
1155
1209
  V as resolveFontSize,
1156
- Rt as resolveGridLayout,
1157
- Ht as resolveLineHeight,
1158
- oe as resolvePaper,
1159
- O as resolveStroke,
1160
- pt as resolveTextColor,
1161
- G as round,
1162
- rt as toNumber,
1163
- Ne as toRenderPlan,
1164
- bt as validateComponent,
1165
- Wt as validatePage,
1166
- It as validateRenderPlan,
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,
1167
1220
  Z as wrapText
1168
1221
  };