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