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