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