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