@agile-team/mach-report 2.10.0 → 2.11.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 +6 -2
- package/dist/ExcelBindingWizard-CjIiVox-.cjs +1 -0
- package/dist/ExcelBindingWizard-Dxm-K5HL.js +1240 -0
- package/dist/ParamEditor-D-Hf5xfO.cjs +1 -0
- package/dist/ParamEditor-DRGxzxeO.js +381 -0
- package/dist/ReportBatchPanel-BYgg0EDB.cjs +1 -0
- package/dist/ReportBatchPanel-Bby5yLzU.js +287 -0
- package/dist/ReportPreview-DWXROHBP.cjs +6 -0
- package/dist/ReportPreview-DiNXhQI0.js +4138 -0
- package/dist/ReportTemplateLibrary-C6CO7YCT.cjs +1 -0
- package/dist/ReportTemplateLibrary-DfzDXRvr.js +260 -0
- package/dist/RuleEditor-C2QsOHOs.cjs +1 -0
- package/dist/RuleEditor-D9wQHrkf.js +2024 -0
- package/dist/TemplateReviewPanel-BKofGrV9.js +222 -0
- package/dist/TemplateReviewPanel-DwtOcLue.cjs +1 -0
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +2 -0
- package/dist/analytics.d.ts +2 -0
- package/dist/analytics.js +29 -29
- package/dist/batch-Bt3Fd27Z.cjs +1 -0
- package/dist/batch-mRqhhhjt.js +364 -0
- package/dist/computed-Bvk0W15F.js +521 -0
- package/dist/computed-CGV2a809.cjs +1 -0
- package/dist/config-B612mw0x.js +525 -0
- package/dist/config-BRoLo2oj.cjs +1 -0
- package/dist/designer.cjs +2 -2
- package/dist/designer.d.cts +659 -9
- package/dist/designer.d.ts +659 -9
- package/dist/designer.js +2030 -1824
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +147 -3
- package/dist/index.d.ts +147 -3
- package/dist/index.js +639 -592
- package/dist/injection-keys-Db_DyLkm.cjs +1 -0
- package/dist/injection-keys-e85udZCp.js +7 -0
- package/dist/list-cell-BuYn4tGF.cjs +1 -0
- package/dist/{list-cell-Dxyi7DOw.js → list-cell-ClFra1zS.js} +54 -40
- package/dist/matrix-DVyWiYsd.cjs +1 -0
- package/dist/matrix-yZsGnldA.js +227 -0
- package/dist/param-validation-BlHHXs6u.js +153 -0
- package/dist/param-validation-DCK039V1.cjs +1 -0
- package/dist/pdf.cjs +25 -25
- package/dist/pdf.d.cts +3 -0
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +677 -677
- package/dist/plugin-BDTU4D94.cjs +1 -0
- package/dist/plugin-Cd5G2QQn.js +22 -0
- package/dist/region-binding-workflow-CXDmt9Bs.js +977 -0
- package/dist/region-binding-workflow-DhQvu1co.cjs +3 -0
- package/dist/{report-params-B_VCihAh.js → report-params-B44imUd4.js} +1 -1
- package/dist/{report-params-CjWrjPl6.cjs → report-params-SJfhKgaX.cjs} +1 -1
- package/dist/server/node.d.cts +5 -2
- package/dist/server/node.d.ts +5 -2
- package/dist/server-node.cjs +1 -1
- package/dist/server-node.js +87 -87
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +201 -2
- package/dist/server.d.ts +201 -2
- package/dist/server.js +557 -658
- package/dist/style.css +1 -1
- package/dist/template-registry-WNXdkiET.js +506 -0
- package/dist/template-registry-ukBGlm8N.cjs +1 -0
- package/dist/template-review-BXp2oyqg.cjs +1 -0
- package/dist/template-review-BdcXSYbx.js +1616 -0
- package/dist/tree-BX380Rr7.cjs +1 -0
- package/dist/tree-CqcQ99NM.js +172 -0
- package/dist/{validate-UUy9yP4K.js → validate-7s0yn6ii.js} +44 -44
- package/dist/validate-DsRiNw8h.cjs +1 -0
- package/dist/vue/async.d.cts +93 -4
- package/dist/vue/async.d.ts +93 -4
- package/dist/vue/index.d.cts +145 -7
- package/dist/vue/index.d.ts +145 -7
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +5 -5
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +116 -113
- package/dist/{workbook-session-B-bW5_yR.js → workbook-session-BKOTwcoq.js} +1 -1
- package/dist/{workbook-session-D7RtdNo0.cjs → workbook-session-CLYLhZWu.cjs} +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +5 -2
- package/dist/worker.d.ts +5 -2
- package/dist/worker.js +1 -1
- package/dist/xlsx.cjs +3 -3
- package/dist/xlsx.d.cts +129 -2
- package/dist/xlsx.d.ts +129 -2
- package/dist/xlsx.js +336 -242
- package/package.json +1 -1
- package/dist/ExcelBindingWizard-CF7RplWm.cjs +0 -1
- package/dist/ExcelBindingWizard-qhwEderR.js +0 -842
- package/dist/ReportPreview-BE1tCHqE.js +0 -4604
- package/dist/ReportPreview-QKRKQOe3.cjs +0 -6
- package/dist/RuleEditor-BA36yIV6.js +0 -1723
- package/dist/RuleEditor-CczJ6mJm.cjs +0 -1
- package/dist/TemplateReviewPanel-CHi4Alqa.cjs +0 -1
- package/dist/TemplateReviewPanel-Dz0G5o83.js +0 -217
- package/dist/binding-preview-BWsdf_z2.cjs +0 -2
- package/dist/binding-preview-DILq0-0f.js +0 -649
- package/dist/decimal-CI1OAczk.js +0 -87
- package/dist/decimal-CQA0xJex.cjs +0 -1
- package/dist/list-cell-CyM1ZlRN.cjs +0 -1
- package/dist/matrix-BbXarwyk.js +0 -661
- package/dist/matrix-Cm65WLLP.cjs +0 -1
- package/dist/param-validation-BWNjLcN0.js +0 -116
- package/dist/param-validation-CiTxFeZ8.cjs +0 -1
- package/dist/plugin-CThk42vJ.cjs +0 -1
- package/dist/plugin-tGn7-5oF.js +0 -25
- package/dist/template-registry-CGWTLtIA.cjs +0 -1
- package/dist/template-registry-DzlQs3OF.js +0 -434
- package/dist/template-review-D1RoNCPw.cjs +0 -1
- package/dist/template-review-fnteXRng.js +0 -1473
- package/dist/validate-Bf6ccFr2.cjs +0 -1
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
import { v as P, h as V, b as D } from "./matrix-BbXarwyk.js";
|
|
2
|
-
import { R as F } from "./render-plan-Ck6koX9L.js";
|
|
3
|
-
import { v as O, d as J } from "./validate-UUy9yP4K.js";
|
|
4
|
-
import { v as C, i as I } from "./param-validation-BWNjLcN0.js";
|
|
5
|
-
function x(e) {
|
|
6
|
-
return !!e && typeof e == "object" && !Array.isArray(e);
|
|
7
|
-
}
|
|
8
|
-
function S(e, s, t) {
|
|
9
|
-
if (e !== void 0) {
|
|
10
|
-
if (!x(e)) {
|
|
11
|
-
t.push({ path: s, message: "条件应为对象" });
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
(typeof e.field != "string" || !e.field.trim()) && t.push({ path: `${s}.field`, message: "条件需要字段" }), e.numeric !== void 0 && e.numeric !== "number" && e.numeric !== "decimal" && t.push({ path: `${s}.numeric`, message: "未知条件数值模式" }), [">", ">=", "<", "<=", "==", "!="].includes(e.op) || t.push({ path: `${s}.op`, message: "未知条件运算符" }), typeof e.value != "string" && !(typeof e.value == "number" && Number.isFinite(e.value)) && t.push({
|
|
15
|
-
path: `${s}.value`,
|
|
16
|
-
message: "条件值应为字符串或有限数字"
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function L(e, s, t) {
|
|
21
|
-
if (e === void 0) return;
|
|
22
|
-
if (!Array.isArray(e) || e.length > 2048) {
|
|
23
|
-
t.push({ path: s, message: "聚合应为数组且最多 2048 项" });
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const i = /* @__PURE__ */ new Set();
|
|
27
|
-
e.forEach((n, a) => {
|
|
28
|
-
const f = `${s}.${a}`;
|
|
29
|
-
if (!x(n)) {
|
|
30
|
-
t.push({ path: f, message: "聚合应为对象" });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const o = n.field;
|
|
34
|
-
typeof o != "string" || !o.trim() || i.has(o) ? t.push({
|
|
35
|
-
path: `${f}.field`,
|
|
36
|
-
message: "聚合输出字段应非空且唯一"
|
|
37
|
-
}) : i.add(o), n.numeric !== void 0 && n.numeric !== "number" && n.numeric !== "decimal" && t.push({
|
|
38
|
-
path: `${f}.numeric`,
|
|
39
|
-
message: "数值模式应为 number 或 decimal"
|
|
40
|
-
}), n.digits !== void 0 && (!Number.isInteger(n.digits) || Number(n.digits) < 0 || Number(n.digits) > 100) && t.push({
|
|
41
|
-
path: `${f}.digits`,
|
|
42
|
-
message: "小数位应为 0–100 的整数"
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
D({
|
|
46
|
-
...n,
|
|
47
|
-
field: n.valueField ?? o
|
|
48
|
-
});
|
|
49
|
-
} catch (m) {
|
|
50
|
-
t.push({
|
|
51
|
-
path: f,
|
|
52
|
-
message: m instanceof Error ? m.message : String(m)
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function j(e, s, t) {
|
|
58
|
-
if (e === void 0) return;
|
|
59
|
-
const i = P(e);
|
|
60
|
-
for (const n of i.errors) t.push({ path: s, message: n });
|
|
61
|
-
}
|
|
62
|
-
function H(e, s, t) {
|
|
63
|
-
if (e !== void 0)
|
|
64
|
-
try {
|
|
65
|
-
V(e);
|
|
66
|
-
} catch (i) {
|
|
67
|
-
t.push({
|
|
68
|
-
path: s,
|
|
69
|
-
message: i instanceof Error ? i.message : String(i)
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const R = "1.0";
|
|
74
|
-
class $ extends Error {
|
|
75
|
-
constructor(s) {
|
|
76
|
-
super(`模板校验失败:${s.slice(0, 3).map((t) => `${t.path}: ${t.message}`).join("; ")}`), this.errors = s, this.name = "ReportTemplateError";
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const W = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]), U = /* @__PURE__ */ new Set(["schemaVersion", "id", "name", "revision", "description", "template"]), G = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), M = 2e5, K = 64, v = 1e7;
|
|
80
|
-
function u(e) {
|
|
81
|
-
return !!e && typeof e == "object" && !Array.isArray(e);
|
|
82
|
-
}
|
|
83
|
-
function Y(e, s, t) {
|
|
84
|
-
const i = Object.getPrototypeOf(e), n = Array.isArray(e);
|
|
85
|
-
if (n ? i !== Array.prototype : i !== Object.prototype && i !== null)
|
|
86
|
-
return t.push({ path: s, message: "模板对象必须使用普通 JSON 对象原型" }), !1;
|
|
87
|
-
if (n) {
|
|
88
|
-
const a = Object.keys(e);
|
|
89
|
-
if (a.length !== e.length || a.some((f) => !/^(0|[1-9]\d*)$/.test(f) || Number(f) >= e.length))
|
|
90
|
-
return t.push({ path: s, message: "模板数组不能包含空位或额外属性" }), !1;
|
|
91
|
-
}
|
|
92
|
-
return Object.getOwnPropertySymbols(e).length > 0 ? (t.push({ path: s, message: "模板不能包含 Symbol 键" }), !1) : !0;
|
|
93
|
-
}
|
|
94
|
-
function z(e, s, t, i) {
|
|
95
|
-
return W.has(e) ? (i.push({ path: t, message: "模板不能包含可能污染原型的键" }), !1) : s.get || s.set || !s.enumerable ? (i.push({ path: t, message: "模板不能包含访问器或不可枚举字段" }), !1) : !0;
|
|
96
|
-
}
|
|
97
|
-
function X(e) {
|
|
98
|
-
return e === null || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e);
|
|
99
|
-
}
|
|
100
|
-
function E(e, s) {
|
|
101
|
-
const t = /* @__PURE__ */ new Set();
|
|
102
|
-
let i = 0, n = 0, a = !1;
|
|
103
|
-
const f = (o, m, h) => {
|
|
104
|
-
if (!a) {
|
|
105
|
-
if (++i > M) {
|
|
106
|
-
i === M + 1 && s.push({ path: m, message: "模板超过 JSON 节点安全上限" });
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (h > K) {
|
|
110
|
-
s.push({ path: m, message: "模板嵌套层级过深" });
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (typeof o == "string") {
|
|
114
|
-
n += o.length, n > v && (a = !0, s.push({ path: m, message: "模板文本超过 1000 万字符的安全上限" }));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (!X(o)) {
|
|
118
|
-
if (!o || typeof o != "object") {
|
|
119
|
-
s.push({ path: m, message: "模板只允许 JSON 值,不允许函数、undefined 或非有限数字" });
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (t.has(o)) {
|
|
123
|
-
s.push({ path: m, message: "模板不能包含循环引用" });
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (Y(o, m, s)) {
|
|
127
|
-
t.add(o);
|
|
128
|
-
for (const [d, l] of Object.entries(Object.getOwnPropertyDescriptors(o))) {
|
|
129
|
-
if (Array.isArray(o) && d === "length") continue;
|
|
130
|
-
const p = `${m}.${d}`;
|
|
131
|
-
if (z(d, l, p, s) && f(l.value, p, h + 1), i > M || a) break;
|
|
132
|
-
}
|
|
133
|
-
t.delete(o);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
f(e, "$", 0);
|
|
139
|
-
}
|
|
140
|
-
function g(e, s, t, i, n = !1) {
|
|
141
|
-
const a = e[s];
|
|
142
|
-
a === void 0 && !n || (typeof a != "string" || n && !a.trim()) && i.push({ path: `${t}.${s}`, message: n ? "应为非空字符串" : "应为字符串" });
|
|
143
|
-
}
|
|
144
|
-
function r(e, s, t, i, n = 0, a = !1) {
|
|
145
|
-
const f = e[s];
|
|
146
|
-
f === void 0 && !a || (typeof f != "number" || !Number.isFinite(f) || f < n) && i.push({ path: `${t}.${s}`, message: `应为大于等于 ${n} 的有限数字` });
|
|
147
|
-
}
|
|
148
|
-
function y(e, s, t, i) {
|
|
149
|
-
e[s] !== void 0 && typeof e[s] != "boolean" && i.push({ path: `${t}.${s}`, message: "应为布尔值" });
|
|
150
|
-
}
|
|
151
|
-
function b(e, s, t, i = !1) {
|
|
152
|
-
e !== void 0 && !G.has(e) && !(i && e === "auto") && t.push({ path: s, message: `未知对齐方式${i ? "(支持 auto)" : ""}` });
|
|
153
|
-
}
|
|
154
|
-
function c(e, s, t) {
|
|
155
|
-
if (e !== void 0) {
|
|
156
|
-
if (!u(e)) {
|
|
157
|
-
t.push({ path: s, message: "样式应为对象" });
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
b(e.align, `${s}.align`, t), e.verticalAlign !== void 0 && !["top", "middle", "bottom"].includes(e.verticalAlign) && t.push({ path: `${s}.verticalAlign`, message: "未知垂直对齐方式" });
|
|
161
|
-
for (const i of ["fontSize", "fontSizePx", "lineWidthPt", "lineHeight"]) r(e, i, s, t);
|
|
162
|
-
for (const i of ["letterSpacing", "rotateDeg"]) r(e, i, s, t, -1 / 0);
|
|
163
|
-
r(e, "opacity", s, t), typeof e.opacity == "number" && e.opacity > 1 && t.push({ path: `${s}.opacity`, message: "透明度不能大于 1" });
|
|
164
|
-
for (const i of ["bold", "italic", "underline", "borderTop", "borderRight", "borderBottom", "borderLeft"]) y(e, i, s, t);
|
|
165
|
-
for (const i of ["fontFamily", "color", "backgroundColor", "lineColor", "borderColor"]) g(e, i, s, t);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function B(e, s, t) {
|
|
169
|
-
if (e === void 0) return;
|
|
170
|
-
if (!Array.isArray(e)) {
|
|
171
|
-
t.push({ path: s, message: "参数定义应为数组" });
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const i = /* @__PURE__ */ new Set(), n = t.length;
|
|
175
|
-
e.forEach((a, f) => {
|
|
176
|
-
const o = `${s}.${f}`;
|
|
177
|
-
if (!u(a)) {
|
|
178
|
-
t.push({ path: o, message: "参数定义应为对象" });
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
g(a, "field", o, t, !0), typeof a.field == "string" && (i.has(a.field) && t.push({ path: `${o}.field`, message: "参数名重复" }), i.add(a.field)), a.type !== void 0 && !["text", "number", "date", "select"].includes(a.type) && t.push({ path: `${o}.type`, message: "未知参数类型" });
|
|
182
|
-
for (const m of ["label", "defaultValue", "placeholder"]) g(a, m, o, t);
|
|
183
|
-
y(a, "required", o, t);
|
|
184
|
-
for (const m of ["minLength", "maxLength"]) {
|
|
185
|
-
const h = a[m];
|
|
186
|
-
h !== void 0 && (typeof h != "number" || !Number.isSafeInteger(h) || h < 0) && t.push({ path: `${o}.${m}`, message: "长度边界应为非负整数" });
|
|
187
|
-
}
|
|
188
|
-
Q(a, o, t), a.options !== void 0 && (Array.isArray(a.options) ? a.options.forEach((m, h) => {
|
|
189
|
-
const d = `${o}.options.${h}`;
|
|
190
|
-
if (!u(m)) t.push({ path: d, message: "选项应为对象" });
|
|
191
|
-
else
|
|
192
|
-
for (const l of ["label", "value"]) typeof m[l] != "string" && t.push({ path: `${d}.${l}`, message: "选项标签与值应为字符串(允许空白选项)" });
|
|
193
|
-
}) : t.push({ path: `${o}.options`, message: "选项应为数组" }));
|
|
194
|
-
}), t.length === n && t.push(...C(e).map((a) => ({ path: a.path.replace("$.paramDefs", s), message: a.message })));
|
|
195
|
-
}
|
|
196
|
-
function Q(e, s, t) {
|
|
197
|
-
for (const a of ["min", "max"]) {
|
|
198
|
-
const f = e[a];
|
|
199
|
-
if (f === void 0) continue;
|
|
200
|
-
(e.type === "date" ? typeof f == "string" && I(f) : e.type === "number" && typeof f == "number" && Number.isFinite(f)) || t.push({ path: `${s}.${a}`, message: "number 使用有限数字边界,date 使用有效 YYYY-MM-DD 日期边界" });
|
|
201
|
-
}
|
|
202
|
-
const i = typeof e.min == "number" && typeof e.max == "number" && e.min > e.max, n = typeof e.min == "string" && typeof e.max == "string" && e.min > e.max;
|
|
203
|
-
(i || n) && t.push({ path: s, message: "最小边界不能大于最大边界" }), typeof e.minLength == "number" && typeof e.maxLength == "number" && e.minLength > e.maxLength && t.push({ path: s, message: "最小长度不能大于最大长度" });
|
|
204
|
-
}
|
|
205
|
-
function _(e, s, t) {
|
|
206
|
-
if (!Array.isArray(e) || e.length === 0) {
|
|
207
|
-
t.push({ path: s, message: "列表至少需要一列" });
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
e.every((i) => u(i) && i.hidden === !0) && t.push({ path: s, message: "列表至少需要一列可见列" }), e.forEach((i, n) => {
|
|
211
|
-
const a = `${s}.${n}`;
|
|
212
|
-
if (!u(i)) {
|
|
213
|
-
t.push({ path: a, message: "列应为对象" });
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (J(i, a, t), y(i, "hidden", a, t), S(i.visibleWhen, `${a}.visibleWhen`, t), typeof i.header != "string" && t.push({ path: `${a}.header`, message: "表头应为字符串(允许空白表头)" }), g(i, "field", a, t, !0), r(i, "widthMm", a, t, Number.MIN_VALUE, !0), c(i.style, `${a}.style`, t), c(i.headerStyle, `${a}.headerStyle`, t), b(i.align, `${a}.align`, t, !0), b(i.headerAlign, `${a}.headerAlign`, t), i.semanticRole !== void 0 && !["identifier", "dimension", "measure", "date", "text"].includes(i.semanticRole) && t.push({ path: `${a}.semanticRole`, message: "未知列语义" }), i.format !== void 0)
|
|
217
|
-
if (!u(i.format) || !["number", "percent", "date"].includes(i.format.kind))
|
|
218
|
-
t.push({ path: `${a}.format`, message: "未知列格式" });
|
|
219
|
-
else {
|
|
220
|
-
const f = i.format.digits;
|
|
221
|
-
f !== void 0 && (typeof f != "number" || !Number.isInteger(f) || f < 0 || f > 100) && t.push({ path: `${a}.format.digits`, message: "小数位应为 0–100 的整数" }), y(i.format, "thousands", `${a}.format`, t), g(i.format, "pattern", `${a}.format`, t);
|
|
222
|
-
}
|
|
223
|
-
i.rules !== void 0 && (Array.isArray(i.rules) ? i.rules.forEach((f, o) => {
|
|
224
|
-
const m = `${a}.rules.${o}`;
|
|
225
|
-
if (!u(f) || !u(f.when)) {
|
|
226
|
-
t.push({ path: m, message: "条件格式缺少 when 对象" });
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
S(f.when, `${m}.when`, t), g(f.when, "field", `${m}.when`, t, !0), [">", ">=", "<", "<=", "==", "!="].includes(f.when.op) || t.push({ path: `${m}.when.op`, message: "未知条件运算符" }), typeof f.when.value != "number" && typeof f.when.value != "string" && t.push({ path: `${m}.when.value`, message: "条件值应为数字或字符串" }), c(f.style, `${m}.style`, t);
|
|
230
|
-
}) : t.push({ path: `${a}.rules`, message: "条件格式应为数组" }));
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
function T(e, s, t) {
|
|
234
|
-
if (e !== void 0) {
|
|
235
|
-
if (!u(e)) {
|
|
236
|
-
t.push({ path: s, message: "分组应为对象" });
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
g(e, "field", s, t, !0);
|
|
240
|
-
for (const i of ["headerTemplate", "subtotalLabel"]) g(e, i, s, t);
|
|
241
|
-
for (const i of ["headerStyle", "subtotalStyle"]) c(e[i], `${s}.${i}`, t);
|
|
242
|
-
y(e, "keepWithNext", s, t), y(e, "repeatHeader", s, t), L(e.aggregates, `${s}.aggregates`, t), e.subtotal !== void 0 && (!Array.isArray(e.subtotal) || e.subtotal.some((i) => typeof i != "string")) && t.push({ path: `${s}.subtotal`, message: "小计字段应为字符串数组" });
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function Z(e, s, t) {
|
|
246
|
-
if (!(e === void 0 || typeof e == "boolean")) {
|
|
247
|
-
if (!u(e)) {
|
|
248
|
-
t.push({ path: s, message: "合计应为布尔值或对象" });
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
g(e, "label", s, t), L(e.aggregates, `${s}.aggregates`, t), c(e.style, `${s}.style`, t), e.fields !== void 0 && (!Array.isArray(e.fields) || e.fields.some((i) => typeof i != "string")) && t.push({ path: `${s}.fields`, message: "合计字段应为字符串数组" });
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
function q(e, s, t, i) {
|
|
255
|
-
const n = { kind: "rect", leftMm: 0, topMm: 0, widthMm: 1, heightMm: 1, grid: e };
|
|
256
|
-
if (O(n, t, i, []), k(n, t, i), !u(e) || !Array.isArray(e.cells)) return;
|
|
257
|
-
const a = e.cells, f = Array.isArray(s) ? s.length : 0;
|
|
258
|
-
if (a.length * f > M) {
|
|
259
|
-
i.push({ path: t, message: "表头逻辑网格超过 20 万格安全上限" });
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
e.cells.length || i.push({ path: `${t}.cells`, message: "表头至少需要一行" }), Array.isArray(e.colWidthsMm) && e.colWidthsMm.length !== f && i.push({ path: `${t}.colWidthsMm`, message: "表头列宽数量应与列表列数一致" }), Array.isArray(e.rowHeightsMm) && e.rowHeightsMm.length !== e.cells.length && i.push({ path: `${t}.rowHeightsMm`, message: "表头行高数量应与行数一致" }), ee(a, f, t, i);
|
|
263
|
-
}
|
|
264
|
-
function ee(e, s, t, i) {
|
|
265
|
-
const n = /* @__PURE__ */ new Set();
|
|
266
|
-
e.forEach((a, f) => {
|
|
267
|
-
if (!Array.isArray(a)) return;
|
|
268
|
-
let o = 0;
|
|
269
|
-
a.forEach((m, h) => {
|
|
270
|
-
for (; n.has(`${f}:${o}`); ) o++;
|
|
271
|
-
const d = u(m) && typeof m.colSpan == "number" ? m.colSpan : 1, l = u(m) && typeof m.rowSpan == "number" ? m.rowSpan : 1;
|
|
272
|
-
(o + d > s || f + l > e.length) && i.push({ path: `${t}.cells.${f}.${h}`, message: "表头合并区域超出表头边界" });
|
|
273
|
-
for (let p = f; p < Math.min(e.length, f + l); p++)
|
|
274
|
-
for (let A = o; A < Math.min(s, o + d); A++)
|
|
275
|
-
n.has(`${p}:${A}`) && i.push({ path: `${t}.cells.${f}.${h}`, message: "表头合并区域重叠" }), n.add(`${p}:${A}`);
|
|
276
|
-
o += d;
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function te(e, s, t) {
|
|
281
|
-
if (j(e.computed, `${s}.computed`, t), H(e.matrix, `${s}.matrix`, t), e.matrix && (e.detail || e.groupBy || Array.isArray(e.groups) && e.groups.length || e.grandTotal) && t.push({ path: `${s}.matrix`, message: "矩阵请使用自身 totals 汇总,不能同时配置普通分组、总计或主从明细" }), S(e.rowVisibleWhen, `${s}.rowVisibleWhen`, t), e.groups !== void 0 && (!Array.isArray(e.groups) || e.groups.length > 16 ? t.push({ path: `${s}.groups`, message: "分组应为数组,最多 16 级" }) : e.groups.forEach((a, f) => T(a, `${s}.groups.${f}`, t))), e.detail === void 0) return;
|
|
282
|
-
const i = e.detail, n = `${s}.detail`;
|
|
283
|
-
if (!u(i)) {
|
|
284
|
-
t.push({ path: n, message: "主从关联应为对象" });
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
for (const a of ["dataset", "parentKey", "foreignKey"]) g(i, a, n, t, !0);
|
|
288
|
-
for (const a of ["rowKey", "revisionField", "sourceTokenField"]) g(i, a, n, t, i[a] !== void 0);
|
|
289
|
-
g(i, "label", n, t), y(i, "header", n, t), r(i, "rowHeightMm", n, t, Number.MIN_VALUE), _(i.columns, `${n}.columns`, t), i.unmatched !== void 0 && i.unmatched !== "error" && i.unmatched !== "ignore" && t.push({ path: `${n}.unmatched`, message: "未关联明细策略应为 error 或 ignore" });
|
|
290
|
-
}
|
|
291
|
-
function se(e, s, t) {
|
|
292
|
-
for (const i of ["leftMm", "topMm"]) r(e, i, s, t, -1 / 0, !0);
|
|
293
|
-
r(e, "widthMm", s, t, Number.MIN_VALUE, !0), g(e, "dataset", s, t, !0), g(e, "title", s, t);
|
|
294
|
-
for (const i of ["rowKey", "revisionField", "sourceTokenField"]) g(e, i, s, t, e[i] !== void 0);
|
|
295
|
-
e.headerGrid !== void 0 && q(e.headerGrid, e.columns, `${s}.headerGrid`, t), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && t.push({ path: `${s}.layout`, message: "布局应为 page 或 wide" }), _(e.columns, `${s}.columns`, t);
|
|
296
|
-
for (const i of ["fontSizePt", "rowHeightMm"]) r(e, i, s, t, Number.MIN_VALUE);
|
|
297
|
-
r(e, "paddingMm", s, t);
|
|
298
|
-
for (const i of ["headerBold", "headerEveryPage", "border"]) y(e, i, s, t);
|
|
299
|
-
g(e, "headerBackgroundColor", s, t), b(e.align, `${s}.align`, t, !0), b(e.headerAlign, `${s}.headerAlign`, t), c(e.headerStyle, `${s}.headerStyle`, t), te(e, s, t), T(e.groupBy, `${s}.groupBy`, t), Z(e.grandTotal, `${s}.grandTotal`, t);
|
|
300
|
-
}
|
|
301
|
-
function k(e, s, t) {
|
|
302
|
-
c(e.style, `${s}.style`, t);
|
|
303
|
-
for (const n of ["text", "rawText", "imageData", "fallbackText", "nid", "rkey"]) g(e, n, s, t);
|
|
304
|
-
if (e.lines !== void 0 && (!Array.isArray(e.lines) || e.lines.some((n) => typeof n != "string")) && t.push({ path: `${s}.lines`, message: "文本行应为字符串数组" }), Array.isArray(e.richParagraphs) && e.richParagraphs.forEach((n, a) => {
|
|
305
|
-
if (!u(n)) return;
|
|
306
|
-
const f = `${s}.richParagraphs.${a}`;
|
|
307
|
-
b(n.align, `${f}.align`, t);
|
|
308
|
-
for (const o of ["lineHeight", "spaceBeforeMm", "spaceAfterMm", "indentMm"]) r(n, o, f, t);
|
|
309
|
-
Array.isArray(n.segments) && n.segments.forEach((o, m) => {
|
|
310
|
-
const h = `${f}.segments.${m}`;
|
|
311
|
-
if (!u(o)) {
|
|
312
|
-
t.push({ path: h, message: "富文本片段应为对象" });
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
o.kind !== void 0 && o.kind !== "text" && o.kind !== "field" && t.push({ path: `${h}.kind`, message: "未知富文本片段类型" });
|
|
316
|
-
for (const d of ["text", "field"]) g(o, d, h, t);
|
|
317
|
-
c(o.style, `${h}.style`, t);
|
|
318
|
-
});
|
|
319
|
-
}), !u(e.grid)) return;
|
|
320
|
-
const i = e.grid;
|
|
321
|
-
r(i, "gapMm", `${s}.grid`, t), r(i, "paddingMm", `${s}.grid`, t);
|
|
322
|
-
for (const n of ["colWidthsMm", "rowHeightsMm"]) {
|
|
323
|
-
const a = i[n];
|
|
324
|
-
a !== void 0 && (!Array.isArray(a) || a.some((f) => typeof f != "number" || !Number.isFinite(f) || f < 0)) && t.push({ path: `${s}.grid.${n}`, message: "网格尺寸应为有限非负数字数组" });
|
|
325
|
-
}
|
|
326
|
-
Array.isArray(i.cells) && i.cells.forEach((n, a) => {
|
|
327
|
-
Array.isArray(n) && n.forEach((f, o) => {
|
|
328
|
-
const m = `${s}.grid.cells.${a}.${o}`;
|
|
329
|
-
if (f !== null) {
|
|
330
|
-
if (!u(f)) {
|
|
331
|
-
t.push({ path: m, message: "网格单元格应为对象或 null" });
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
for (const h of ["text", "rawText", "numberFormat"]) g(f, h, m, t);
|
|
335
|
-
for (const h of ["colSpan", "rowSpan"]) {
|
|
336
|
-
const d = f[h];
|
|
337
|
-
d !== void 0 && (typeof d != "number" || !Number.isInteger(d) || d <= 0) && t.push({ path: `${m}.${h}`, message: "跨度应为正整数" });
|
|
338
|
-
}
|
|
339
|
-
f.value !== void 0 && f.value !== null && !["string", "number", "boolean"].includes(typeof f.value) && t.push({ path: `${m}.value`, message: "Excel 原始值应为字符串、数字、布尔值或 null" }), c(f.style, `${m}.style`, t), f.children !== void 0 && (Array.isArray(f.children) ? f.children.forEach((h, d) => {
|
|
340
|
-
u(h) && k(h, `${m}.children.${d}`, t);
|
|
341
|
-
}) : t.push({ path: `${m}.children`, message: "嵌套组件应为数组" }));
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
function ie(e) {
|
|
347
|
-
const s = [], t = [];
|
|
348
|
-
return E(e, s), s.length ? { ok: !1, errors: s, warnings: t } : (u(e) ? (e.schemaVersion !== void 0 && e.schemaVersion !== F && s.push({ path: "$.schemaVersion", message: "不支持的模板 schemaVersion" }), B(e.params, "$.params", s), !Array.isArray(e.pages) || e.pages.length === 0 ? s.push({ path: "$.pages", message: "模板至少需要一页" }) : e.pages.forEach((i, n) => {
|
|
349
|
-
const a = `$.pages.${n}`;
|
|
350
|
-
if (!u(i)) {
|
|
351
|
-
s.push({ path: a, message: "页应为对象" });
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
r(i, "widthMm", a, s, Number.MIN_VALUE, !0), r(i, "heightMm", a, s, Number.MIN_VALUE, !0), i.layout !== void 0 && i.layout !== "page" && i.layout !== "wide" && s.push({ path: `${a}.layout`, message: "布局应为 page 或 wide" }), typeof i.heightMm == "number" && i.heightMm >= 5e3 && s.push({ path: `${a}.heightMm`, message: "页高应小于 5000mm" });
|
|
355
|
-
for (const f of ["marginTopMm", "marginBottomMm", "marginLeftMm", "marginRightMm"]) r(i, f, a, s);
|
|
356
|
-
typeof i.widthMm == "number" && Number(i.marginLeftMm ?? 0) + Number(i.marginRightMm ?? 0) >= i.widthMm && s.push({ path: a, message: "横向页边距占满页面" }), typeof i.heightMm == "number" && Number(i.marginTopMm ?? 0) + Number(i.marginBottomMm ?? 0) >= i.heightMm && s.push({ path: a, message: "纵向页边距占满页面" }), Array.isArray(i.components) ? i.components.forEach((f, o) => {
|
|
357
|
-
const m = `${a}.components.${o}`;
|
|
358
|
-
u(f) && f.kind === "list" ? se(f, m, s) : (O(f, m, s, t), u(f) && k(f, m, s));
|
|
359
|
-
}) : s.push({ path: `${a}.components`, message: "组件应为数组" });
|
|
360
|
-
})) : s.push({ path: "$", message: "模板应为对象" }), { ok: s.length === 0, errors: s, warnings: t });
|
|
361
|
-
}
|
|
362
|
-
function ne(e) {
|
|
363
|
-
const s = [], t = [];
|
|
364
|
-
if (E(e, s), s.length) return { ok: !1, errors: s, warnings: t };
|
|
365
|
-
if (!u(e)) s.push({ path: "$", message: "模板文档应为对象" });
|
|
366
|
-
else {
|
|
367
|
-
for (const n of Object.keys(e))
|
|
368
|
-
U.has(n) || s.push({ path: `$.${n}`, message: "模板文档存在未知字段;只保存模板与描述,不保存取数或业务数据" });
|
|
369
|
-
e.schemaVersion !== R && s.push({ path: "$.schemaVersion", message: "不支持的模板文档版本" });
|
|
370
|
-
for (const n of ["id", "name"]) g(e, n, "$", s, !0);
|
|
371
|
-
for (const n of ["revision", "description"]) g(e, n, "$", s);
|
|
372
|
-
const i = ie(e.template);
|
|
373
|
-
s.push(...i.errors.map((n) => ({ ...n, path: `$.template${n.path.slice(1)}` }))), t.push(...i.warnings.map((n) => ({ ...n, path: `$.template${n.path.slice(1)}` })));
|
|
374
|
-
}
|
|
375
|
-
return { ok: s.length === 0, errors: s, warnings: t };
|
|
376
|
-
}
|
|
377
|
-
function N(e) {
|
|
378
|
-
const s = ne(e);
|
|
379
|
-
if (!s.ok) throw new $(s.errors);
|
|
380
|
-
}
|
|
381
|
-
function he(e) {
|
|
382
|
-
const s = [];
|
|
383
|
-
if (E(e, s), s.length) throw new $(s);
|
|
384
|
-
const t = { ...e, schemaVersion: e.schemaVersion ?? R };
|
|
385
|
-
return N(t), w(t);
|
|
386
|
-
}
|
|
387
|
-
function ue(e) {
|
|
388
|
-
let s = e;
|
|
389
|
-
if (typeof e == "string") {
|
|
390
|
-
if (e.length > v)
|
|
391
|
-
throw new $([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
|
|
392
|
-
try {
|
|
393
|
-
s = JSON.parse(e);
|
|
394
|
-
} catch {
|
|
395
|
-
throw new $([{ path: "$", message: "模板 JSON 语法无效" }]);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return N(s), w(s);
|
|
399
|
-
}
|
|
400
|
-
function ge(e) {
|
|
401
|
-
N(e);
|
|
402
|
-
const s = JSON.stringify(e, null, 2);
|
|
403
|
-
if (s.length > v) throw new $([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
|
|
404
|
-
return s;
|
|
405
|
-
}
|
|
406
|
-
function w(e) {
|
|
407
|
-
return JSON.parse(JSON.stringify(e));
|
|
408
|
-
}
|
|
409
|
-
function de(e = []) {
|
|
410
|
-
const s = /* @__PURE__ */ new Map(), t = {
|
|
411
|
-
get: (i) => {
|
|
412
|
-
const n = s.get(i);
|
|
413
|
-
return n ? w(n) : void 0;
|
|
414
|
-
},
|
|
415
|
-
list: () => Array.from(s.values(), ({ template: i, ...n }) => ({ ...n })),
|
|
416
|
-
register: (i, n = {}) => {
|
|
417
|
-
if (N(i), s.has(i.id) && !n.replace) throw new $([{ path: "$.id", message: `模板 ID ${i.id} 已注册;更新需显式 replace:true` }]);
|
|
418
|
-
s.set(i.id, w(i));
|
|
419
|
-
},
|
|
420
|
-
remove: (i) => s.delete(i)
|
|
421
|
-
};
|
|
422
|
-
for (const i of e) t.register(i);
|
|
423
|
-
return t;
|
|
424
|
-
}
|
|
425
|
-
export {
|
|
426
|
-
R,
|
|
427
|
-
$ as a,
|
|
428
|
-
ne as b,
|
|
429
|
-
de as c,
|
|
430
|
-
he as d,
|
|
431
|
-
ue as p,
|
|
432
|
-
ge as s,
|
|
433
|
-
ie as v
|
|
434
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const X=require("./render-plan-7xpGrCEl.cjs"),Pe=require("./validate-Bf6ccFr2.cjs"),lt=require("./report-params-CjWrjPl6.cjs"),_=require("./template-registry-CGWTLtIA.cjs"),ce=require("./param-validation-CiTxFeZ8.cjs"),pe=require("./grid-geometry-CZ_cYB6O.cjs"),ke=require("./number-format-CZ2T_5kF.cjs"),ct=require("./task-events-DQ276fn2.cjs"),Ie=require("./dataset-BkRmwgeJ.cjs"),q=require("./defaults-xhmcLLrf.cjs"),Z=require("./textwrap-CWHyzkBH.cjs"),R=require("./list-cell-CyM1ZlRN.cjs"),z=require("./matrix-Cm65WLLP.cjs"),O=require("./style-UgIJSA1F.cjs"),ut=require("./capabilities-CsZ-pNHR.cjs");function dt(e,t,r){const n=new Set,o=e.cells.map((a,s)=>{const i=[];let l=0;for(const c of a){for(;n.has(`${s}:${l}`);)l++;const u=c?.colSpan??1,f=c?.rowSpan??1;let d=0;for(let g=l;g<l+u;g++){t.has(g)&&d++;for(let w=s+1;w<s+f;w++)n.add(`${w}:${g}`)}d&&i.push(c?{...c,colSpan:d}:null),l+=u}return i});return{...e,cells:o,colWidthsMm:r}}function Ae(e){if(!e.columns.some(n=>n.hidden))return e;const t=new Set,r=e.columns.filter((n,o)=>n.hidden?!1:(t.add(o),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:dt(e.headerGrid,t,r.map(n=>n.widthMm))}:{}}}function ft(e){return!!(e.computed?.length||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen||e.matrix||e.detail||e.columns.some(t=>t.rules?.length||t.visibleWhen))}function ee(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"&&ft(r)))}class W extends Error{constructor(t,r){super(`报表页数超出上限 ${t}(至少 ${r} 页)`),this.limit=t,this.actual=r,this.code="page-limit",this.name="PaginatePageLimitError"}}class B extends Error{constructor(t,r){super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`),this.limit=t,this.actual=r,this.code="cell-limit",this.name="PaginateCellLimitError"}}function mt(e){return{widthMm:e.widthMm,heightMm:e.heightMm,marginTopMm:e.marginTopMm??0,marginBottomMm:e.marginBottomMm??0,marginLeftMm:e.marginLeftMm??0,marginRightMm:e.marginRightMm??0,components:[]}}function Me(e,t){const r=t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm);return e.components.reduce((n,o)=>o.kind!=="list"&&o.pageAnchor==="footer"?Math.min(n,o.topMm):n,r)}function $e(e){return e.components.reduce((t,r)=>r.kind!=="list"&&r.pageAnchor==="header"?Math.max(t,r.topMm+r.heightMm):t,0)}function Fe(e,t){let r=e.textMetrics.get(t);if(!r){const n=O.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:n,fontFamily:t.fontFamily??q.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:n*(t.lineHeight??q.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function gt(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function Oe(e,t){const r=e.fontSizePt??q.DEFAULT_FONT_PT,n=e.paddingMm??1,o=e.columns.map(m=>m.align??m.style?.align??e.align??"left"),a=e.columns.map((m,p)=>({...O.mergeComponentStyles({fontSize:r,verticalAlign:"middle"},m.style),align:o[p]==="auto"?"left":o[p]})),s=a.map((m,p)=>o[p]==="auto"?{left:m,center:{...m,align:"center"},right:{...m,align:"right"}}:void 0),i=e.columns.map((m,p)=>m.rules?.map(v=>{const x=s[p];if(x)return{left:O.mergeComponentStyles(x.left,v.style),center:O.mergeComponentStyles(x.center,v.style),right:O.mergeComponentStyles(x.right,v.style)};const y=O.mergeComponentStyles(a[p],v.style);return{left:y,center:y,right:y}})),l=e.columns.map(m=>R.resolveListHeaderStyle(e,m)),c=e.columns.map(m=>m.header);let u=e.rowHeightMm??0;for(let m=0;m<c.length;m++){const p=l[m],v=O.resolveFontSize(p).fontSizePt,x=Z.wrapText(c[m],e.columns[m].widthMm-n*2,{fontSizePt:v,fontFamily:p.fontFamily??q.DEFAULT_FONT_FAMILY,italic:p.italic,bold:p.bold,letterSpacingPt:p.letterSpacing},t),y=v*(p.lineHeight??q.LINE_HEIGHT)*25.4/72;u=Math.max(u,Math.max(x.length,1)*y+n*2)}const f=c.map((m,p)=>({text:m,style:l[p]})),d=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},g=e.columns.map(m=>m.widthMm),w=pt(e.headerGrid,g,{cells:[f],colWidthsMm:g,rowHeightsMm:[u],paddingMm:n});return{fontSizePt:r,paddingMm:n,cellStyles:a,autoStyles:s,ruleStyles:i,textMetrics:new WeakMap,numberFormats:e.columns.map(m=>R.toExcelNumberFormat(m.format)),derivedFields:new Set(e.computed?.map(m=>m.field)),borderStyle:d,headerHeightMm:w.rowHeightsMm.reduce((m,p)=>m+p,0),headerGrid:w,colWidthsMm:g,columns:e.columns}}function pt(e,t,r){if(!e)return r;if(!e.cells.length)throw new Error("自定义列表表头至少需要一行");const n=e.rowHeightsMm??e.cells.map(()=>r.rowHeightsMm[0]);if(n.length!==e.cells.length||n.some(o=>!Number.isFinite(o)||o<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:n}}function ht(e,t,r){const n=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:n&&(e.valueType="number"),t.editable!==void 0&&(e.editable=t.editable),(typeof e.value=="number"||e.value==null)&&r!==void 0&&(e.numberFormat=r)}function ue(e,t,r){const n=e.columns;let o=e.rowHeightFloorMm;const a=new Array(n.length);for(let s=0;s<n.length;s++){const i=n[s],l=i.visibleWhen&&!R.evalStyleRule(t,i.visibleWhen)?null:t[i.field],c=e.autoStyles[s]?R.resolveListAutoAlignment(l,i.format,i.semanticRole):"left";let u=e.autoStyles[s]?.[c]??e.cellStyles[s];if(i.rules)for(let p=0;p<i.rules.length;p++){const v=i.rules[p];if(R.evalStyleRule(t,v.when)){u=e.ruleStyles[s][p][c];break}}const f=i.format?R.formatValue(l,i.format):R.listCellText(l),d=Fe(e,u),g=Z.wrapText(f,i.widthMm-e.paddingMm*2,d.measureOptions,r);o=Math.max(o,g.length*d.lineMm+e.paddingMm*2);const w=gt(l),m={text:f,style:u};w!==void 0&&(m.value=w),ht(m,i,e.numberFormats[s]),e.derivedFields.has(i.field)&&(m.derived=!0,m.editable=!1),i.visibleWhen&&l===null&&!R.evalStyleRule(t,i.visibleWhen)&&(m.editable=!1),a[s]=m}return{grid:{cells:[a],colWidthsMm:e.colWidthsMm,rowHeightsMm:[o],paddingMm:e.paddingMm},heightMm:o}}function Ne(e){if(e!=null&&typeof e!="string"&&typeof e!="boolean"&&!(typeof e=="number"&&Number.isFinite(e)))throw new Error("分组字段应为有限 JSON 标量");return JSON.stringify([typeof e,e??null])}function*Ke(e,t,r=0){const n=t[r];if(!n){for(const a of e)yield{kind:"row",row:a};return}const o=new Map;for(const a of e){const s=Ne(a[n.field]),i=o.get(s);i?i.push(a):o.set(s,[a])}for(const a of o.values())yield{kind:"groupHeader",label:(n.headerTemplate??"{value}").replace(/\{value\}/g,R.listCellText(a[0][n.field])),firstRow:a[0],group:n,depth:r,rows:a},yield*Ke(a,t,r+1),(n.subtotal?.length||n.aggregates?.length)&&(yield{kind:"subtotal",label:n.subtotalLabel??"小计",rows:a,group:n,depth:r}),yield{kind:"groupEnd",depth:r}}function je(e,t,r,n=[]){const o=[...r.filter(a=>!n.some(s=>s.field===a)).map(a=>({field:a,op:"sum"})),...n];return new Map(o.map(a=>{const s=e.find(l=>l.field===a.field)?.format??{kind:"number",thousands:!0},i=z.aggregateRows(t,{...a,field:a.valueField??a.field});return[a.field,{text:R.formatValue(i,s),...i===null?{}:{value:i},...typeof i=="number"?{numberFormat:R.toExcelNumberFormat(s)}:{}}]}))}function Le(e,t){const r=e.findIndex(n=>t.includes(n.field));return r<0?1:r}function D(e,t,r,n,o,a){const s=[],i=Math.max(0,Math.min(a,e.columns.length)),l=O.mergeComponentStyles({fontSize:e.fontSizePt},o);i&&s.push({text:r,colSpan:i,style:{bold:!0,...l}});for(let d=i;d<e.columns.length;d++){const g=e.columns[d],w=n.get(g.field),m=e.autoStyles[d]?.[R.resolveListAutoAlignment(w?.value,g.format)]??e.cellStyles[d];s.push({...w,text:w?.text??"",style:O.mergeComponentStyles(m,o)})}const c={text:r,colSpan:e.columns.length,style:{bold:!0,...l}},u=i?[s]:[[c],s],f=u.map(d=>wt(e,d,t));return{grid:{cells:u,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((d,g)=>d+g,0)}}function wt(e,t,r){let n=e.rowHeightFloorMm,o=0;for(const a of t){let s=0;const i=o+(a.colSpan??1);for(;o<i;o++)s+=e.colWidthsMm[o]??0;const l=Fe(e,a.style),c=Z.wrapText(a.text??"",s-e.paddingMm*2,l.measureOptions,r);n=Math.max(n,c.length*l.lineMm+e.paddingMm*2)}return n}function yt(e,t,r){const{templatePage:n,current:o,warnings:a,nextId:s,pushCurrent:i}=r,l=()=>Me(n,o),c=Math.max(o.marginTopMm,$e(n)),u=n.layout==="wide"?$e(n):c,f={id:r.tableId,columnKeys:e.columns.map(h=>h.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}},d=new Map,g=new Map,w={kind:"rect",leftMm:e.leftMm,topMm:0,widthMm:e.widthMm,heightMm:t.headerHeightMm,grid:t.headerGrid,nid:s("listh"),table:{...f,role:"header",rowIndex:-1},style:t.borderStyle},m=h=>o.components.push({...w,topMm:h});let p=Math.max(e.topMm,c);m(p),p+=t.headerHeightMm+r.mmPerRow;function v(){const h=Math.max(n.layout==="wide"?0:e.topMm,u);return(e.headerEveryPage!==!1?h+t.headerHeightMm:u)+[...g.values()].reduce(($,E)=>$+E.heightMm,0)}function x(){const h=n.layout==="wide"?0:o.marginBottomMm;return Math.min(n.heightMm-h,Me(n,o))-v()}function y(h){if(p+h<=l())return;i(),o.components=[],o.heightMm=n.heightMm,n.layout==="wide"&&(o.marginTopMm=0,o.marginBottomMm=0);const M=Math.max(n.layout==="wide"?0:e.topMm,u);e.headerEveryPage!==!1?(m(M),p=M+t.headerHeightMm):p=u;for(const $ of g.values())F($,"listgr","group-header")}function L(h,M,$,E){const A=x();h.heightMm>A&&a.push(`列表 ${e.id??e.dataset} 行高 ${h.heightMm.toFixed(2)}mm 超出单页可用高度 ${A.toFixed(2)}mm,预览与打印可能截断内容`),y(h.heightMm),F(h,M,$,E)}function F(h,M,$,E){const A=h.table?.id??f.id,K=$==="header"?-1:d.get(A)??0;$!=="header"&&d.set(A,K+h.grid.cells.length),o.components.push({kind:"rect",leftMm:e.leftMm,topMm:p,widthMm:e.widthMm,heightMm:h.heightMm,grid:h.grid,nid:s(M),table:{...f,...h.table,role:$,rowIndex:K,...E?{source:E}:{}},style:t.borderStyle}),p+=h.heightMm}function T(h){h<=x()&&y(h)}return{keepTogether:T,placeGridRow:L,setGroupHeader:(h,M)=>{M?g.set(h,M):g.delete(h)}}}function bt(e,t){if(!e.rowKey)return;const r=t[e.rowKey];if((typeof r!="string"||!r.trim())&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);const n=e.revisionField?t[e.revisionField]:void 0,o=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(n!==void 0&&typeof n!="string"&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("业务修订号应为字符串或有限数字");if(o!==void 0&&typeof o!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...n===void 0?{}:{revision:n},...o===void 0?{}:{sourceToken:o}}}function he(e,t){const r=new Map;if(!e.rowKey)return r;const n=new Set;for(const o of t){const a=bt(e,o),s=JSON.stringify(a.rowKey);if(n.has(s))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);n.add(s),r.set(o,a)}return r}function vt(e,t,r,n,o){if(!e.grandTotal)return;const a=typeof e.grandTotal=="object"?e.grandTotal:void 0,s=te(e)[0],i=a?.fields??s?.subtotal??[],l=a?.aggregates??s?.aggregates??[];if(i.length===0&&l.length===0){n.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const c=D(r,n.measurer,a?.label??"合计",je(e.columns,t,i,l),a?.style??{},Le(e.columns,[...i,...l.map(u=>u.field)]));o.placeGridRow(c,"listgt","grand-total")}function we(e){if(e?.aborted){const t=new Error("报表排版已取消");throw t.name="AbortError",t}}function te(e){const t=e.groups??(e.groupBy?[e.groupBy]:[]);if(t.length>16)throw new Error("列表最多支持 16 级分组");return t}function He(e){const t=Ae(e),r=t.columns.reduce((o,a)=>o+a.widthMm,0),n=r>t.widthMm?t.widthMm/r:1;return n===1?t:{...t,columns:t.columns.map(o=>({...o,widthMm:o.widthMm*n}))}}function xt(e,t,r){const n=e.detail;if(!n)return;const o=new Set;for(const c of t){const u=de(c[n.parentKey]);if(o.has(u))throw new Error("主从明细的主表关联键重复");o.add(u)}const a=r.datasets[n.dataset]??[],s=new Map,i=[];for(const c of a){const u=c[n.foreignKey];if(!We(u)&&n.unmatched==="ignore")continue;const f=de(u);if(!o.has(f)){if(n.unmatched!=="ignore")throw new Error(`明细数据集 ${n.dataset} 存在未关联的业务键`);continue}const d=s.get(f);d?d.push(c):s.set(f,[c]),i.push(c)}const l=He({...e,id:`${e.id??e.dataset}:detail`,dataset:n.dataset,rowKey:n.rowKey,revisionField:n.revisionField,sourceTokenField:n.sourceTokenField,computed:void 0,columns:n.columns,headerGrid:void 0,rowHeightMm:n.rowHeightMm??e.rowHeightMm,detail:void 0});return{list:l,inter:{...Oe(l,r.measurer),rowHeightFloorMm:l.rowHeightMm??0},rows:s,sources:he(l,i)}}function We(e){return typeof e=="string"&&!!e.trim()||typeof e=="number"&&Number.isFinite(e)}function de(e){if(!We(e))throw new Error("主从关联键必须是非空字符串或有限数字");return Ne(e)}function*Mt(e,t,r,n,o){if(!r)return;const a=r.rows.get(de(t[e.detail.parentKey]))??[];if(!a.length)return;const s={id:`${n.tableId}:detail`,columnKeys:r.list.columns.map(i=>i.field),title:e.detail.label};e.detail.label&&o.placeGridRow({...D(r.inter,n.measurer,e.detail.label,new Map,{},r.list.columns.length),table:s},"listdl","group-header"),e.detail.header!==!1&&o.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:s},"listdh","header"),yield*n.takePages();for(const i of a)we(n.signal),o.placeGridRow({...ue(r.inter,i,n.measurer),table:s},"listdr","body",r.sources.get(i)),yield*n.takePages()}function $t(e,t){if(!e.matrix)return{list:e,rows:t};if(e.detail||e.groupBy||e.groups?.length||e.grandTotal)throw new Error("矩阵不能同时配置普通分组、总计或主从明细");const r=z.createMatrixTable(t,e.matrix),n=r.columns.map((a,s)=>({...a,widthMm:s===0?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:s===0?"center":"right"})),o={...e,columns:n,headerGrid:void 0,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};return e.layout==="wide"&&(o.widthMm=n.reduce((a,s)=>a+s.widthMm,0)),{list:o,rows:r.rows}}function St(e,t,r){const n=r.prepared.get(e);if(n)return n;let o=e.computed?.length?z.computeDataset(t,{fields:e.computed,signal:r.signal,formula:r.formula}).rows:t;const a=o===t?void 0:new Map(o.map((i,l)=>[i,t[l]]));e.rowVisibleWhen&&(o=o.filter(i=>R.evalStyleRule(i,e.rowVisibleWhen)));const s=$t(e,o);if(!e.matrix){const i=he(e,a?o.map(l=>a.get(l)):o);s.sources=a?new Map(o.map(l=>[l,i.get(a.get(l))])):i}return r.prepared.set(e,s),s}function*Rt(e,t,r){const n=St(e,t,r),o=n.rows;e=n.list,e.layout==="wide"&&(r.current.widthMm=Math.max(r.current.widthMm,e.leftMm+e.widthMm+r.current.marginRightMm));const a=n.sources??he(e,o),s=He(e),i=te(s),l={...Oe(s,r.measurer),rowHeightFloorMm:s.rowHeightMm??0},c=yt(s,l,r),u=xt(s,o,r);let f;for(const d of Ke(o,i)){if(we(r.signal),d.kind==="row")c.placeGridRow(f??ue(l,d.row,r.measurer),"listr","body",a.get(d.row)),f=void 0,yield*r.takePages(),yield*Mt(s,d.row,u,r,c);else if(d.kind==="groupHeader"){const g=D(l,r.measurer,d.label,new Map,d.group.headerStyle??{},s.columns.length);f??=ue(l,d.firstRow,r.measurer);const w=i.slice(d.depth+1).reduce((m,p)=>m+D(l,r.measurer,(p.headerTemplate??"{value}").replace(/\{value\}/g,R.listCellText(d.firstRow[p.field])),new Map,p.headerStyle??{},s.columns.length).heightMm,0);d.group.keepWithNext!==!1&&c.keepTogether(g.heightMm+w+f.heightMm),c.placeGridRow(g,"listg","group-header"),d.group.repeatHeader&&c.setGroupHeader(d.depth,g)}else if(d.kind==="subtotal"){const g=d.group.subtotal??[],w=d.group.aggregates??[],m=D(l,r.measurer,d.label,je(s.columns,d.rows,g,w),d.group.subtotalStyle??{},Le(s.columns,[...g,...w.map(p=>p.field)]));c.placeGridRow(m,"listst","subtotal")}else c.setGroupHeader(d.depth);yield*r.takePages()}vt(s,o,l,r,c),yield*r.takePages()}function Y(e){return e.kind!=="list"&&(e.pageAnchor!==void 0||e.kind==="text"&&typeof e.text=="string"&&(e.text.includes("{page}")||e.text.includes("{totalPages}")))}function re(e,t){return{...e,...e.text===void 0?{}:{text:t(e.text)},...e.lines?{lines:e.lines.map(t)}:{},...e.richParagraphs?{richParagraphs:e.richParagraphs.map(r=>({...r,segments:r.segments.map(n=>({...n,...n.text===void 0?{}:{text:t(n.text)}}))}))}:{},...e.grid?{grid:{...e.grid,cells:e.grid.cells.map(r=>r.map(n=>n?{...n,...n.text===void 0?{}:{text:t(n.text)},...n.children?{children:n.children.map(o=>re(o,t))}:{}}:null))}}:{}}}function Ct(e){let t=!1;for(const r of e.pages)for(const n of r.components)Y(n)&&re(n,o=>(o.includes("{totalPages}")&&(t=!0),o));return t}function Et(e,t,r,n,o,a){const s={pageWidthMm:t.widthMm,pageHeightMm:t.heightMm,...e.layout===void 0?{}:{layout:e.layout},marginTopMm:t.marginTopMm,marginBottomMm:t.marginBottomMm,marginLeftMm:t.marginLeftMm,marginRightMm:t.marginRightMm,components:t.components},i=l=>{const c=l.replace(/\{page\}/g,String(n));return a===void 0?c:c.replace(/\{totalPages\}/g,String(a))};for(const l of r)s.components.push(re(l,i));if(e.layout==="wide"){const l=s.components.reduce((c,u)=>Math.max(c,u.topMm+u.heightMm),0);s.marginBottomMm=o?e.marginBottomMm??0:0,s.pageHeightMm=Math.max(1,l+s.marginBottomMm)}return s}function Be(e){return e.cells.reduce((t,r)=>t+r.reduce((n,o)=>n+(o?1+(o.children?.reduce((a,s)=>a+Ve(s),0)??0):0),0),0)}function Ve(e){return e.grid?Be(e.grid):0}function ye(e){for(const t of["maxPages","maxCells","knownTotalPages"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<1))throw new RangeError(`${t} 应为正安全整数`)}function*Q(e,t,r,n,o,a=new WeakMap){let s=0,i=0,l=0;const c=u=>`${u}_${(++s).toString(36)}`;for(const[u,f]of e.pages.entries()){we(r.signal);const d=mt(f),g=f.components.filter(Y);let w=[];const m=(v=!1)=>{if(r.maxPages!==void 0&&i>=r.maxPages)throw new W(r.maxPages,i+1);if(r.maxCells!==void 0&&(l+=[...d.components,...g].reduce((x,y)=>x+Ve(y),0),l>r.maxCells))throw new B(r.maxCells,l);w.push(Et(f,d,g,++i,v,o))},p=()=>{const v=w;return w=[],v};for(const[v,x]of f.components.entries()){if(Y(x))continue;if(x.kind!=="list"){d.components.push(x);continue}const y=t[x.dataset];Array.isArray(y)||n.push(`数据集 ${x.dataset} 未提供数据,列表 ${x.id??""} 输出为空`),yield*Rt(x,Array.isArray(y)?y:[],{templatePage:f,current:d,warnings:n,nextId:c,pushCurrent:m,takePages:p,datasets:t,signal:r.signal,formula:r.formula,prepared:a,measurer:r.measurer??Z.heuristicMeasurer,mmPerRow:r.mmPerRow??0,tableId:`table:${u}:${v}`})}m(!0),yield*p()}}function Tt(e,t,r={}){ye(r);let n=0;for(const o of Q(e,t,{...r},[]))n++;return n}function*Ge(e,t,r={}){ye(r);const n=Ct(e),o=new WeakMap;let a=r.knownTotalPages;if(n&&a===void 0){a=0;for(const l of Q(e,t,r,[],void 0,o))a++}const s=[];let i=0;for(const l of Q(e,t,r,s,a,o)){for(;i<s.length;i++)r.onWarning?.(s[i]);yield l}}function ne(e,t,r={}){const n=typeof r=="number"?{mmPerRow:r}:r;ye(n);const o=[],a=[...Q(e,t,n,o,n.knownTotalPages)];for(const s of a)s.components=s.components.map(i=>Y(i)?re(i,l=>l.replace(/\{totalPages\}/g,String(a.length))):i);return o.forEach(s=>n.onWarning?.(s)),{plan:{schemaVersion:X.RENDER_PLAN_SCHEMA_VERSION,...ee(e)?{requiresRecalculation:!0}:{},pages:a},warnings:o}}function Pt(e){const t=e.columns.find(a=>!a.hidden)?.field;if(!t)return{groups:0,total:0};const r=te(e),n=(a=[],s=[])=>a.includes(t)||s.some(i=>i.field===t),o=typeof e.grandTotal=="object"?e.grandTotal:void 0;return{groups:r.filter(a=>n(a.subtotal,a.aggregates)).length,total:Number(n(o?.fields??r[0]?.subtotal,o?.aggregates??r[0]?.aggregates))}}function kt(e,t,r={}){if(e.matrix){let l=t[e.dataset]??[];e.computed?.length&&(l=z.computeDataset(l,{fields:e.computed,...r}).rows),e.rowVisibleWhen&&(l=l.filter(u=>R.evalStyleRule(u,e.rowVisibleWhen)));const c=z.estimateMatrixTable(l,e.matrix);return c.cells+c.columnCount}const n=t[e.dataset]?.length??0,o=e.columns.filter(l=>!l.hidden).length,a=te(e).length,s=Pt(e);let i=(n*(1+2*a+s.groups)+ +!!e.grandTotal*(1+s.total))*o;if(i+=e.headerGrid?Be(e.headerGrid):o,e.detail){const l=t[e.detail.dataset]?.length??0,c=e.detail.columns.filter(u=>!u.hidden).length;i+=(l+n*(+(e.detail.header!==!1)+ +!!e.detail.label))*c}if(!Number.isSafeInteger(i))throw new RangeError("报表单元格估算超出安全整数预算");return i}function qe(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function De(e,t,r){const n=e.grid;if(!n)return null;const o=n.cells[t];if(!o)return null;const s=pe.resolveGridLayout(n,e.widthMm,e.heightMm).cells.filter(l=>l.ri===t).findIndex(l=>l.ci===r),i=o[s];return i?{cell:i,sourceColumnIndex:s}:null}function It(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function At(e,t){return e.valueType?e.valueType:typeof t=="number"?"number":typeof t=="boolean"?"boolean":t===null&&e.numberFormat&&/[0#?]/.test(e.numberFormat)?"number":"text"}function Ft(e,t){if(e.derived)return"derived";if(e.editable===!1)return"cell";if(e.formula!==void 0)return"formula";if(e.children?.length)return"complex";if(t.table&&t.table.role!=="body"&&e.editable!==!0)return"structure"}function Ot(e,t){const r=e.table;if(r)return{id:r.id,rowIndex:r.rowIndex+t.rowIndex,role:r.role,columnKey:r.columnKeys[t.columnIndex]}}function Nt(e,t,r){if(e.derived)return;if(e.source)return{...e.source};const n=t.table?.source,o=t.table?.columnKeys[r.columnIndex];if(!(!n||n.rowKey===void 0||o===void 0))return{...n,rowKey:n.rowKey,field:o}}function _e(e,t,r){const n=It(r),o=Ft(r,e);return{address:{...t},cell:r,component:e,value:n,valueType:At(r,n),table:Ot(e,t),source:Nt(r,e,t),editable:o===void 0,readOnlyReason:o}}function oe(e,t){if(!qe(t))return null;const r=e.pages[t.pageIndex]?.components[t.componentIndex];if(!r)return null;const n=De(r,t.rowIndex,t.columnIndex);return n?_e(r,t,n.cell):null}function j(e){const t=new Map;return r=>{if(!qe(r))return null;const n=e.pages[r.pageIndex]?.components[r.componentIndex];if(!n?.grid)return null;let o=t.get(n);if(!o){const s=new Map;o=new Map;for(const i of pe.resolveGridLayout(n.grid,n.widthMm,n.heightMm).cells){const l=s.get(i.ri)??0;s.set(i.ri,l+1);const c=n.grid.cells[i.ri]?.[l];c&&o.set(`${i.ri}:${i.ci}`,c)}t.set(n,o)}const a=o.get(`${r.rowIndex}:${r.columnIndex}`);return a?_e(n,r,a):null}}class b extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function Kt(e,t){let r=e.trim();const n=t&&r.endsWith("%");if(n&&(r=r.slice(0,-1).trim()),/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?(?:[eE][+-]?\d+)?$/.test(r)&&(r=r.replace(/,/g,"")),!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(r))throw new b("number");return Number(r)/(n?100:1)}function jt(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new b("number");const r=typeof e=="number"?e:Kt(e,ke.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new b("number");return r}function Lt(e){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e=="boolean")return e;const t=String(e).trim().toLowerCase();if(["true","yes","是","1"].includes(t))return!0;if(["false","no","否","0"].includes(t))return!1;throw new b("boolean")}function be(e,t){return e.valueType==="number"?jt(t,e):e.valueType==="boolean"?Lt(t):t===null?null:String(t)}function Ht(e,t){const r=t.cell.text,o=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(a=>a.includes(r??""));return o?o[e?0:1]:String(e)}function G(e,t){return t===null?"":typeof t=="boolean"?Ht(t,e):typeof t=="number"?ke.formatExcelNumber(t,e.cell.numberFormat):String(t)}function Wt(e,t,r){const n=oe(e,t);if(!n)throw new b("missing");return J(n,r)}function J(e,t){if(!e.editable)throw new b("readonly");const r=be(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:r,text:G(e,r)}}function Bt(e,t){const r=e.table,n=t.table;return!r||!n||r.columnKey===void 0?!1:r.id===n.id&&r.rowIndex===n.rowIndex&&r.role===n.role&&r.columnKey===n.columnKey}function ze(e,t,r){const n=e.grid,{rowIndex:o,columnIndex:a}=t.address,s=De(e,o,a),i=[...n.cells],l=[...i[o]],c=G(t,r.value),u={...s.cell,value:r.value,text:c,rawText:c};return l[s.sourceColumnIndex]=u,i[o]=l,{...e,grid:{...n,cells:i}}}function Vt(e,t){const r=e.table?.columnKeys,n=t.table?.columnKey;return r&&n!==void 0?r.flatMap((o,a)=>o===n?[a]:[]):[]}function Gt(e,t,r,n,o,a){const s=t.table,i=o.table;if(!s||!i||s.id!==i.id||s.role!==i.role||!t.grid)return t;const l=i.rowIndex-s.rowIndex;if(l<0||l>=t.grid.cells.length)return t;let c=t;for(const u of Vt(t,o)){const f=oe(e,{pageIndex:r,componentIndex:n,rowIndex:l,columnIndex:u});f?.editable&&Bt(o,f)&&(c=ze(c,f,a))}return c}function qt(e,t,r,n,o,a){const s=o.address;return o.table?.columnKey!==void 0?Gt(e,t,r,n,o,a):s.pageIndex===r&&s.componentIndex===n?ze(t,o,a):t}function ve(e,t){const r=t.source;if(!r)return!1;const n=e.source;return!n||["datasetId","rowKey","field","revision","sourceToken"].some(o=>!Object.is(n[o],r[o]))}function Dt(e,t){const r=oe(e,t.address);if(!r)throw new b("missing");if(!r.editable)throw new b("readonly");if(ve(r,t))throw new b("conflict");if(!Object.is(r.value,t.previousValue)||(r.cell.text??"")!==t.previousText)throw new b("conflict");const n=be(r,t.value),o={...t,value:n,text:G(r,n)};if(Object.is(n,r.value)&&o.text===r.cell.text)return e;const a=e.pages.map((s,i)=>{const l=s.components.map((c,u)=>qt(e,c,i,u,r,o));return l.every((c,u)=>c===s.components[u])?s:{...s,components:l}});return{...e,pages:a}}function Je(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const n=new Set(t.edits.flatMap(s=>s.source?[s.source.datasetId]:[]));if(!n.size)return e;function o(s){return!s.datasetId||!n.has(s.datasetId)||(r.revision===void 0||Object.is(r.revision,s.revision))&&(r.sourceToken===void 0||r.sourceToken===s.sourceToken)?s:{...s,...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}}}const a=e.pages.map(s=>{const i=s.components.map(l=>{const c=l.table?.source?o(l.table.source):void 0,u=l.table&&c!==l.table.source?{...l.table,source:c}:l.table,f=l.grid?.cells.map(g=>{const w=g.map(m=>{if(!m?.source)return m;const p=o(m.source);return p===m.source?m:{...m,source:p}});return w.some((m,p)=>m!==g[p])?w:g}),d=l.grid&&f?.some((g,w)=>g!==l.grid.cells[w])?{...l.grid,cells:f}:l.grid;return u!==l.table||d!==l.grid?{...l,table:u,grid:d}:l});return i.some((l,c)=>l!==s.components[c])?{...s,components:i}:s});return a.some((s,i)=>s!==e.pages[i])?{...e,pages:a}:e}function _t(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function Se(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):_t(e.address)}function zt(e,t){if(!t.length)return e;const r=new Map(t.map(l=>[Se(l),l])),n=new Set(t.flatMap(l=>l.table?[l.table.id]:[])),o=new Set(t.map(l=>`${l.address.pageIndex}:${l.address.componentIndex}`)),a=j(e);function s(l,c,u){const f=l.grid;if(!f||!o.has(`${c}:${u}`)&&!n.has(l.table?.id??""))return l;const d=new Map,g=new Map;for(const w of pe.resolveGridLayout(f,l.widthMm,l.heightMm).cells){const m=g.get(w.ri)??0;g.set(w.ri,m+1);const p=a({pageIndex:c,componentIndex:u,rowIndex:w.ri,columnIndex:w.ci}),v=p&&r.get(Se(p));if(!v||!p.editable)continue;const x=d.get(w.ri)??[...f.cells[w.ri]],y=G(p,v.value);Object.is(p.value,v.value)&&y===p.cell.text||(x[m]={...w.cell,value:v.value,text:y,rawText:y},d.set(w.ri,x))}return d.size?{...l,grid:{...f,cells:f.cells.map((w,m)=>d.get(m)??w)}}:l}const i=e.pages.map((l,c)=>{const u=l.components.map((f,d)=>s(f,c,d));return u.every((f,d)=>f===l.components[d])?l:{...l,components:u}});return i.every((l,c)=>l===e.pages[c])?e:{...e,pages:i}}function I(e){const t=e.source;if(t)return JSON.stringify([t.datasetId,t.rowKey,t.field]);const r=e.table;if(r?.columnKey!==void 0)return JSON.stringify([r.id,r.role,r.rowIndex,r.columnKey]);const n=e.address;return JSON.stringify([n.pageIndex,n.componentIndex,n.rowIndex,n.columnIndex])}function Jt(e,t,r){if(typeof r!="string"||!r.trim()||!Array.isArray(t))throw new b("missing");if(t.length>1e4)throw new b("limit");const n=new Set,o=j(e),a=t.map(({address:s,value:i})=>{const l=o(s);if(!l)throw new b("missing");const c=J(l,i),u=I(c);if(n.has(u))throw new b("duplicate");return n.add(u),c});return{requestId:r,edits:a}}function Ut(e,t){if(t.edits.length>1e4)throw new b("limit");const r=j(e),n=new Set,o=t.edits.map(a=>{const s=r(a.address);if(!s)throw new b("missing");const i=I(a);if(n.has(i))throw new b("duplicate");if(n.add(i),ve(s,a)||!Object.is(s.value,a.previousValue)||(s.cell.text??"")!==a.previousText)throw new b("conflict");return J(s,a.value)});return zt(e,o)}function Yt(e){const t=new Map;for(const r of e){const n=I(r),o=t.get(n),a=o?{...r,previousValue:o.previousValue,previousText:o.previousText}:{...r};Object.is(a.previousValue,a.value)?t.delete(n):t.set(n,a)}return[...t.values()]}function V(e,t){for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);e.first=Math.imul(e.first^n,16777619),e.second=Math.imul(e.second,33)^n,e.count++}}function Qt(e,t,r){const n=Object.getOwnPropertyDescriptor(e,t);if(!n||n.get||n.set)throw new b("conflict");V(r,`${t.length}:${t}`),Ue(n.value,r)}function Xt(e,t){if(Object.getOwnPropertyDescriptor(e,"toJSON"))throw new b("conflict");if(t.active.has(e))throw new b("conflict");if(t.active.add(e),e instanceof Date)V(t,`date:${Date.prototype.getTime.call(e)};`);else{const r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw new b("conflict");const n=Object.keys(e);V(t,`${Array.isArray(e)?"array":"object"}:${Array.isArray(e)?e.length:n.length}:{`),n.forEach(o=>Qt(e,o,t)),V(t,"}")}t.active.delete(e)}function Ue(e,t){if(++t.nodes>1e6)throw new b("limit");if(e===null){V(t,"null;");return}if(typeof e=="object"){Xt(e,t);return}if(typeof e=="function"||typeof e=="symbol")throw new b("conflict");const r=String(e);V(t,`${typeof e}:${r.length}:${r};`)}function Re(e){const t={first:2166136261,second:5381,count:0,nodes:0,active:new Set};return Ue(e,t),`${t.count}:${t.first>>>0}:${t.second>>>0}`}function fe(e,t,r){if(++r.nodes>1e6)throw new b("limit");if(typeof e=="string"&&(r.text+=e.length,r.text>32*1024*1024))throw new b("limit");if(e===null||typeof e!="object")return e;if(t.has(e))throw new b("conflict");if(e instanceof Date)return new Date(Date.prototype.getTime.call(e));t.add(e);const n=Array.isArray(e)?e.map(o=>fe(o,t,r)):Object.fromEntries(Object.entries(e).map(([o,a])=>[o,fe(a,t,r)]));return t.delete(e),n}function Zt(e){return fe(e,new Set,{nodes:0,text:0})}function Ye(e){const t=[];for(const r of e.template.pages)for(const n of r.components)n.kind==="list"&&(t.push(n),n.detail&&t.push({...n.detail,relation:{detail:n.detail,parentRows:e.datasets[n.dataset]??[]}}));return t}function Ce(e){return JSON.stringify([e.datasetId,e.rowKey])}function Qe(e){const t=new Map,r=new Set;return e.forEach((n,o)=>{for(const a of Ye(n)){if(!a.rowKey)continue;const s=a.relation,i=s?new Set(s.parentRows.map(l=>JSON.stringify(l[s.detail.parentKey]))):void 0;(n.datasets[a.dataset]??[]).forEach((l,c)=>{if(s&&!i.has(JSON.stringify(l[s.detail.foreignKey])))return;const u=l[a.rowKey];if(typeof u!="string"&&typeof u!="number")return;const f=`${o}:${a.dataset}:${c}:${a.rowKey}`;if(r.has(f))return;r.add(f);const d=Ce({datasetId:a.dataset,rowKey:u}),g=t.get(d)??[];g.push({partIndex:o,dataset:a.dataset,rowIndex:c,row:l,binding:a}),t.set(d,g)})}}),n=>{const o=t.get(Ce(n));if(!o?.length)throw new b("missing");if(new Set(o.map(a=>`${a.partIndex}:${a.dataset}`)).size!==o.length)throw new b("conflict");return o}}function Xe(e,t){const r=e.map(o=>({...o,datasets:{...o.datasets}})),n=new Set;for(const{row:o,field:a,value:s}of t){const i=r[o.partIndex],l=`${o.partIndex}:${o.dataset}`;n.has(l)||(i.datasets[o.dataset]=[...i.datasets[o.dataset]],n.add(l)),i.datasets[o.dataset][o.rowIndex]={...i.datasets[o.dataset][o.rowIndex],[a]:s}}return r}function er(e,t,r){const n=[],o=new Set;return e.forEach((a,s)=>{for(const i of Ye(a))t.has(i.dataset)&&(a.datasets[i.dataset]??[]).forEach((l,c)=>{const u={partIndex:s,dataset:i.dataset,rowIndex:c,row:l,binding:i};for(const[f,d]of[[i.revisionField,r.revision],[i.sourceTokenField,r.sourceToken]]){if(!f||d===void 0)continue;const g=`${s}:${i.dataset}:${c}:${f}`;o.has(g)||(o.add(g),n.push({row:u,field:f,value:d}))}})}),n}function Ze(e){const t=new Map,r=j(e);return e.pages.forEach((n,o)=>n.components.forEach((a,s)=>{if(!(!a.grid||a.table?.role!=="body"))for(let i=0;i<a.grid.cells.length;i++)for(let l=0;l<a.table.columnKeys.length;l++){const c=r({pageIndex:o,componentIndex:s,rowIndex:i,columnIndex:l});c?.source&&c.editable&&t.set(I(c),c)}})),t}function tr(e,t,r){const n=Ze(e),o=j(e);return t.map(a=>{const s=a.source?n.get(I(a)):o(a.address);if(!s||I(s)!==I(a))throw new b("missing");return{address:{...s.address},value:a[r]}})}async function et(e,t,r={}){const n=[],o={...r,knownTotalPages:void 0};for(const a of Ge(e,t,o))n.push(a),n.length%8===0&&await new Promise(s=>setTimeout(s,0));if(r.signal?.aborted){const a=new Error("报表重算已取消");throw a.name="AbortError",a}return{schemaVersion:X.RENDER_PLAN_SCHEMA_VERSION,...ee(e)?{requiresRecalculation:!0}:{},pages:n}}const me=new WeakMap;function rr(e){return me.get(e)}function U(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function tt(e,t){return e[t]===void 0?"":e[t]}function nr(e,t){if(t.edits.length>1e4)throw new b("limit");const r=j(e),n=new Set,o=[],a=t.edits.map(s=>{const i=r(s.address);if(!i?.source)throw new b("missing");const l=I(s);if(n.has(l))throw new b("duplicate");if(n.add(l),ve(i,s)||!Object.is(i.value,s.previousValue)||(i.cell.text??"")!==s.previousText)throw new b("conflict");return o.push(i),J(i,s.value)});return{batch:{requestId:t.requestId,edits:a},contexts:o}}function or(e,t){const r=Qe(e);return t.flatMap(n=>{if(!n.source)throw new b("missing");return r(n.source).map(o=>{if(!Object.is(tt(o.row,n.source.field),n.previousValue))throw new b("conflict");if(o.binding.rowKey===n.source.field)throw new b("readonly");return{row:o,field:n.source.field,value:n.value}})})}function ie(e,t,r){const n={...e,value:t,source:{...e.source,...r?.revision===void 0?{}:{revision:r.revision},...r?.sourceToken===void 0?{}:{sourceToken:r.sourceToken}}};return n.cell={...e.cell,value:n.value,text:G(n,n.value)},n}function sr(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return[...e];const n=new Set(t.edits.flatMap(o=>o.source?[o.source.datasetId]:[]));return Xe(e,er(e,n,r))}function xe(e,t){let r=t.parts;const n=t.rebuild,o=Re(r);let a=e,s;const i=new Map;function l(f){if(f!==a)throw new b("conflict");if(s)return s;if(Re(r)!==o)throw new b("conflict");return Zt(r)}async function c(f,d,g,w={}){U(w.signal),d={requestId:d.requestId,edits:d.edits.map(y=>({...y,address:{...y.address},source:y.source?{...y.source}:void 0,table:y.table?{...y.table}:void 0}))},g=g.map(y=>({...y,address:{...y.address},source:y.source?{...y.source}:void 0,table:y.table?{...y.table}:void 0,cell:{...y.cell}})),await new Promise(y=>setTimeout(y,0)),U(w.signal);const m=l(f),p=Xe(m,or(m,d.edits)),v=await n(p,w.signal);U(w.signal);let x=!1;return{plan:v,commit(y){if(U(w.signal),x||a!==f)throw new b("conflict");if(y?.conflicts?.length)throw new b("conflict");const L=sr(p,d,y),F=Je(v,d,y);if(y){const T=new Set(d.edits.map(P=>P.source.datasetId));for(const[P,h]of i)T.has(h.source.datasetId)&&i.set(P,ie(h,h.value,y))}return g.forEach((T,P)=>i.set(I(T),ie(T,d.edits[P].value,y))),x=!0,s=L,r=void 0,a=F,me.set(a,u),a}}}const u={get plan(){return a},async prepare(f,d,g){const w=nr(f,d);return c(f,w.batch,w.contexts,g)},async prepareHistory(f,d,g,w,m){if(!w.trim()||d.length>1e4)throw new b("limit");const p=l(f),v=Qe(p),x=Ze(f),y=new Set,F=d.map(h=>{if(!h.source)throw new b("missing");const M=I(h);if(y.has(M))throw new b("duplicate");y.add(M);const $=x.get(M)??i.get(M);if(!$?.source)throw new b("missing");const E=v($.source)[0];return ie($,tt(E.row,$.source.field))}).map((h,M)=>({context:h,edit:J(h,d[M][g])})).filter(({edit:h})=>!Object.is(h.previousValue,h.value)),T={requestId:w,edits:F.map(({edit:h})=>h)},P=F.map(({context:h})=>h);return{batch:T,contexts:P,prepared:await c(f,T,P,m)}}};return me.set(e,u),u}function ar(e){const t=ne(e.template,e.datasets,e.pagination).plan;return xe(t,{parts:[{template:e.template,datasets:e.datasets}],rebuild:(r,n)=>et(r[0].template,r[0].datasets,{...e.pagination,signal:n})})}function ir(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...n}=e;return{...n,load:async o=>{const a=await t(o);k(o.signal);try{return r(a,o)}catch(s){throw new S("validate",`报表 ${o.reportId} 数据映射失败`,s)}}}}class S extends Error{constructor(t,r,n){super(r),this.name="ReportSourceError",this.code=t,this.cause=n}}function se(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function k(e){if(e?.aborted)throw se(e)}function ge(e,t){return t?new Promise((r,n)=>{const o=()=>t.removeEventListener("abort",a),a=()=>{o(),n(se(t))};t.addEventListener("abort",a,{once:!0}),t.aborted&&a(),Promise.resolve(e).then(s=>{o(),r(s)},s=>{o(),n(s)})}):Promise.resolve(e)}function lr(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new S("validate",`报表 ${t} 的数据集应为对象`);for(const[r,n]of Object.entries(e))if(!Array.isArray(n)||n.some(o=>!o||typeof o!="object"||Array.isArray(o)))throw new S("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function cr(e,t,r){const{reportId:n,signal:o}=t;try{const a=await ge(e(t),o);k(o);const s=_.validateReportTemplate(a);if(!s.ok)throw new S("validate",`报表 ${n} 模板校验失败:${s.errors.slice(0,3).map(i=>`${i.path}: ${i.message}`).join("; ")}`);return r.push(...s.warnings.map(i=>`${n}: ${i.path}: ${i.message}`)),a}catch(a){throw o?.aborted?se(o):a instanceof S?a:a instanceof _.ReportTemplateError?new S("validate",`报表 ${n} 模板校验失败:${a.message}`,a):new S("fetch",`报表 ${n} 模板加载失败:${a instanceof Error?a.message:String(a)}`,a)}}async function ur(e,t,r,n){const o=t.signal;let a;try{if(e.load)a=await ge(e.load(t),o);else if(e.provider){const s=await ge(e.provider.query(t),o);k(o),dr(s,r),a=s.datasets,n?.(r,s)}else a=e.datasets??{}}catch(s){throw o?.aborted?se(o):s instanceof S?s:new S("fetch",`报表 ${r} 取数失败:${s instanceof Error?s.message:String(s)}`,s)}return k(o),a}function dr(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new S("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new S("validate",`报表 ${t} Provider ${r} 应为字符串`);if(e.diagnostics!==void 0&&(!Array.isArray(e.diagnostics)||e.diagnostics.some(r=>!r||typeof r.code!="string"||typeof r.message!="string"||!["info","warning","error"].includes(r.severity))))throw new S("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`)}function fr(e,t,r){for(const[n,o]of Object.entries(e.dataSchema??{})){let a;try{a=Ie.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,n)?t[n]:void 0,o,{...e.dataValidation,path:`$.datasets.${n}`})}catch(s){throw new S("config",`报表 ${r} 数据集 ${n} 字段契约配置无效`,s)}if(!a.ok)throw new S("validate",`报表 ${r} 数据集 ${n} 不符合字段契约:${a.issues[0]?.message}`,{issues:a.issues})}}function rt(e){const t=r=>r.grid?.cells.reduce((n,o)=>n+o.reduce((a,s)=>a+(s?1+(s.children?.reduce((i,l)=>i+t(l),0)??0):0),0),0)??0;return e.pages.reduce((r,n)=>r+n.components.reduce((o,a)=>o+t(a),0),0)}function nt(e,t,r,n){return{...e,signal:n??e?.signal,...t===void 0?{}:{maxPages:Math.max(1,Math.min(t,e?.maxPages??t))},...r===void 0?{}:{maxCells:Math.max(1,Math.min(r,e?.maxCells??r))}}}function mr(e,t,r,n,o,a){const s=o.maxPages===void 0?void 0:o.maxPages-o.usedPages,i=o.maxCells===void 0?void 0:o.maxCells-o.usedCells;try{if(s!==void 0&&s<1&&e.pages.length)throw new W(0,1);const l=nt(r.pagination,s,i,a),c=ne(e,t,l),u=rt(c.plan);if(i!==void 0&&u>i)throw new B(i,u);return{...c,cells:u}}catch(l){let c=l;throw l instanceof W&&o.maxPages!==void 0&&l.limit===s&&(c=new W(o.maxPages,o.usedPages+l.actual)),l instanceof B&&o.maxCells!==void 0&&(c=new B(o.maxCells,o.usedCells+l.actual)),new S("validate",`报表 ${n} 排版失败:${c instanceof Error?c.message:String(c)}`,c)}}function ot(e,t,r,n){const o=new Map,a=s=>{let i=o.get(s);return i===void 0&&(i=JSON.stringify([r,n,s]),o.set(s,i)),i};for(const s of t.pages)e.push({...s,components:s.components.map(i=>i.table?{...i,table:{...i.table,id:a(i.table.id)}}:i)})}async function gr(e,t,r,n,o){const a=[];let s=0;for(const[c,u]of e.entries()){k(o);const f=n.maxPages===void 0?void 0:n.maxPages-a.length,d=n.maxCells===void 0?void 0:n.maxCells-s;if(f!==void 0&&f<1&&u.template.pages.length)throw new W(n.maxPages,a.length+1);const g=await et(u.template,u.datasets,nt(t[c]?.pagination,f,d,o));if(s+=rt(g),n.maxCells!==void 0&&s>n.maxCells)throw new B(n.maxCells,s);ot(a,g,c,r[c])}const i={schemaVersion:X.RENDER_PLAN_SCHEMA_VERSION,...e.some(c=>ee(c.template))?{requiresRecalculation:!0}:{},pages:a},l=Pe.validateRenderPlan(i);if(!l.ok)throw new S("validate",`重算渲染计划校验失败:${l.errors[0]?.message}`);return i}function pr(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new S("config","maxPages 应为正安全整数");if(t.maxCells!==void 0&&(!Number.isSafeInteger(t.maxCells)||t.maxCells<1))throw new S("config","maxCells 应为正安全整数");function r(o){const a=Object.prototype.hasOwnProperty.call(e,o)?e[o]:void 0;if(!a)throw new S("config",`未注册报表 ${o}`);return a}return Object.assign(async({reportIds:o,params:a,signal:s,onWarning:i,onQueryResult:l,...c})=>{k(s);const u=ct.createReportTaskReporter({...c,signal:s}),f=[...o],d={...a};if(f.length===0)throw new S("config","缺少报表 ID");const g=f.map(r),w=u.runSync("validate",()=>g.map(h=>ce.assertReportParams(h.params??(typeof h.template=="function"?[]:h.template.params)??[],d))),m=[],p=[];let v=0;const x=[];for(const[h,M]of g.entries()){k(s);const $=f[h],E={reportId:$,params:w[h],signal:s},A=typeof M.template=="function"?await u.run("query",()=>cr(M.template,E,x),$):M.template;E.params=u.runSync("validate",()=>ce.assertReportParams(M.params??A.params??[],E.params),$);const K=await u.run("query",()=>ur(M,E,$,l),$);u.runSync("validate",()=>{lr(K,$),t.onDatasets?.($,K,A),fr(M,K,$)},$),k(s);const ae=u.runSync("layout",()=>mr(A,K,M,$,{maxPages:t.maxPages,usedPages:m.length,maxCells:t.maxCells,usedCells:v},s),$);v+=ae.cells,p.push({template:A,datasets:K}),ot(m,ae.plan,h,$),x.push(...ae.warnings.map(it=>`${$}: ${it}`))}k(s);const y={schemaVersion:X.RENDER_PLAN_SCHEMA_VERSION,...p.some(h=>ee(h.template))?{requiresRecalculation:!0}:{},pages:m},L=u.runSync("validate",()=>{const h=Pe.validateRenderPlan(y);if(!h.ok)throw new S("validate",`渲染计划校验失败:${h.errors.slice(0,3).map(M=>`${M.path}: ${M.message}`).join("; ")}`);return h});x.push(...L.warnings.map(h=>`${h.path}: ${h.message}`));const F=g.map(h=>({...h,pagination:{...h.pagination}})),T={maxPages:t.maxPages,maxCells:t.maxCells};try{xe(y,{parts:p,rebuild:(h,M)=>gr(h,F,f,T,M)})}catch{x.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const P=i??t.onWarning??(h=>console.warn("[mach-report]",h));for(const h of x)k(s),P(h);return k(s),y},{getParamDefs:o=>lt.getReportParamDefs(e,o)})}function Ee(e){if(e===void 0)return;const t=typeof e=="string"?e:JSON.stringify(e);return t.length>160?t.slice(0,157)+"…":t}function hr(e){return/\.(?:computed|computeOptions|groups|groupBy|aggregates|grandTotal)(?:\.|\[|$)/.test(e)?"calculation":/\.(?:dataset|field|rowKey|revisionField|sourceTokenField|foreignKey|parentKey)$/.test(e)?"binding":/\.(?:style|headerStyle|format|rules|align|headerAlign|semanticRole|unit)(?:\.|\[|$)/.test(e)?"format":e.startsWith("$.template")?"structure":"metadata"}function Te(e){const t=new Map;for(const r of e){if(!r||typeof r!="object"||!("field"in r)||typeof r.field!="string"||t.has(r.field))return;t.set(r.field,r)}return t}function wr(e,t,r){return!e.startsWith("$.template.params")||t==="moved"?!1:/\.(?:type|required|min|max|minLength|maxLength|options|defaultValue)(?:\[|$)/.test(e)?!0:t!=="added"?!1:Array.isArray(r)?r.some(n=>!!n&&typeof n=="object"&&"required"in n&&n.required===!0):!!r&&typeof r=="object"&&"required"in r&&r.required===!0}function st(e,t,r={}){const n=_.parseReportTemplate(e),o=_.parseReportTemplate(t),a=r.maxChanges??500;if(!Number.isSafeInteger(a)||a<1||a>1e4)throw new RangeError("maxChanges must be between 1 and 10000");const s={changes:[],totalChanges:0,breakingChanges:0,truncated:!1};function i(u,f,d,g){const w=hr(f),m=u!=="moved"&&(w==="binding"||f==="$.id"||u==="removed"&&w==="structure"||wr(f,u,g));s.totalChanges++,m&&s.breakingChanges++,s.changes.length<a&&s.changes.push({kind:u,category:w,path:f,before:Ee(d),after:Ee(g),breaking:m})}function l(u,f,d){const g=Te(u),w=Te(f);if(!g||!w)return!1;const m=new Map(f.map((p,v)=>[p.field,v]));Array.from(g).forEach(([p,v],x)=>{const y=`${d}[${JSON.stringify(p)}]`;w.has(p)?(m.get(p)!==x&&i("moved",y,x,m.get(p)),c(v,w.get(p),y)):i("removed",y,v,void 0)});for(const[p,v]of w)g.has(p)||i("added",`${d}[${JSON.stringify(p)}]`,void 0,v);return!0}function c(u,f,d){if(!(Object.is(u,f)||d==="$.revision")){if(u===void 0||f===void 0){i(u===void 0?"added":"removed",d,u,f);return}if(Array.isArray(u)&&Array.isArray(f)){if((d.endsWith(".columns")||d.endsWith(".params"))&&l(u,f,d))return;for(let g=0;g<Math.max(u.length,f.length);g++)c(u[g],f[g],`${d}[${g}]`)}else if(u&&f&&typeof u=="object"&&typeof f=="object"&&!Array.isArray(u)&&!Array.isArray(f)){const g=u,w=f;for(const m of new Set([...Object.keys(g),...Object.keys(w)]))c(g[m],w[m],`${d}.${m}`)}else i("modified",d,u,f)}}return c(n,o,"$"),s.truncated=s.totalChanges>s.changes.length,s}function N(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function C(e,t,r){typeof e=="string"?r.push({field:e,path:t}):Array.isArray(e)&&e.forEach((n,o)=>C(n,`${t}[${o}]`,r))}function H(e,t,r){if(Array.isArray(e)){e.forEach((n,o)=>H(n,`${t}[${o}]`,r));return}if(N(e))for(const[n,o]of Object.entries(e))["field","weightField"].includes(n)?C(o,`${t}.${n}`,r):n!=="value"&&n!=="style"&&H(o,`${t}.${n}`,r)}function le(e,t,r){Array.isArray(e)&&e.forEach((n,o)=>{N(n)&&(typeof n.field=="string"&&n.valueField!==void 0&&n.valueField!==n.field&&r.summaries.add(n.field),C(n.valueField??n.field,`${t}[${o}].valueField`,r.fields),C(n.weightField,`${t}[${o}].weightField`,r.fields))})}function yr(e,t,r){for(const o of["rowKey","revisionField","sourceTokenField"])C(e[o],`${t}.${o}`,r.fields);!e.matrix&&Array.isArray(e.columns)&&e.columns.forEach((o,a)=>{N(o)&&(typeof o.field=="string"&&r.fields.push({field:o.field,path:`${t}.columns[${a}].field`,summary:!0}),H(o.rules,`${t}.columns[${a}].rules`,r.fields),H(o.visibleWhen,`${t}.columns[${a}].visibleWhen`,r.fields))}),H(e.rowVisibleWhen,`${t}.rowVisibleWhen`,r.fields),Array.isArray(e.computed)&&e.computed.forEach((o,a)=>{N(o)&&(typeof o.field=="string"&&r.generated.add(o.field),H(o.expression,`${t}.computed[${a}].expression`,r.fields),C(o.dependsOn,`${t}.computed[${a}].dependsOn`,r.fields),C(o.groupBy,`${t}.computed[${a}].groupBy`,r.fields))}),(Array.isArray(e.groups)?e.groups:e.groupBy?[e.groupBy]:[]).forEach((o,a)=>{N(o)&&(C(o.field,`${t}.groups[${a}].field`,r.fields),C(o.subtotal,`${t}.groups[${a}].subtotal`,r.fields),le(o.aggregates,`${t}.groups[${a}].aggregates`,r))}),N(e.grandTotal)&&(C(e.grandTotal.fields,`${t}.grandTotal.fields`,r.fields),le(e.grandTotal.aggregates,`${t}.grandTotal.aggregates`,r)),N(e.matrix)&&(C(e.matrix.rowFields,`${t}.matrix.rowFields`,r.fields),C(e.matrix.columnFields,`${t}.matrix.columnFields`,r.fields),le(e.matrix.measures,`${t}.matrix.measures`,r)),N(e.detail)&&C(e.detail.parentKey,`${t}.detail.parentKey`,r.fields)}function at(e){const t=[];function r(n,o){if(Array.isArray(n)){n.forEach((a,s)=>r(a,`${o}[${s}]`));return}if(N(n)){if(typeof n.dataset=="string"&&Array.isArray(n.columns)){const a={dataset:n.dataset,path:o,fields:[],generated:new Set,summaries:new Set};yr(n,o,a),typeof n.foreignKey=="string"&&C(n.foreignKey,`${o}.foreignKey`,a.fields),t.push(a)}for(const[a,s]of Object.entries(n))r(s,`${o}.${a}`)}}return r(e,"$.template"),t}function br(e,t,r){for(const n of at(e)){const o=Object.prototype.hasOwnProperty.call(t,n.dataset)?t[n.dataset]:void 0;if(!o){r.push({code:"dataset",severity:"error",path:`${n.path}.dataset`,message:`未声明数据集 ${n.dataset}`});continue}const a=new Set(o.fields.map(s=>s.field));n.fields.forEach(({field:s,path:i,summary:l})=>{!a.has(s)&&!n.generated.has(s)&&!(l&&n.summaries.has(s))&&r.push({code:"field",severity:"error",path:i,field:s,message:`数据集 ${n.dataset} 缺少字段 ${s}`})})}}function vr(e,t,r,n){const o=r.maxSampleRows??1e3,a=Object.values(e.datasets).reduce((i,l)=>i+l.length,0);if(a>o)return n.push({code:"sample",severity:"error",path:"$.fixtures",fixture:e.name,message:`样例 ${a} 行超过预算 ${o},请显式选择验收样例`}),!1;const s=new Set(at(t).map(i=>i.dataset));for(const[i,l]of Object.entries(r.dataSchemas??{}).filter(([c])=>s.has(c)))try{const c=Ie.validateDatasetRows(e.datasets[i],l,{path:`$.datasets.${i}`,maxRows:o});if(n.push(...c.issues.map(u=>({...u,code:"sample",severity:"error",fixture:e.name}))),!c.ok)return!1}catch(c){return n.push({code:"dataset",severity:"error",path:`$.dataSchemas.${i}`,message:String(c)}),!1}return!0}function xr(e,t,r){const n=t.pages[r.pageIndex]?.components[r.componentIndex],o=/^table:(\d+):(\d+)(?::|$)/.exec(n?.table?.id??"");if(o)return{path:`$.template.pages[${o[1]}].components[${o[2]}]`,pageIndex:Number(o[1]),componentIndex:Number(o[2])};for(const[a,s]of e.pages.entries()){const i=s.components.findIndex(l=>l===n||n?.nid!==void 0&&"nid"in l&&l.nid===n.nid);if(i>=0)return{path:`$.template.pages[${a}].components[${i}]`,pageIndex:a,componentIndex:i}}return{path:"$.template"}}function Mr(e,t,r,n,o){const a=ce.validateReportParams(e.template.params??[],t.params??{});if(o.issues.push(...a.issues.map(s=>({...s,code:"params",severity:"error",fixture:t.name,path:s.path.replace(/^\$\.params/,`$.fixtures[${r}].params`)}))),!!a.ok&&vr(t,e.template,n,o.issues))try{const{plan:s,warnings:i}=ne(e.template,t.datasets,{maxPages:n.maxPages??100,maxCells:n.maxCells??25e4}),l=(n.formats??["pdf","xlsx"]).flatMap(c=>ut.inspectOutputCapabilities(s,c));o.issues.push(...i.map(c=>({code:"layout",severity:"warning",path:"$.template",fixture:t.name,message:c}))),o.issues.push(...l.map(c=>({code:"output",severity:n.strictOutputs?"error":"warning",...xr(e.template,s,c),fixture:t.name,message:`${c.format}: ${c.message}`}))),o.samples.push({name:t.name,pages:s.pages.length,rows:Object.values(t.datasets).reduce((c,u)=>c+u.length,0),diagnostics:l})}catch(s){o.issues.push({code:"layout",severity:"error",path:"$.template",fixture:t.name,message:s instanceof Error?s.message:String(s)})}}function $r(e,t={}){const r={ok:!1,issues:[],samples:[]};try{for(const[o,a]of[["maxPages",t.maxPages],["maxCells",t.maxCells],["maxSampleRows",t.maxSampleRows]])if(a!==void 0&&(!Number.isSafeInteger(a)||a<1))throw new RangeError(`${o} must be a positive safe integer`);if((t.fixtures?.length??0)>20)throw new RangeError("At most 20 review fixtures are allowed");const n=_.parseReportTemplate(e);t.previous&&(r.changes=st(t.previous,n),r.changes.breakingChanges&&!t.allowBreakingChanges&&r.issues.push({code:"compatibility",severity:"error",path:"$.template",message:`${r.changes.breakingChanges} 项字段或结构变更需要明确确认兼容性`})),t.dataSchemas&&br(n.template,t.dataSchemas,r.issues);for(const[o,a]of(t.fixtures??[]).entries())Mr(n,a,o,t,r);t.fixtures?.length||r.issues.push({code:"sample",severity:"warning",path:"$.fixtures",message:"未提供验收样例,仅完成结构和字段检查,尚未验证排版与输出"})}catch(n){r.issues.push({code:"template",severity:"error",path:"$",message:n instanceof Error?n.message:String(n)})}return r.ok=r.issues.every(n=>n.severity!=="error"),r}exports.PaginateCellLimitError=B;exports.PaginatePageLimitError=W;exports.ReportCellEditError=b;exports.ReportSourceError=S;exports.applyReportCellEdit=Dt;exports.applyReportCellEditBatch=Ut;exports.applyReportEditResult=Je;exports.countTemplatePages=Tt;exports.createReportCellEdit=Wt;exports.createReportCellEditBatch=Jt;exports.createReportCellResolver=j;exports.createReportEditSession=ar;exports.createReportSource=pr;exports.defineReport=ir;exports.diffReportTemplates=st;exports.estimateListLayoutCells=kt;exports.formatReportCellEdit=G;exports.getReportCellContext=oe;exports.getReportEditSession=rr;exports.paginateTemplate=ne;exports.paginateTemplatePages=Ge;exports.parseReportCellInput=be;exports.projectListColumns=Ae;exports.registerReportEditSession=xe;exports.relocateReportCellEdits=tr;exports.reportCellEditKey=I;exports.reviewReportTemplate=$r;exports.summarizeReportCellEdits=Yt;
|