@agile-team/mach-report 2.8.4 → 2.9.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 +27 -9
- package/dist/ExcelBindingWizard-DiaxvWpQ.cjs +1 -0
- package/dist/ExcelBindingWizard-RLJIXKKG.js +816 -0
- package/dist/{ReportPreview-DTWiCH5a.js → ReportPreview-B5ZNEasW.js} +22 -21
- package/dist/ReportPreview-DRtVPUYo.cjs +6 -0
- package/dist/RuleEditor-CskN5Fr3.cjs +1 -0
- package/dist/RuleEditor-CtJFzKuY.js +1578 -0
- package/dist/TemplateReviewPanel-C_Lmzis6.cjs +1 -0
- package/dist/TemplateReviewPanel-Cn32OY4_.js +173 -0
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +188 -5
- package/dist/analytics.d.ts +188 -5
- package/dist/analytics.js +68 -202
- package/dist/{assets-B9qJku3V.js → assets-DDsfEi8R.js} +3 -3
- package/dist/{assets-RZan7EyL.cjs → assets-ahTRUXRk.cjs} +1 -1
- package/dist/binding-preview-B5834rml.cjs +2 -0
- package/dist/binding-preview-ChXjN5L5.js +649 -0
- package/dist/{capabilities-joSutDF8.js → capabilities-Cm9hZ3uV.js} +5 -5
- package/dist/{capabilities-xGTpnPjJ.cjs → capabilities-DYzWL7KS.cjs} +1 -1
- package/dist/dataset-BkRmwgeJ.cjs +1 -0
- package/dist/dataset-H5pFuQGU.js +121 -0
- package/dist/defaults-DXhiM1ZD.js +10 -0
- package/dist/defaults-xhmcLLrf.cjs +1 -0
- package/dist/designer.cjs +2 -1
- package/dist/designer.d.cts +1373 -6
- package/dist/designer.d.ts +1373 -6
- package/dist/designer.js +2495 -767
- package/dist/grid-geometry-BNptEcMm.js +65 -0
- package/dist/grid-geometry-CZ_cYB6O.cjs +1 -0
- package/dist/import-template-CNMLJSQw.js +23030 -0
- package/dist/import-template-CpxunKVp.cjs +29 -0
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +202 -3
- package/dist/index.d.ts +202 -3
- package/dist/index.js +554 -535
- package/dist/matrix-CNPDJxED.js +745 -0
- package/dist/matrix-Div9Ilh3.cjs +1 -0
- package/dist/pdf.cjs +46 -46
- package/dist/pdf.d.cts +2 -0
- package/dist/pdf.d.ts +2 -0
- package/dist/pdf.js +17 -16
- package/dist/{plugin-CQmJXNcA.js → plugin-BWwIgZXV.js} +1 -1
- package/dist/{plugin-DSFu51Ua.cjs → plugin-Dg-J1Rbm.cjs} +1 -1
- package/dist/progress-7OSZbFok.js +39 -0
- package/dist/progress-BnLiS5eH.cjs +1 -0
- package/dist/render-plan-7xpGrCEl.cjs +1 -0
- package/dist/render-plan-Ck6koX9L.js +13 -0
- package/dist/server/node.d.cts +62 -0
- package/dist/server/node.d.ts +62 -0
- package/dist/server-node.cjs +1 -1
- package/dist/server-node.js +373 -145
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +311 -0
- package/dist/server.d.ts +311 -0
- package/dist/server.js +590 -186
- package/dist/{style-Dv5o_x6b.js → style-CQ1PK8ZB.js} +5 -5
- package/dist/style-UgIJSA1F.cjs +1 -0
- package/dist/style.css +1 -1
- package/dist/template-registry-CHMYZ7SD.cjs +1 -0
- package/dist/template-registry-R61AMCr0.js +433 -0
- package/dist/template-review-hvWWQFsi.js +1027 -0
- package/dist/template-review-jEcOfmGr.cjs +1 -0
- package/dist/textwrap-CWHyzkBH.cjs +4 -0
- package/dist/{textwrap-DOl04hCQ.js → textwrap-DE1kgcJB.js} +1 -1
- package/dist/{validate-DfHPD8wX.cjs → validate-BDiMqkJC.cjs} +1 -1
- package/dist/{validate-S6CgIm5d.js → validate-DWPF7icl.js} +13 -13
- package/dist/vue/async.d.cts +186 -0
- package/dist/vue/async.d.ts +186 -0
- package/dist/vue/index.d.cts +271 -3
- package/dist/vue/index.d.ts +271 -3
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +4 -4
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +1 -1
- package/dist/xlsx.cjs +2 -30
- package/dist/xlsx.d.cts +268 -0
- package/dist/xlsx.d.ts +268 -0
- package/dist/xlsx.js +220 -23440
- package/package.json +1 -1
- package/dist/ReportPreview-DjGeWHY-.cjs +0 -6
- package/dist/progress-DD964VAB.js +0 -102
- package/dist/progress-KvhwXZ1Q.cjs +0 -1
- package/dist/render-plan-CckPEQyf.cjs +0 -1
- package/dist/render-plan-uzZYYSy1.js +0 -19
- package/dist/report-source-BXHNy_AD.js +0 -755
- package/dist/report-source-CCAvFE3t.cjs +0 -1
- package/dist/style-CpwiOPyB.cjs +0 -1
- package/dist/template-registry-DWExx0gU.cjs +0 -1
- package/dist/template-registry-NpOakidD.js +0 -354
- package/dist/textwrap-CnGsEum6.cjs +0 -4
|
@@ -1,755 +0,0 @@
|
|
|
1
|
-
import { R as _, d as re, D as q, L as z } from "./render-plan-uzZYYSy1.js";
|
|
2
|
-
import { h as oe, w as K } from "./textwrap-DOl04hCQ.js";
|
|
3
|
-
import { e as $, a as G } from "./style-Dv5o_x6b.js";
|
|
4
|
-
import { c as ae } from "./validate-S6CgIm5d.js";
|
|
5
|
-
import { g as ie } from "./report-params-B_VCihAh.js";
|
|
6
|
-
import { v as se, a as me } from "./template-registry-NpOakidD.js";
|
|
7
|
-
import { a as B } from "./param-validation-BWNjLcN0.js";
|
|
8
|
-
import { c as ce } from "./task-events-Dpsvf_t2.js";
|
|
9
|
-
function Y(e) {
|
|
10
|
-
if (!e || e.kind === "date") return;
|
|
11
|
-
const t = e.digits;
|
|
12
|
-
if (!(t !== void 0 && (!Number.isInteger(t) || t < 0 || t > 100))) {
|
|
13
|
-
if (e.kind === "percent") {
|
|
14
|
-
const n = t ?? 2;
|
|
15
|
-
return `0${n ? `.${"0".repeat(n)}` : ""}%`;
|
|
16
|
-
}
|
|
17
|
-
return t === void 0 ? e.thousands ? "#,##0.###############" : void 0 : `${e.thousands ? "#,##0" : "0"}${t ? `.${"0".repeat(t)}` : ""}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function ue(e) {
|
|
21
|
-
const t = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());
|
|
22
|
-
if (t) {
|
|
23
|
-
const r = new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
|
|
24
|
-
return Number.isNaN(r.getTime()) ? null : r;
|
|
25
|
-
}
|
|
26
|
-
const n = new Date(e);
|
|
27
|
-
return Number.isNaN(n.getTime()) ? null : n;
|
|
28
|
-
}
|
|
29
|
-
function A(e, t) {
|
|
30
|
-
return e.toLocaleString("en-US", {
|
|
31
|
-
minimumFractionDigits: t,
|
|
32
|
-
maximumFractionDigits: t
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function le(e, t) {
|
|
36
|
-
const n = (r) => String(r).padStart(2, "0");
|
|
37
|
-
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()));
|
|
38
|
-
}
|
|
39
|
-
function de(e, t, n) {
|
|
40
|
-
return n != null ? t ? A(e, n) : e.toFixed(n) : t ? A(e) : String(e);
|
|
41
|
-
}
|
|
42
|
-
function H(e) {
|
|
43
|
-
const t = typeof e == "number" ? e : Number(String(e).replace(/,/g, ""));
|
|
44
|
-
return Number.isFinite(t) ? t : null;
|
|
45
|
-
}
|
|
46
|
-
function V(e, t) {
|
|
47
|
-
if (e == null || e === "" || !t) return String(e ?? "");
|
|
48
|
-
switch (t.kind) {
|
|
49
|
-
case "number": {
|
|
50
|
-
const n = H(e);
|
|
51
|
-
return n == null ? String(e) : de(n, t.thousands === !0, t.digits);
|
|
52
|
-
}
|
|
53
|
-
case "percent": {
|
|
54
|
-
const n = H(e);
|
|
55
|
-
return n == null ? String(e) : `${A(n * 100, t.digits ?? 2)}%`;
|
|
56
|
-
}
|
|
57
|
-
case "date": {
|
|
58
|
-
const n = t.pattern ?? "YYYY-MM-DD", r = e instanceof Date ? e : ue(String(e));
|
|
59
|
-
return r ? le(r, n) : String(e);
|
|
60
|
-
}
|
|
61
|
-
default:
|
|
62
|
-
return String(e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function fe(e, t) {
|
|
66
|
-
const n = e[t.field];
|
|
67
|
-
if (n == null || n === "") return !1;
|
|
68
|
-
if (typeof t.value == "number") {
|
|
69
|
-
const i = H(n);
|
|
70
|
-
if (i == null) return !1;
|
|
71
|
-
switch (t.op) {
|
|
72
|
-
case ">":
|
|
73
|
-
return i > t.value;
|
|
74
|
-
case ">=":
|
|
75
|
-
return i >= t.value;
|
|
76
|
-
case "<":
|
|
77
|
-
return i < t.value;
|
|
78
|
-
case "<=":
|
|
79
|
-
return i <= t.value;
|
|
80
|
-
case "==":
|
|
81
|
-
return i === t.value;
|
|
82
|
-
case "!=":
|
|
83
|
-
return i !== t.value;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const r = String(n), o = String(t.value);
|
|
87
|
-
switch (t.op) {
|
|
88
|
-
case "==":
|
|
89
|
-
return r === o;
|
|
90
|
-
case "!=":
|
|
91
|
-
return r !== o;
|
|
92
|
-
case ">":
|
|
93
|
-
return r > o;
|
|
94
|
-
case ">=":
|
|
95
|
-
return r >= o;
|
|
96
|
-
case "<":
|
|
97
|
-
return r < o;
|
|
98
|
-
case "<=":
|
|
99
|
-
return r <= o;
|
|
100
|
-
}
|
|
101
|
-
return !1;
|
|
102
|
-
}
|
|
103
|
-
const ge = ["text", "number", "boolean", "date", "decimal"], he = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
104
|
-
function v(e) {
|
|
105
|
-
throw new Error(`数据契约无效:${e}`);
|
|
106
|
-
}
|
|
107
|
-
function J(e) {
|
|
108
|
-
(!e || !Array.isArray(e.fields) || !e.fields.length || e.fields.length > 2048) && v("fields 应包含 1–2048 个字段");
|
|
109
|
-
const t = /* @__PURE__ */ new Set();
|
|
110
|
-
for (const n of e.fields)
|
|
111
|
-
(!n || typeof n.field != "string" || !n.field.trim() || he.has(n.field) || t.has(n.field)) && v("字段名应安全、非空且唯一"), t.add(n.field), ge.includes(n.type) || v(`未知字段类型 ${n.type}`), be(n), we(n), pe(n);
|
|
112
|
-
ye(e, t);
|
|
113
|
-
}
|
|
114
|
-
function pe(e) {
|
|
115
|
-
e.enum !== void 0 && (!Array.isArray(e.enum) || !e.enum.length || e.enum.some((t) => !U(t, e.type))) && v("enum 应为匹配字段类型的非空标量数组");
|
|
116
|
-
}
|
|
117
|
-
function ye(e, t) {
|
|
118
|
-
e.rowKey !== void 0 && ((typeof e.rowKey != "string" || !e.rowKey.trim() || !t.has(e.rowKey)) && v("rowKey 应为引用已声明字段的非空字符串"), e.fields.find((n) => n.field === e.rowKey)?.type === "boolean" && v("布尔字段不能作为业务主键"));
|
|
119
|
-
}
|
|
120
|
-
function we(e) {
|
|
121
|
-
for (const t of ["label", "unit"]) e[t] !== void 0 && typeof e[t] != "string" && v(`${t} 应为字符串`);
|
|
122
|
-
for (const t of ["required", "nullable"]) e[t] !== void 0 && typeof e[t] != "boolean" && v(`${t} 应为布尔值`);
|
|
123
|
-
e.semanticRole !== void 0 && !["identifier", "dimension", "measure", "date", "text"].includes(e.semanticRole) && v("未知字段语义");
|
|
124
|
-
}
|
|
125
|
-
function be(e) {
|
|
126
|
-
for (const t of ["min", "max", "minLength", "maxLength"]) {
|
|
127
|
-
const n = e[t];
|
|
128
|
-
n !== void 0 && (!Number.isFinite(n) || t.includes("Length") && (!Number.isInteger(n) || n < 0)) && v(`${t} 无效`);
|
|
129
|
-
}
|
|
130
|
-
e.min !== void 0 && e.max !== void 0 && e.min > e.max && v("min 不能超过 max"), e.minLength !== void 0 && e.maxLength !== void 0 && e.minLength > e.maxLength && v("minLength 不能超过 maxLength"), e.type !== "number" && (e.min !== void 0 || e.max !== void 0) && v("min/max 仅适用于 number,精确小数文本需业务校验"), ["number", "boolean"].includes(e.type) && (e.minLength !== void 0 || e.maxLength !== void 0) && v("长度约束仅适用于文本类型");
|
|
131
|
-
}
|
|
132
|
-
function Me(e) {
|
|
133
|
-
const t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
|
|
134
|
-
if (!t) return !1;
|
|
135
|
-
const n = Number(t[1]), r = Number(t[2]), o = Number(t[3]), i = n % 4 === 0 && (n % 100 !== 0 || n % 400 === 0);
|
|
136
|
-
return n > 0 && r >= 1 && r <= 12 && o >= 1 && o <= [31, i ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][r - 1];
|
|
137
|
-
}
|
|
138
|
-
function U(e, t) {
|
|
139
|
-
return t === "number" ? typeof e == "number" && Number.isFinite(e) : t === "boolean" ? typeof e == "boolean" : typeof e != "string" ? !1 : t === "date" ? Me(e) : t === "decimal" ? e.length <= 1e4 && /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(e) : !0;
|
|
140
|
-
}
|
|
141
|
-
function Se(e, t) {
|
|
142
|
-
if (e == null)
|
|
143
|
-
return t.required || e === null && t.nullable === !1 ? { code: "required", message: "缺少必需字段值" } : void 0;
|
|
144
|
-
if (!U(e, t.type)) return { code: "type", message: `值应为 ${t.type},不会自动转换原始值` };
|
|
145
|
-
if (t.enum && !t.enum.includes(e)) return { code: "enum", message: "值不在允许的枚举中" };
|
|
146
|
-
if (typeof e == "number" && (t.min !== void 0 && e < t.min || t.max !== void 0 && e > t.max)) return { code: "range", message: "数值超出范围" };
|
|
147
|
-
if (typeof e == "string" && !ve(e, t)) return { code: "range", message: "文本长度超出范围" };
|
|
148
|
-
}
|
|
149
|
-
function ve(e, t) {
|
|
150
|
-
if (t.minLength === void 0 && t.maxLength === void 0) return !0;
|
|
151
|
-
let n = 0;
|
|
152
|
-
for (const r of e) n++;
|
|
153
|
-
return (t.minLength === void 0 || n >= t.minLength) && (t.maxLength === void 0 || n <= t.maxLength);
|
|
154
|
-
}
|
|
155
|
-
function E(e, t) {
|
|
156
|
-
const n = e ?? t;
|
|
157
|
-
if (!Number.isInteger(n) || n < 1) throw new Error("数据校验预算应为正整数");
|
|
158
|
-
return n;
|
|
159
|
-
}
|
|
160
|
-
function xe(e, t, n) {
|
|
161
|
-
const r = Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0;
|
|
162
|
-
if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r))) return "业务主键应为非空字符串或有限数字";
|
|
163
|
-
const o = JSON.stringify([typeof r, r]);
|
|
164
|
-
if (n.has(o)) return "业务主键重复";
|
|
165
|
-
n.add(o);
|
|
166
|
-
}
|
|
167
|
-
function $e(e, t, n = {}) {
|
|
168
|
-
J(t);
|
|
169
|
-
const r = n.path ?? "$.rows", o = [], i = E(n.maxIssues, 100);
|
|
170
|
-
if (!Array.isArray(e)) return { ok: !1, issues: [{ code: "row", path: r, message: "数据集应为对象数组" }] };
|
|
171
|
-
if (e.length > E(n.maxRows, 1e5) || e.length * t.fields.length > E(n.maxCells, 2e6)) return { ok: !1, issues: [{ code: "budget", path: r, message: "数据校验超出行数或单元格预算" }] };
|
|
172
|
-
const a = /* @__PURE__ */ new Set();
|
|
173
|
-
for (let s = 0; s < e.length && o.length < i; s++) {
|
|
174
|
-
const d = e[s];
|
|
175
|
-
if (!d || typeof d != "object" || Array.isArray(d)) {
|
|
176
|
-
o.push({ code: "row", path: `${r}[${s}]`, rowIndex: s, message: "行应为对象" });
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
Pe(d, t, s, r, a, o, i);
|
|
180
|
-
}
|
|
181
|
-
return { ok: o.length === 0, issues: o };
|
|
182
|
-
}
|
|
183
|
-
function Pe(e, t, n, r, o, i, a) {
|
|
184
|
-
for (const s of t.fields) {
|
|
185
|
-
if (i.length >= a) return;
|
|
186
|
-
const d = Se(Object.prototype.hasOwnProperty.call(e, s.field) ? e[s.field] : void 0, s);
|
|
187
|
-
d && i.push({ ...d, rowIndex: n, field: s.field, path: `${r}[${n}].${s.field}` });
|
|
188
|
-
}
|
|
189
|
-
if (t.rowKey && i.length < a) {
|
|
190
|
-
const s = xe(e, t.rowKey, o);
|
|
191
|
-
s && i.push({ code: "row-key", path: `${r}[${n}].${t.rowKey}`, message: s, rowIndex: n, field: t.rowKey });
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function ot(e) {
|
|
195
|
-
return J(e), { $schema: "https://json-schema.org/draft/2020-12/schema", type: "array", items: { type: "object", properties: Object.fromEntries(e.fields.map((n) => [n.field, ke(n, n.field === e.rowKey)])), required: e.fields.filter((n) => n.required || n.field === e.rowKey).map((n) => n.field), additionalProperties: !0 }, ...e.rowKey ? { "x-report-rowKey": e.rowKey } : {} };
|
|
196
|
-
}
|
|
197
|
-
function ke(e, t) {
|
|
198
|
-
const n = !t && e.nullable !== !1 && !e.required;
|
|
199
|
-
return {
|
|
200
|
-
type: n ? [j(e.type), "null"] : j(e.type),
|
|
201
|
-
...e.label ? { title: e.label } : {},
|
|
202
|
-
...e.type === "date" ? { format: "date" } : {},
|
|
203
|
-
...e.type === "decimal" ? { pattern: "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$" } : {},
|
|
204
|
-
...e.enum ? { enum: n ? [...e.enum, null] : [...e.enum] } : {},
|
|
205
|
-
...e.min === void 0 ? {} : { minimum: e.min },
|
|
206
|
-
...e.max === void 0 ? {} : { maximum: e.max },
|
|
207
|
-
...Re(e, t),
|
|
208
|
-
...t && e.type === "text" ? { pattern: "\\S" } : {},
|
|
209
|
-
...e.unit ? { "x-report-unit": e.unit } : {},
|
|
210
|
-
...e.semanticRole ? { "x-report-semanticRole": e.semanticRole } : {}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
function Re(e, t) {
|
|
214
|
-
const n = {};
|
|
215
|
-
return (e.minLength !== void 0 || t && e.type !== "number") && (n.minLength = Math.max(e.minLength ?? 0, t ? 1 : 0)), e.type === "decimal" ? n.maxLength = Math.min(e.maxLength ?? 1e4, 1e4) : e.maxLength !== void 0 && (n.maxLength = e.maxLength), n;
|
|
216
|
-
}
|
|
217
|
-
function j(e) {
|
|
218
|
-
return e === "text" || e === "date" || e === "decimal" ? "string" : e;
|
|
219
|
-
}
|
|
220
|
-
class N extends Error {
|
|
221
|
-
constructor(t, n) {
|
|
222
|
-
super(`报表页数超出上限 ${t}(至少 ${n} 页)`), this.limit = t, this.actual = n, this.code = "page-limit", this.name = "PaginatePageLimitError";
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function Te(e) {
|
|
226
|
-
return {
|
|
227
|
-
widthMm: e.widthMm,
|
|
228
|
-
heightMm: e.heightMm,
|
|
229
|
-
marginTopMm: e.marginTopMm ?? 0,
|
|
230
|
-
marginBottomMm: e.marginBottomMm ?? 0,
|
|
231
|
-
marginLeftMm: e.marginLeftMm ?? 0,
|
|
232
|
-
marginRightMm: e.marginRightMm ?? 0,
|
|
233
|
-
components: []
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
function Le(e, t) {
|
|
237
|
-
return t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
|
|
238
|
-
}
|
|
239
|
-
function Q(e) {
|
|
240
|
-
if (e == null) return "";
|
|
241
|
-
if (typeof e == "string") return e;
|
|
242
|
-
if (typeof e == "number") return String(e);
|
|
243
|
-
if (typeof e == "boolean") return e ? "是" : "否";
|
|
244
|
-
if (e instanceof Date) return e.toISOString().slice(0, 10);
|
|
245
|
-
try {
|
|
246
|
-
return JSON.stringify(e);
|
|
247
|
-
} catch {
|
|
248
|
-
return String(e);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function X(e, t) {
|
|
252
|
-
let n = e.textMetrics.get(t);
|
|
253
|
-
if (!n) {
|
|
254
|
-
const r = G(t).fontSizePt;
|
|
255
|
-
n = {
|
|
256
|
-
measureOptions: {
|
|
257
|
-
fontSizePt: r,
|
|
258
|
-
fontFamily: t.fontFamily ?? q,
|
|
259
|
-
italic: t.italic,
|
|
260
|
-
bold: t.bold,
|
|
261
|
-
letterSpacingPt: t.letterSpacing
|
|
262
|
-
},
|
|
263
|
-
lineMm: r * (t.lineHeight ?? z) * 25.4 / 72
|
|
264
|
-
}, e.textMetrics.set(t, n);
|
|
265
|
-
}
|
|
266
|
-
return n;
|
|
267
|
-
}
|
|
268
|
-
function Z(e, t, n) {
|
|
269
|
-
return n === "identifier" || n === "dimension" || n === "date" ? "center" : n === "measure" ? "right" : n === "text" ? "left" : 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";
|
|
270
|
-
}
|
|
271
|
-
function Ne(e) {
|
|
272
|
-
if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
|
|
273
|
-
}
|
|
274
|
-
function Fe(e, t) {
|
|
275
|
-
const n = e.fontSizePt ?? re, r = e.paddingMm ?? 1, o = e.columns.map((m) => m.align ?? m.style?.align ?? e.align ?? "left"), i = e.columns.map((m, u) => ({
|
|
276
|
-
...$({
|
|
277
|
-
fontSize: n,
|
|
278
|
-
verticalAlign: "middle"
|
|
279
|
-
}, m.style),
|
|
280
|
-
align: o[u] === "auto" ? "left" : o[u]
|
|
281
|
-
})), a = i.map((m, u) => o[u] === "auto" ? { left: m, center: { ...m, align: "center" }, right: { ...m, align: "right" } } : void 0), s = e.columns.map((m, u) => m.rules?.map((b) => {
|
|
282
|
-
const x = a[u];
|
|
283
|
-
if (x) return {
|
|
284
|
-
left: $(x.left, b.style),
|
|
285
|
-
center: $(x.center, b.style),
|
|
286
|
-
right: $(x.right, b.style)
|
|
287
|
-
};
|
|
288
|
-
const k = $(i[u], b.style);
|
|
289
|
-
return { left: k, center: k, right: k };
|
|
290
|
-
})), d = e.columns.map((m) => {
|
|
291
|
-
let u = $({
|
|
292
|
-
fontSize: n,
|
|
293
|
-
bold: e.headerBold ?? !0,
|
|
294
|
-
align: "center",
|
|
295
|
-
verticalAlign: "middle",
|
|
296
|
-
backgroundColor: e.headerBackgroundColor
|
|
297
|
-
}, m.style);
|
|
298
|
-
return e.headerAlign !== void 0 && (u.align = e.headerAlign), u = $(u, e.headerStyle), m.headerAlign !== void 0 && (u.align = m.headerAlign), $(u, m.headerStyle);
|
|
299
|
-
}), g = e.columns.map((m) => m.header);
|
|
300
|
-
let c = e.rowHeightMm ?? 0;
|
|
301
|
-
for (let m = 0; m < g.length; m++) {
|
|
302
|
-
const u = d[m], b = G(u).fontSizePt, x = K(
|
|
303
|
-
g[m],
|
|
304
|
-
e.columns[m].widthMm - r * 2,
|
|
305
|
-
{ fontSizePt: b, fontFamily: u.fontFamily ?? q, italic: u.italic, bold: u.bold, letterSpacingPt: u.letterSpacing },
|
|
306
|
-
t
|
|
307
|
-
), k = b * (u.lineHeight ?? z) * 25.4 / 72;
|
|
308
|
-
c = Math.max(c, Math.max(x.length, 1) * k + r * 2);
|
|
309
|
-
}
|
|
310
|
-
const f = g.map((m, u) => ({
|
|
311
|
-
text: m,
|
|
312
|
-
style: d[u]
|
|
313
|
-
})), w = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, p = e.columns.map((m) => m.widthMm), h = Ee(e.headerGrid, p, {
|
|
314
|
-
cells: [f],
|
|
315
|
-
colWidthsMm: p,
|
|
316
|
-
rowHeightsMm: [c],
|
|
317
|
-
paddingMm: r
|
|
318
|
-
});
|
|
319
|
-
return {
|
|
320
|
-
fontSizePt: n,
|
|
321
|
-
paddingMm: r,
|
|
322
|
-
cellStyles: i,
|
|
323
|
-
autoStyles: a,
|
|
324
|
-
ruleStyles: s,
|
|
325
|
-
textMetrics: /* @__PURE__ */ new WeakMap(),
|
|
326
|
-
numberFormats: e.columns.map((m) => Y(m.format)),
|
|
327
|
-
borderStyle: w,
|
|
328
|
-
headerHeightMm: h.rowHeightsMm.reduce((m, u) => m + u, 0),
|
|
329
|
-
headerGrid: h,
|
|
330
|
-
colWidthsMm: p,
|
|
331
|
-
columns: e.columns
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function Ee(e, t, n) {
|
|
335
|
-
if (!e) return n;
|
|
336
|
-
if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
|
|
337
|
-
const r = e.rowHeightsMm ?? e.cells.map(() => n.rowHeightsMm[0]);
|
|
338
|
-
if (r.length !== e.cells.length || r.some((o) => !Number.isFinite(o) || o <= 0)) throw new Error("自定义列表表头行高无效");
|
|
339
|
-
return { ...e, colWidthsMm: t, rowHeightsMm: r };
|
|
340
|
-
}
|
|
341
|
-
function Ae(e, t, n) {
|
|
342
|
-
const r = t.format?.kind === "number" || t.format?.kind === "percent";
|
|
343
|
-
t.valueType !== void 0 ? e.valueType = t.valueType : r && (e.valueType = "number"), t.editable !== void 0 && (e.editable = t.editable), (typeof e.value == "number" || e.value == null) && n !== void 0 && (e.numberFormat = n);
|
|
344
|
-
}
|
|
345
|
-
function C(e, t, n) {
|
|
346
|
-
const r = e.columns;
|
|
347
|
-
let o = e.rowHeightFloorMm;
|
|
348
|
-
const i = new Array(r.length);
|
|
349
|
-
for (let a = 0; a < r.length; a++) {
|
|
350
|
-
const s = r[a], d = t[s.field], g = e.autoStyles[a] ? Z(d, s.format, s.semanticRole) : "left";
|
|
351
|
-
let c = e.autoStyles[a]?.[g] ?? e.cellStyles[a];
|
|
352
|
-
if (s.rules)
|
|
353
|
-
for (let u = 0; u < s.rules.length; u++) {
|
|
354
|
-
const b = s.rules[u];
|
|
355
|
-
if (fe(t, b.when)) {
|
|
356
|
-
c = e.ruleStyles[a][u][g];
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const f = s.format ? V(d, s.format) : Q(d), w = X(e, c), p = K(f, s.widthMm - e.paddingMm * 2, w.measureOptions, n);
|
|
361
|
-
o = Math.max(o, p.length * w.lineMm + e.paddingMm * 2);
|
|
362
|
-
const h = Ne(d), m = { text: f, style: c };
|
|
363
|
-
h !== void 0 && (m.value = h), Ae(m, s, e.numberFormats[a]), i[a] = m;
|
|
364
|
-
}
|
|
365
|
-
return {
|
|
366
|
-
grid: { cells: [i], colWidthsMm: e.colWidthsMm, rowHeightsMm: [o], paddingMm: e.paddingMm },
|
|
367
|
-
heightMm: o
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function* He(e, t) {
|
|
371
|
-
if (!t) {
|
|
372
|
-
for (const r of e) yield { kind: "row", row: r };
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const n = /* @__PURE__ */ new Map();
|
|
376
|
-
for (const r of e) {
|
|
377
|
-
const o = Q(r[t.field]), i = n.get(o);
|
|
378
|
-
i ? i.push(r) : n.set(o, [r]);
|
|
379
|
-
}
|
|
380
|
-
for (const [r, o] of n) {
|
|
381
|
-
yield { kind: "groupHeader", label: (t.headerTemplate ?? "{value}").replace(/\{value\}/g, r), firstRow: o[0] };
|
|
382
|
-
for (const i of o) yield { kind: "row", row: i };
|
|
383
|
-
t.subtotal?.length && (yield { kind: "subtotal", label: t.subtotalLabel ?? "小计", rows: o });
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
function De(e, t) {
|
|
387
|
-
let n = 0;
|
|
388
|
-
for (const r of e) {
|
|
389
|
-
const o = typeof r[t] == "number" ? r[t] : Number(r[t]);
|
|
390
|
-
Number.isFinite(o) && (n += o);
|
|
391
|
-
}
|
|
392
|
-
return n;
|
|
393
|
-
}
|
|
394
|
-
function ee(e, t, n) {
|
|
395
|
-
return new Map(n.map((r) => {
|
|
396
|
-
const o = e.find((a) => a.field === r)?.format ?? { kind: "number", thousands: !0 }, i = De(t, r);
|
|
397
|
-
return [r, { text: V(i, o), value: i, numberFormat: Y(o) }];
|
|
398
|
-
}));
|
|
399
|
-
}
|
|
400
|
-
function te(e, t) {
|
|
401
|
-
const n = e.findIndex((r) => t.includes(r.field));
|
|
402
|
-
return n > 0 ? n : 1;
|
|
403
|
-
}
|
|
404
|
-
function D(e, t, n, r, o, i) {
|
|
405
|
-
const a = [], s = Math.max(1, Math.min(i, e.columns.length)), d = $({ fontSize: e.fontSizePt }, o);
|
|
406
|
-
a.push({ text: n, colSpan: s, style: { bold: !0, ...d } });
|
|
407
|
-
for (let f = s; f < e.columns.length; f++) {
|
|
408
|
-
const w = e.columns[f], p = r.get(w.field), h = e.autoStyles[f]?.[Z(p?.value, w.format)] ?? e.cellStyles[f];
|
|
409
|
-
a.push({ ...p, text: p?.text ?? "", style: $(h, o) });
|
|
410
|
-
}
|
|
411
|
-
let g = e.rowHeightFloorMm, c = 0;
|
|
412
|
-
for (const f of a) {
|
|
413
|
-
let w = 0;
|
|
414
|
-
const p = c + (f.colSpan ?? 1);
|
|
415
|
-
for (; c < p; c++) w += e.colWidthsMm[c] ?? 0;
|
|
416
|
-
const h = X(e, f.style), m = K(f.text ?? "", w - e.paddingMm * 2, h.measureOptions, t);
|
|
417
|
-
g = Math.max(g, m.length * h.lineMm + e.paddingMm * 2);
|
|
418
|
-
}
|
|
419
|
-
return {
|
|
420
|
-
grid: { cells: [a], colWidthsMm: e.colWidthsMm, rowHeightsMm: [g], paddingMm: e.paddingMm },
|
|
421
|
-
heightMm: g
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
function Ie(e, t, n) {
|
|
425
|
-
const { templatePage: r, current: o, warnings: i, nextId: a, pushCurrent: s } = n, d = () => Le(r, o), g = o.marginTopMm, c = {
|
|
426
|
-
id: n.tableId,
|
|
427
|
-
columnKeys: e.columns.map((l) => l.field),
|
|
428
|
-
...e.layout === void 0 ? {} : { layout: e.layout },
|
|
429
|
-
...e.title === void 0 ? {} : { title: e.title }
|
|
430
|
-
};
|
|
431
|
-
let f = 0;
|
|
432
|
-
const w = {
|
|
433
|
-
kind: "rect",
|
|
434
|
-
leftMm: e.leftMm,
|
|
435
|
-
topMm: 0,
|
|
436
|
-
widthMm: e.widthMm,
|
|
437
|
-
heightMm: t.headerHeightMm,
|
|
438
|
-
grid: t.headerGrid,
|
|
439
|
-
nid: a("listh"),
|
|
440
|
-
table: { ...c, role: "header", rowIndex: -1 },
|
|
441
|
-
style: t.borderStyle
|
|
442
|
-
}, p = (l) => o.components.push({ ...w, topMm: l });
|
|
443
|
-
let h = e.topMm;
|
|
444
|
-
p(h), h += t.headerHeightMm + n.mmPerRow;
|
|
445
|
-
function m() {
|
|
446
|
-
const l = r.layout === "wide" ? 0 : e.topMm;
|
|
447
|
-
return e.headerEveryPage !== !1 ? l + t.headerHeightMm : r.layout === "wide" ? 0 : g;
|
|
448
|
-
}
|
|
449
|
-
function u() {
|
|
450
|
-
const l = r.layout === "wide" ? 0 : o.marginBottomMm;
|
|
451
|
-
return r.heightMm - l - m();
|
|
452
|
-
}
|
|
453
|
-
function b(l) {
|
|
454
|
-
if (h + l <= d()) return;
|
|
455
|
-
s(), o.components = [], o.heightMm = r.heightMm, r.layout === "wide" && (o.marginTopMm = 0, o.marginBottomMm = 0);
|
|
456
|
-
const M = r.layout === "wide" ? 0 : e.topMm;
|
|
457
|
-
e.headerEveryPage !== !1 ? (p(M), h = M + t.headerHeightMm) : h = r.layout === "wide" ? 0 : g;
|
|
458
|
-
}
|
|
459
|
-
function x(l, M, S, R) {
|
|
460
|
-
const T = u();
|
|
461
|
-
l.heightMm > T && i.push(`列表 ${e.id ?? e.dataset} 行高 ${l.heightMm.toFixed(2)}mm 超出单页可用高度 ${T.toFixed(2)}mm,预览与打印可能截断内容`), b(l.heightMm), o.components.push({
|
|
462
|
-
kind: "rect",
|
|
463
|
-
leftMm: e.leftMm,
|
|
464
|
-
topMm: h,
|
|
465
|
-
widthMm: e.widthMm,
|
|
466
|
-
heightMm: l.heightMm,
|
|
467
|
-
grid: l.grid,
|
|
468
|
-
nid: a(M),
|
|
469
|
-
table: { ...c, role: S, rowIndex: f++, ...R ? { source: R } : {} },
|
|
470
|
-
style: t.borderStyle
|
|
471
|
-
}), h += l.heightMm;
|
|
472
|
-
}
|
|
473
|
-
function k(l) {
|
|
474
|
-
l <= u() && b(l);
|
|
475
|
-
}
|
|
476
|
-
return { keepTogether: k, placeGridRow: x };
|
|
477
|
-
}
|
|
478
|
-
function Ke(e, t) {
|
|
479
|
-
if (!e.rowKey) return;
|
|
480
|
-
const n = t[e.rowKey];
|
|
481
|
-
if ((typeof n != "string" || !n.trim()) && !(typeof n == "number" && Number.isFinite(n)))
|
|
482
|
-
throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);
|
|
483
|
-
const r = e.revisionField ? t[e.revisionField] : void 0, o = e.sourceTokenField ? t[e.sourceTokenField] : void 0;
|
|
484
|
-
if (r !== void 0 && typeof r != "string" && !(typeof r == "number" && Number.isFinite(r))) throw new Error("业务修订号应为字符串或有限数字");
|
|
485
|
-
if (o !== void 0 && typeof o != "string") throw new Error("来源令牌应为字符串");
|
|
486
|
-
return { datasetId: e.dataset, rowKey: n, ...r === void 0 ? {} : { revision: r }, ...o === void 0 ? {} : { sourceToken: o } };
|
|
487
|
-
}
|
|
488
|
-
function Oe(e, t) {
|
|
489
|
-
const n = /* @__PURE__ */ new Map();
|
|
490
|
-
if (!e.rowKey) return n;
|
|
491
|
-
const r = /* @__PURE__ */ new Set();
|
|
492
|
-
for (const o of t) {
|
|
493
|
-
const i = Ke(e, o), a = JSON.stringify(i.rowKey);
|
|
494
|
-
if (r.has(a)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(i.rowKey)}`);
|
|
495
|
-
r.add(a), n.set(o, i);
|
|
496
|
-
}
|
|
497
|
-
return n;
|
|
498
|
-
}
|
|
499
|
-
function Be(e, t, n, r, o) {
|
|
500
|
-
if (!e.grandTotal) return;
|
|
501
|
-
const i = typeof e.grandTotal == "object" ? e.grandTotal : void 0, a = i?.fields ?? e.groupBy?.subtotal ?? [];
|
|
502
|
-
if (a.length === 0) {
|
|
503
|
-
r.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
const s = D(n, r.measurer, i?.label ?? "合计", ee(e.columns, t, a), i?.style ?? {}, te(e.columns, a));
|
|
507
|
-
o.placeGridRow(s, "listgt", "grand-total");
|
|
508
|
-
}
|
|
509
|
-
function je(e, t, n) {
|
|
510
|
-
const r = Oe(e, t), o = e.columns.reduce((c, f) => c + f.widthMm, 0), i = o > e.widthMm ? e.widthMm / o : 1, a = i === 1 ? e : { ...e, columns: e.columns.map((c) => ({ ...c, widthMm: c.widthMm * i })) }, s = { ...Fe(a, n.measurer), rowHeightFloorMm: a.rowHeightMm ?? 0 }, d = Ie(a, s, n);
|
|
511
|
-
let g;
|
|
512
|
-
for (const c of He(t, a.groupBy))
|
|
513
|
-
if (c.kind === "row")
|
|
514
|
-
d.placeGridRow(g ?? C(s, c.row, n.measurer), "listr", "body", r.get(c.row)), g = void 0;
|
|
515
|
-
else if (c.kind === "groupHeader") {
|
|
516
|
-
const f = D(s, n.measurer, c.label, /* @__PURE__ */ new Map(), a.groupBy?.headerStyle ?? {}, a.columns.length);
|
|
517
|
-
g = C(s, c.firstRow, n.measurer), a.groupBy?.keepWithNext !== !1 && d.keepTogether(f.heightMm + g.heightMm), d.placeGridRow(f, "listg", "group-header");
|
|
518
|
-
} else {
|
|
519
|
-
const f = a.groupBy?.subtotal ?? [], w = D(s, n.measurer, c.label, ee(a.columns, c.rows, f), a.groupBy?.subtotalStyle ?? {}, te(a.columns, f));
|
|
520
|
-
d.placeGridRow(w, "listst", "subtotal");
|
|
521
|
-
}
|
|
522
|
-
Be(a, t, s, n, d);
|
|
523
|
-
}
|
|
524
|
-
function W(e) {
|
|
525
|
-
return e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}"));
|
|
526
|
-
}
|
|
527
|
-
function Ce(e, t, n, r, o, i) {
|
|
528
|
-
const a = {
|
|
529
|
-
pageWidthMm: t.widthMm,
|
|
530
|
-
pageHeightMm: t.heightMm,
|
|
531
|
-
...e.layout === void 0 ? {} : { layout: e.layout },
|
|
532
|
-
marginTopMm: t.marginTopMm,
|
|
533
|
-
marginBottomMm: t.marginBottomMm,
|
|
534
|
-
marginLeftMm: t.marginLeftMm,
|
|
535
|
-
marginRightMm: t.marginRightMm,
|
|
536
|
-
components: t.components
|
|
537
|
-
};
|
|
538
|
-
r.push(a);
|
|
539
|
-
for (const s of n) {
|
|
540
|
-
const d = { ...s, text: String(s.text ?? "").replace(/\{page\}/g, String(r.length)) };
|
|
541
|
-
a.components.push(d), d.text.includes("{totalPages}") && o.push(d);
|
|
542
|
-
}
|
|
543
|
-
if (e.layout === "wide") {
|
|
544
|
-
const s = a.components.reduce((d, g) => Math.max(d, g.topMm + g.heightMm), 0);
|
|
545
|
-
a.marginBottomMm = i ? e.marginBottomMm ?? 0 : 0, a.pageHeightMm = Math.max(1, s + a.marginBottomMm);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
function We(e, t, n = {}) {
|
|
549
|
-
const r = typeof n == "number" ? { mmPerRow: n } : n;
|
|
550
|
-
if (r.maxPages !== void 0 && (!Number.isSafeInteger(r.maxPages) || r.maxPages < 1)) throw new RangeError("maxPages 应为正安全整数");
|
|
551
|
-
const o = [], i = [], a = [];
|
|
552
|
-
let s = 0;
|
|
553
|
-
const d = (g) => `${g}_${(++s).toString(36)}`;
|
|
554
|
-
for (const [g, c] of e.pages.entries()) {
|
|
555
|
-
const f = Te(c), w = c.components.filter(W), p = (h = !1) => {
|
|
556
|
-
if (r.maxPages !== void 0 && i.length >= r.maxPages) throw new N(r.maxPages, i.length + 1);
|
|
557
|
-
Ce(c, f, w, i, a, h);
|
|
558
|
-
};
|
|
559
|
-
for (const [h, m] of c.components.entries()) {
|
|
560
|
-
if (W(m)) continue;
|
|
561
|
-
if (m.kind !== "list") {
|
|
562
|
-
f.components.push(m);
|
|
563
|
-
continue;
|
|
564
|
-
}
|
|
565
|
-
const u = t[m.dataset];
|
|
566
|
-
Array.isArray(u) || o.push(`数据集 ${m.dataset} 未提供数据,列表 ${m.id ?? ""} 输出为空`), je(m, Array.isArray(u) ? u : [], {
|
|
567
|
-
templatePage: c,
|
|
568
|
-
current: f,
|
|
569
|
-
warnings: o,
|
|
570
|
-
nextId: d,
|
|
571
|
-
pushCurrent: p,
|
|
572
|
-
measurer: r.measurer ?? oe,
|
|
573
|
-
mmPerRow: r.mmPerRow ?? 0,
|
|
574
|
-
tableId: `table:${g}:${h}`
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
p(!0);
|
|
578
|
-
}
|
|
579
|
-
for (const g of a) g.text = g.text.replace(/\{totalPages\}/g, String(i.length));
|
|
580
|
-
return { plan: { schemaVersion: _, pages: i }, warnings: o };
|
|
581
|
-
}
|
|
582
|
-
function at(e) {
|
|
583
|
-
if (!("mapData" in e)) return e;
|
|
584
|
-
const { load: t, mapData: n, ...r } = e;
|
|
585
|
-
return { ...r, load: async (o) => {
|
|
586
|
-
const i = await t(o);
|
|
587
|
-
P(o.signal);
|
|
588
|
-
try {
|
|
589
|
-
return n(i, o);
|
|
590
|
-
} catch (a) {
|
|
591
|
-
throw new y("validate", `报表 ${o.reportId} 数据映射失败`, a);
|
|
592
|
-
}
|
|
593
|
-
} };
|
|
594
|
-
}
|
|
595
|
-
class y extends Error {
|
|
596
|
-
constructor(t, n, r) {
|
|
597
|
-
super(n), this.name = "ReportSourceError", this.code = t, this.cause = r;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
function F(e) {
|
|
601
|
-
const t = new Error("报表加载已取消");
|
|
602
|
-
return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
|
|
603
|
-
}
|
|
604
|
-
function P(e) {
|
|
605
|
-
if (e?.aborted) throw F(e);
|
|
606
|
-
}
|
|
607
|
-
function I(e, t) {
|
|
608
|
-
return t ? new Promise((n, r) => {
|
|
609
|
-
const o = () => t.removeEventListener("abort", i), i = () => {
|
|
610
|
-
o(), r(F(t));
|
|
611
|
-
};
|
|
612
|
-
t.addEventListener("abort", i, { once: !0 }), t.aborted && i(), Promise.resolve(e).then(
|
|
613
|
-
(a) => {
|
|
614
|
-
o(), n(a);
|
|
615
|
-
},
|
|
616
|
-
(a) => {
|
|
617
|
-
o(), r(a);
|
|
618
|
-
}
|
|
619
|
-
);
|
|
620
|
-
}) : Promise.resolve(e);
|
|
621
|
-
}
|
|
622
|
-
function _e(e, t) {
|
|
623
|
-
if (!e || typeof e != "object" || Array.isArray(e))
|
|
624
|
-
throw new y("validate", `报表 ${t} 的数据集应为对象`);
|
|
625
|
-
for (const [n, r] of Object.entries(e))
|
|
626
|
-
if (!Array.isArray(r) || r.some((o) => !o || typeof o != "object" || Array.isArray(o)))
|
|
627
|
-
throw new y("validate", `报表 ${t} 的数据集 ${n} 应为对象数组`);
|
|
628
|
-
}
|
|
629
|
-
async function qe(e, t, n) {
|
|
630
|
-
const { reportId: r, signal: o } = t;
|
|
631
|
-
try {
|
|
632
|
-
const i = await I(e(t), o);
|
|
633
|
-
P(o);
|
|
634
|
-
const a = se(i);
|
|
635
|
-
if (!a.ok)
|
|
636
|
-
throw new y("validate", `报表 ${r} 模板校验失败:${a.errors.slice(0, 3).map((s) => `${s.path}: ${s.message}`).join("; ")}`);
|
|
637
|
-
return n.push(...a.warnings.map((s) => `${r}: ${s.path}: ${s.message}`)), i;
|
|
638
|
-
} catch (i) {
|
|
639
|
-
throw o?.aborted ? F(o) : i instanceof y ? i : i instanceof me ? new y("validate", `报表 ${r} 模板校验失败:${i.message}`, i) : new y("fetch", `报表 ${r} 模板加载失败:${i instanceof Error ? i.message : String(i)}`, i);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
async function ze(e, t, n, r) {
|
|
643
|
-
const o = t.signal;
|
|
644
|
-
let i;
|
|
645
|
-
try {
|
|
646
|
-
if (e.load) i = await I(e.load(t), o);
|
|
647
|
-
else if (e.provider) {
|
|
648
|
-
const a = await I(e.provider.query(t), o);
|
|
649
|
-
P(o), Ge(a, n), i = a.datasets, r?.(n, a);
|
|
650
|
-
} else i = e.datasets ?? {};
|
|
651
|
-
} catch (a) {
|
|
652
|
-
throw o?.aborted ? F(o) : a instanceof y ? a : new y("fetch", `报表 ${n} 取数失败:${a instanceof Error ? a.message : String(a)}`, a);
|
|
653
|
-
}
|
|
654
|
-
return P(o), i;
|
|
655
|
-
}
|
|
656
|
-
function Ge(e, t) {
|
|
657
|
-
if (!e || typeof e != "object" || Array.isArray(e)) throw new y("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
|
|
658
|
-
for (const n of ["revision", "sourceToken"])
|
|
659
|
-
if (e[n] !== void 0 && typeof e[n] != "string") throw new y("validate", `报表 ${t} Provider ${n} 应为字符串`);
|
|
660
|
-
if (e.diagnostics !== void 0 && (!Array.isArray(e.diagnostics) || e.diagnostics.some((n) => !n || typeof n.code != "string" || typeof n.message != "string" || !["info", "warning", "error"].includes(n.severity))))
|
|
661
|
-
throw new y("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
|
|
662
|
-
}
|
|
663
|
-
function Ye(e, t, n) {
|
|
664
|
-
for (const [r, o] of Object.entries(e.dataSchema ?? {})) {
|
|
665
|
-
let i;
|
|
666
|
-
try {
|
|
667
|
-
i = $e(Object.prototype.hasOwnProperty.call(t, r) ? t[r] : void 0, o, { ...e.dataValidation, path: `$.datasets.${r}` });
|
|
668
|
-
} catch (a) {
|
|
669
|
-
throw new y("config", `报表 ${n} 数据集 ${r} 字段契约配置无效`, a);
|
|
670
|
-
}
|
|
671
|
-
if (!i.ok) throw new y("validate", `报表 ${n} 数据集 ${r} 不符合字段契约:${i.issues[0]?.message}`, { issues: i.issues });
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
function Ve(e, t, n, r, o) {
|
|
675
|
-
const i = o ? o.maxPages - o.usedPages : void 0;
|
|
676
|
-
try {
|
|
677
|
-
if (i !== void 0 && i < 1 && e.pages.length) throw new N(0, 1);
|
|
678
|
-
const a = i === void 0 ? n.pagination : {
|
|
679
|
-
...n.pagination,
|
|
680
|
-
maxPages: Math.max(1, Math.min(i, n.pagination?.maxPages ?? i))
|
|
681
|
-
};
|
|
682
|
-
return We(e, t, a);
|
|
683
|
-
} catch (a) {
|
|
684
|
-
const s = a instanceof N && o && a.limit === i ? new N(o.maxPages, o.usedPages + a.actual) : a;
|
|
685
|
-
throw new y("validate", `报表 ${r} 排版失败:${s instanceof Error ? s.message : String(s)}`, s);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
function Je(e, t, n, r) {
|
|
689
|
-
const o = /* @__PURE__ */ new Map(), i = (a) => {
|
|
690
|
-
let s = o.get(a);
|
|
691
|
-
return s === void 0 && (s = JSON.stringify([n, r, a]), o.set(a, s)), s;
|
|
692
|
-
};
|
|
693
|
-
for (const a of t.pages) e.push({
|
|
694
|
-
...a,
|
|
695
|
-
components: a.components.map((s) => s.table ? {
|
|
696
|
-
...s,
|
|
697
|
-
table: { ...s.table, id: i(s.table.id) }
|
|
698
|
-
} : s)
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
function it(e, t = {}) {
|
|
702
|
-
if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new y("config", "maxPages 应为正安全整数");
|
|
703
|
-
function n(o) {
|
|
704
|
-
const i = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
|
|
705
|
-
if (!i) throw new y("config", `未注册报表 ${o}`);
|
|
706
|
-
return i;
|
|
707
|
-
}
|
|
708
|
-
return Object.assign(async ({ reportIds: o, params: i, signal: a, onWarning: s, onQueryResult: d, ...g }) => {
|
|
709
|
-
P(a);
|
|
710
|
-
const c = ce({ ...g, signal: a }), f = [...o], w = { ...i };
|
|
711
|
-
if (f.length === 0) throw new y("config", "缺少报表 ID");
|
|
712
|
-
const p = f.map(n), h = c.runSync("validate", () => p.map((l) => B(
|
|
713
|
-
l.params ?? (typeof l.template == "function" ? [] : l.template.params) ?? [],
|
|
714
|
-
w
|
|
715
|
-
))), m = [], u = [];
|
|
716
|
-
for (const [l, M] of p.entries()) {
|
|
717
|
-
P(a);
|
|
718
|
-
const S = f[l], R = { reportId: S, params: h[l], signal: a }, T = typeof M.template == "function" ? await c.run("query", () => qe(M.template, R, u), S) : M.template;
|
|
719
|
-
R.params = c.runSync("validate", () => B(M.params ?? T.params ?? [], R.params), S);
|
|
720
|
-
const L = await c.run("query", () => ze(M, R, S, d), S);
|
|
721
|
-
c.runSync("validate", () => {
|
|
722
|
-
_e(L, S), t.onDatasets?.(S, L, T), Ye(M, L, S);
|
|
723
|
-
}, S), P(a);
|
|
724
|
-
const O = c.runSync("layout", () => Ve(T, L, M, S, t.maxPages === void 0 ? void 0 : { maxPages: t.maxPages, usedPages: m.length }), S);
|
|
725
|
-
Je(m, O.plan, l, S), u.push(...O.warnings.map((ne) => `${S}: ${ne}`));
|
|
726
|
-
}
|
|
727
|
-
P(a);
|
|
728
|
-
const b = { schemaVersion: _, pages: m }, x = c.runSync("validate", () => {
|
|
729
|
-
const l = ae(b);
|
|
730
|
-
if (!l.ok) throw new y("validate", `渲染计划校验失败:${l.errors.slice(0, 3).map((M) => `${M.path}: ${M.message}`).join("; ")}`);
|
|
731
|
-
return l;
|
|
732
|
-
});
|
|
733
|
-
u.push(...x.warnings.map((l) => `${l.path}: ${l.message}`));
|
|
734
|
-
const k = s ?? t.onWarning ?? ((l) => console.warn("[mach-report]", l));
|
|
735
|
-
for (const l of u)
|
|
736
|
-
P(a), k(l);
|
|
737
|
-
return P(a), b;
|
|
738
|
-
}, {
|
|
739
|
-
getParamDefs: (o) => ie(e, o)
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
export {
|
|
743
|
-
N as P,
|
|
744
|
-
y as R,
|
|
745
|
-
at as a,
|
|
746
|
-
ue as b,
|
|
747
|
-
it as c,
|
|
748
|
-
ot as d,
|
|
749
|
-
fe as e,
|
|
750
|
-
V as f,
|
|
751
|
-
H as g,
|
|
752
|
-
We as p,
|
|
753
|
-
Y as t,
|
|
754
|
-
$e as v
|
|
755
|
-
};
|