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