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