@agile-team/mach-report 2.22.0 → 2.23.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 +7 -6
- package/dist/{ExcelBindingWizard-CZyppD7I.js → ExcelBindingWizard-D4FLind-.js} +3 -3
- package/dist/{ExcelBindingWizard-CW79I6Gl.cjs → ExcelBindingWizard-D4RS5Bpg.cjs} +1 -1
- package/dist/{ParamEditor-CiYCJI0b.cjs → ParamEditor-C-6C9rd2.cjs} +1 -1
- package/dist/{ParamEditor-DQit-Gdf.js → ParamEditor-CASZt-Ma.js} +2 -2
- package/dist/{ReportBatchPanel-DKTpV7MU.js → ReportBatchPanel-Bq7t8a5r.js} +2 -2
- package/dist/{ReportBatchPanel-Db6TAfG5.cjs → ReportBatchPanel-YVj5IO5y.cjs} +1 -1
- package/dist/ReportLabelStudio-Cqhita1b.cjs +1 -0
- package/dist/{ReportLabelStudio-BYnRqmje.js → ReportLabelStudio-Dj7GXhuv.js} +295 -292
- package/dist/ReportParamPanel-DZbFVmDL.cjs +1 -0
- package/dist/{ReportParamPanel-BHSKVL8k.js → ReportParamPanel-Dgmqro1Y.js} +93 -79
- package/dist/ReportPreview-DeWzG8jQ.js +6257 -0
- package/dist/ReportPreview-FFIryrIr.cjs +6 -0
- package/dist/{ReportTemplateLibrary-DEXH07ND.cjs → ReportTemplateLibrary-BaWodmpm.cjs} +1 -1
- package/dist/{ReportTemplateLibrary-BZuKn0YK.js → ReportTemplateLibrary-DdAAAD2I.js} +1 -1
- package/dist/{RuleEditor-CIQn547x.js → RuleEditor-D2UwQGF6.js} +59 -59
- package/dist/{RuleEditor-zSUmPjKa.cjs → RuleEditor-DcT9xI1v.cjs} +1 -1
- package/dist/TemplateOutlinePanel-CUHFFiNM.cjs +1 -0
- package/dist/{TemplateOutlinePanel-D0PgOSQE.js → TemplateOutlinePanel-DrT7XN0m.js} +2 -2
- package/dist/{TemplateReusePanel-BKlAEF8-.js → TemplateReusePanel-4eejkNqi.js} +2 -2
- package/dist/{TemplateReusePanel-DAy_Hwqz.cjs → TemplateReusePanel-DZMyiX5I.cjs} +1 -1
- package/dist/{TemplateReviewPanel-div-EH_m.js → TemplateReviewPanel-BIhNLeNw.js} +2 -2
- package/dist/{TemplateReviewPanel-CowmHaQQ.cjs → TemplateReviewPanel-DnYImiXu.cjs} +1 -1
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.js +26 -26
- package/dist/artifact-integrity.json +106 -104
- package/dist/assets-D2gHc4Mz.cjs +1 -0
- package/dist/assets-T_gDeFaz.js +132 -0
- package/dist/auto-4pK9HePf.cjs +1 -0
- package/dist/auto-CTIJ6PnR.js +257 -0
- package/dist/capabilities-DiBj4Qgl.cjs +1 -0
- package/dist/capabilities-pg7j7VLT.js +106 -0
- package/dist/charts-Cjw5AYkg.cjs +1 -0
- package/dist/{charts-Dlv8j2AG.js → charts-CxJZ0XaY.js} +1 -1
- package/dist/computed-DK6BruFz.cjs +1 -0
- package/dist/{computed-C8NRZQss.js → computed-f3pOqWLX.js} +381 -301
- package/dist/data-bar-CeZuFmYl.cjs +1 -0
- package/dist/{data-bar-8baGYEZ9.js → data-bar-IkI6VvMQ.js} +1 -1
- package/dist/designer-DhrE7jzw.js +7169 -0
- package/dist/designer-IAZu6kBX.cjs +2 -0
- package/dist/designer.cjs +1 -1
- package/dist/designer.d.cts +98 -45
- package/dist/designer.d.ts +98 -45
- package/dist/designer.js +3 -3
- package/dist/dom-ChE5D-L-.cjs +1 -0
- package/dist/dom-JWrchIre.js +452 -0
- package/dist/dom-cell-address-DLD1mkTB.cjs +1 -0
- package/dist/dom-cell-address-Fn-8nk7D.js +11 -0
- package/dist/{encoding-ncQAvyOv.cjs → encoding-BefcaHdp.cjs} +1 -1
- package/dist/{encoding-DbnhbwI8.js → encoding-CL6rXEkR.js} +2 -2
- package/dist/{font-loader-Di0lQKFf.js → font-loader-BT5baV-o.js} +1 -1
- package/dist/{font-loader-BB372_XN.cjs → font-loader-Ga51c2VC.cjs} +1 -1
- package/dist/grid-strokes-Be24LGuV.cjs +1 -0
- package/dist/grid-strokes-EoY66L2f.js +53 -0
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +944 -1259
- package/dist/json-snapshot-1tvQNzQE.cjs +2 -0
- package/dist/{json-snapshot-DvQbZlD7.js → json-snapshot-OqkPyUk5.js} +763 -776
- package/dist/matrix-B8QWbsGM.cjs +1 -0
- package/dist/matrix-C6e_r_vp.js +302 -0
- package/dist/{pdf-CARdBcuw.cjs → pdf-HiEeXe9H.cjs} +42 -42
- package/dist/{pdf-DmlnL5eB.js → pdf-aobetCsy.js} +20 -20
- package/dist/pdf.cjs +1 -1
- package/dist/pdf.js +2 -2
- package/dist/{plugin-AcAQ2m9X.cjs → plugin-BFANt-i8.cjs} +1 -1
- package/dist/{plugin-w5Nyt08U.js → plugin-DeYYAL6F.js} +1 -1
- package/dist/{prefill-BXBxx5We.js → prefill-Dk4C6S5R.js} +21 -21
- package/dist/prefill-DsUD5OoK.cjs +1 -0
- package/dist/prepared-DCIxhKFo.js +94 -0
- package/dist/prepared-Dv-XM3i1.cjs +1 -0
- package/dist/progress-ByiOxUD3.js +250 -0
- package/dist/progress-WomPRP3B.cjs +1 -0
- package/dist/{protocol-C9ZaylID.cjs → protocol-B9YgfQ_d.cjs} +1 -1
- package/dist/{protocol-fjaeKkjf.js → protocol-DxeUKGYG.js} +3 -3
- package/dist/record-bindings-DatJZv_e.js +200 -0
- package/dist/record-bindings-MBxbeBsi.cjs +1 -0
- package/dist/{region-binding-workflow-aA8nxmkZ.js → region-binding-workflow-DjrXuR1q.js} +2 -2
- package/dist/{region-binding-workflow-BiJQ7NU6.cjs → region-binding-workflow-l7NGfagJ.cjs} +2 -2
- package/dist/report-encoding-worker.cjs +1 -1
- package/dist/report-encoding-worker.js +1 -1
- package/dist/rich-text-layout-Ciwa6D2o.js +52 -0
- package/dist/rich-text-layout-DK7A_a5r.cjs +3 -0
- package/dist/{runtime-BTtpjF3D.js → runtime-75Y5Oq5B.js} +52 -51
- package/dist/runtime-DKlGd_D4.cjs +1 -0
- package/dist/sbom.cdx.json +1 -1
- package/dist/server-node.cjs +5 -5
- package/dist/server-node.js +1642 -1586
- package/dist/server.cjs +1 -1
- package/dist/server.js +24 -24
- package/dist/style.css +1 -1
- package/dist/{template-catalog-JSxSqk5y.js → template-catalog--cjxzgH7.js} +17 -17
- package/dist/template-catalog-CoT7jm_6.cjs +1 -0
- package/dist/{template-fragments-D2JFj7Du.js → template-fragments-CPpGpQoz.js} +12 -12
- package/dist/template-fragments-GVjpew_q.cjs +1 -0
- package/dist/template-registry-DI59PXVK.cjs +1 -0
- package/dist/{template-registry-Do1Uav2Z.js → template-registry-O0hNIOfB.js} +17 -17
- package/dist/{template-serialization-CU4n_Miu.js → template-serialization-CWmHq7lX.js} +1 -1
- package/dist/{template-serialization-CgqBo6s-.cjs → template-serialization-CqQY4zDg.cjs} +1 -1
- package/dist/{textwrap-CkGjRFT3.js → textwrap-BIjtEWmq.js} +1 -1
- package/dist/textwrap-Cy7o1hIR.cjs +4 -0
- package/dist/vue/async.d.cts +24 -0
- package/dist/vue/async.d.ts +24 -0
- package/dist/vue/index.d.cts +25 -1
- package/dist/vue/index.d.ts +25 -1
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +52 -47
- package/dist/{workbook-session-BvEBRRMz.cjs → workbook-session-C6-SrnCT.cjs} +4 -4
- package/dist/{workbook-session-f0wVlzst.js → workbook-session-C9ZmCBwY.js} +15 -16
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +4 -4
- package/dist/xlsx.cjs +4 -4
- package/dist/xlsx.js +184 -179
- package/package.json +1 -1
- package/dist/ReportLabelStudio-B0i9ohQj.cjs +0 -1
- package/dist/ReportParamPanel-lngONOEz.cjs +0 -1
- package/dist/ReportPreview-BDgKssYR.js +0 -5887
- package/dist/ReportPreview-Dw-4icG6.cjs +0 -6
- package/dist/TemplateOutlinePanel-B5SfGYVN.cjs +0 -1
- package/dist/assets-CxHunY_9.js +0 -232
- package/dist/assets-vbjAGgk8.cjs +0 -1
- package/dist/auto-DcUHlKob.cjs +0 -1
- package/dist/auto-moShblh1.js +0 -240
- package/dist/charts-aCtoswXq.cjs +0 -1
- package/dist/component-tree-1_QCiQJX.js +0 -67
- package/dist/component-tree-BjZIp6w9.cjs +0 -1
- package/dist/computed-4TnxzgIh.cjs +0 -1
- package/dist/data-bar-YltqGTaC.cjs +0 -1
- package/dist/designer-B7jJeAeG.js +0 -6914
- package/dist/designer-BWQVpJeN.cjs +0 -2
- package/dist/grid-geometry-D3SJgWFv.js +0 -136
- package/dist/grid-geometry-D8ReblRV.cjs +0 -1
- package/dist/json-snapshot-nyV63AbB.cjs +0 -2
- package/dist/matrix-0hywp0-F.cjs +0 -1
- package/dist/matrix-Dy-tyY7E.js +0 -381
- package/dist/prefill-DUvejVt1.cjs +0 -1
- package/dist/prepared-YXy-fVLw.cjs +0 -1
- package/dist/prepared-rXCKqdHY.js +0 -88
- package/dist/progress-B0ctFpKf.cjs +0 -1
- package/dist/progress-Hc2vxoCs.js +0 -52
- package/dist/record-bindings-Ct1HkPrc.cjs +0 -1
- package/dist/record-bindings-VZGS-Qd8.js +0 -155
- package/dist/rich-text-layout-K48VHUoW.cjs +0 -3
- package/dist/rich-text-layout-wxBhnAS7.js +0 -102
- package/dist/runtime-Dq0LUsyS.cjs +0 -1
- package/dist/template-catalog-CLAM4w7H.cjs +0 -1
- package/dist/template-fragments-Ca25Jt7e.cjs +0 -1
- package/dist/template-outline-CDWXptuj.js +0 -88
- package/dist/template-outline-K4jGhATu.cjs +0 -1
- package/dist/template-registry-CWnuGqyP.cjs +0 -1
- package/dist/textwrap-OTOUMr4f.cjs +0 -4
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
const N = 1.35, v = 10.5, B = '"Microsoft YaHei", sans-serif', U = 0.75, R = "#333333", H = "#000000", k = "1.0.0-mach", $ = 25.4, y = 96;
|
|
2
|
-
function D(t = 96) {
|
|
3
|
-
return t / 25.4;
|
|
4
|
-
}
|
|
5
|
-
function G(t, o = 96) {
|
|
6
|
-
return (t || 0) * D(o);
|
|
7
|
-
}
|
|
8
|
-
function K(t, o = 96) {
|
|
9
|
-
return t / D(o);
|
|
10
|
-
}
|
|
11
|
-
function O(t, o = 96) {
|
|
12
|
-
return t * o / 72;
|
|
13
|
-
}
|
|
14
|
-
function W(t, o) {
|
|
15
|
-
const r = 10 ** o;
|
|
16
|
-
return Math.round(t * r) / r;
|
|
17
|
-
}
|
|
18
|
-
const Y = {
|
|
19
|
-
a3: { widthMm: 297, heightMm: 420 },
|
|
20
|
-
a4: { widthMm: 210, heightMm: 297 },
|
|
21
|
-
a5: { widthMm: 148, heightMm: 210 },
|
|
22
|
-
b4: { widthMm: 250, heightMm: 353 },
|
|
23
|
-
b5: { widthMm: 176, heightMm: 250 }
|
|
24
|
-
};
|
|
25
|
-
function j(t, o = 96, r = 10.5) {
|
|
26
|
-
if (t?.fontSizePx != null)
|
|
27
|
-
return { fontSizePt: t.fontSizePx * 72 / o, fontSizePx: t.fontSizePx };
|
|
28
|
-
const c = t?.fontSize ?? r;
|
|
29
|
-
return { fontSizePt: c, fontSizePx: O(c, o) };
|
|
30
|
-
}
|
|
31
|
-
function V(t, o = R) {
|
|
32
|
-
return {
|
|
33
|
-
color: t?.borderColor ?? t?.lineColor ?? o,
|
|
34
|
-
widthPt: t?.lineWidthPt ?? 0.75
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function X(t, o = H) {
|
|
38
|
-
return t?.color ?? o;
|
|
39
|
-
}
|
|
40
|
-
function Z(t) {
|
|
41
|
-
return t?.lineHeight ?? 1.35;
|
|
42
|
-
}
|
|
43
|
-
function q(t) {
|
|
44
|
-
const o = t?.borderTop !== !1, r = t?.borderRight !== !1, c = t?.borderBottom !== !1, a = t?.borderLeft !== !1;
|
|
45
|
-
return { top: o, right: r, bottom: c, left: a, inner: o || r || c || a };
|
|
46
|
-
}
|
|
47
|
-
function J(t, o) {
|
|
48
|
-
const r = { ...t, ...o };
|
|
49
|
-
return o?.fontSize != null && o.fontSizePx == null && delete r.fontSizePx, o?.fontSizePx != null && o.fontSize == null && delete r.fontSize, r;
|
|
50
|
-
}
|
|
51
|
-
function b(t, o) {
|
|
52
|
-
const r = t.length;
|
|
53
|
-
if (r === 0) return [];
|
|
54
|
-
const c = t.reduce((l, f) => l + f, 0), a = c > 0 && o > 0 ? o / c : 1, i = [];
|
|
55
|
-
let S = 0;
|
|
56
|
-
for (let l = 0; l < r; l++) {
|
|
57
|
-
const f = Math.max(0, t[l] * a);
|
|
58
|
-
i.push({ pos: S, size: f }), S += f;
|
|
59
|
-
}
|
|
60
|
-
return i;
|
|
61
|
-
}
|
|
62
|
-
function L(t, o, r) {
|
|
63
|
-
return t?.length ? b(t, o) : Array.from({ length: r }, (c, a) => ({
|
|
64
|
-
pos: o * a / r,
|
|
65
|
-
size: o / r
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
function Q(t, o, r) {
|
|
69
|
-
const c = t.cells ?? [], a = Math.max(c.length, 1), i = t.colWidthsMm?.length ?? Math.max(1, ...c.map((n) => Array.isArray(n) ? n.length : 0)), S = L(t.colWidthsMm, o, i), l = (n) => n <= 0 ? 0 : n >= i ? S[S.length - 1].pos + S[S.length - 1].size : S[n].pos, f = L(t.rowHeightsMm, r, a), d = (n) => n <= 0 ? 0 : n >= a ? f[f.length - 1].pos + f[f.length - 1].size : f[n].pos, p = /* @__PURE__ */ new Set(), g = (n, s) => `${n}:${s}`, T = [], E = /* @__PURE__ */ new Set(), x = /* @__PURE__ */ new Set(), w = (n, s) => `v${n}:${s}`, C = (n, s) => `h${n}:${s}`;
|
|
70
|
-
c.forEach((n, s) => {
|
|
71
|
-
if (!Array.isArray(n)) return;
|
|
72
|
-
let e = 0;
|
|
73
|
-
for (const m of n) {
|
|
74
|
-
for (; e < i && p.has(g(s, e)); ) e++;
|
|
75
|
-
if (e >= i) break;
|
|
76
|
-
const I = Math.max(1, Math.min(m?.colSpan ?? 1, i - e)), F = Math.max(1, m?.rowSpan ?? 1), M = Math.min(a, s + F), P = Math.min(i, e + I);
|
|
77
|
-
for (let h = s; h < M; h++)
|
|
78
|
-
for (let u = e; u < P; u++)
|
|
79
|
-
p.add(g(h, u));
|
|
80
|
-
for (let h = e + 1; h < P; h++)
|
|
81
|
-
for (let u = s; u < M; u++) E.add(w(h, u));
|
|
82
|
-
for (let h = s + 1; h < M; h++)
|
|
83
|
-
for (let u = e; u < P; u++) x.add(C(h, u));
|
|
84
|
-
const A = l(e), z = d(s);
|
|
85
|
-
T.push({
|
|
86
|
-
ri: s,
|
|
87
|
-
ci: e,
|
|
88
|
-
cell: m ?? {},
|
|
89
|
-
xMm: A,
|
|
90
|
-
yMm: z,
|
|
91
|
-
widthMm: l(P) - A,
|
|
92
|
-
heightMm: d(M) - z
|
|
93
|
-
}), e = P;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
const _ = [];
|
|
97
|
-
for (let n = 1; n < i; n++) {
|
|
98
|
-
let s = -1;
|
|
99
|
-
for (let e = 0; e <= a; e++) {
|
|
100
|
-
const m = e < a && !E.has(w(n, e));
|
|
101
|
-
m && s < 0 && (s = e), !m && s >= 0 && (_.push({ kind: "v", pos: l(n), from: d(s), to: d(e) }), s = -1);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
for (let n = 1; n < a; n++) {
|
|
105
|
-
let s = -1;
|
|
106
|
-
for (let e = 0; e <= i; e++) {
|
|
107
|
-
const m = e < i && !x.has(C(n, e));
|
|
108
|
-
m && s < 0 && (s = e), !m && s >= 0 && (_.push({ kind: "h", pos: d(n), from: l(s), to: l(e) }), s = -1);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return { columns: S, rows: f, cells: T, edges: _ };
|
|
112
|
-
}
|
|
113
|
-
export {
|
|
114
|
-
y as C,
|
|
115
|
-
B as D,
|
|
116
|
-
N as L,
|
|
117
|
-
$ as M,
|
|
118
|
-
Y as P,
|
|
119
|
-
k as S,
|
|
120
|
-
j as a,
|
|
121
|
-
W as b,
|
|
122
|
-
Z as c,
|
|
123
|
-
H as d,
|
|
124
|
-
V as e,
|
|
125
|
-
q as f,
|
|
126
|
-
J as g,
|
|
127
|
-
X as h,
|
|
128
|
-
U as i,
|
|
129
|
-
v as j,
|
|
130
|
-
R as k,
|
|
131
|
-
D as l,
|
|
132
|
-
G as m,
|
|
133
|
-
K as n,
|
|
134
|
-
O as p,
|
|
135
|
-
Q as r
|
|
136
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const N='"Microsoft YaHei", sans-serif';const R="#333333",O="#000000",U="1.0.0-mach";function M(o=96){return o/25.4}function v(o,t=96){return(o||0)*M(t)}function B(o,t=96){return o/M(t)}function H(o,t=96){return o*t/72}function b(o,t){const s=10**t;return Math.round(o*s)/s}const k={a3:{widthMm:297,heightMm:420},a4:{widthMm:210,heightMm:297},a5:{widthMm:148,heightMm:210},b4:{widthMm:250,heightMm:353},b5:{widthMm:176,heightMm:250}};function G(o,t=96,s=10.5){if(o?.fontSizePx!=null)return{fontSizePt:o.fontSizePx*72/t,fontSizePx:o.fontSizePx};const c=o?.fontSize??s;return{fontSizePt:c,fontSizePx:H(c,t)}}function $(o,t=R){return{color:o?.borderColor??o?.lineColor??t,widthPt:o?.lineWidthPt??.75}}function y(o,t=O){return o?.color??t}function K(o){return o?.lineHeight??1.35}function W(o){const t=o?.borderTop!==!1,s=o?.borderRight!==!1,c=o?.borderBottom!==!1,l=o?.borderLeft!==!1;return{top:t,right:s,bottom:c,left:l,inner:t||s||c||l}}function Y(o,t){const s={...o,...t};return t?.fontSize!=null&&t.fontSizePx==null&&delete s.fontSizePx,t?.fontSizePx!=null&&t.fontSize==null&&delete s.fontSize,s}function V(o,t){const s=o.length;if(s===0)return[];const c=o.reduce((f,h)=>f+h,0),l=c>0&&t>0?t/c:1,i=[];let S=0;for(let f=0;f<s;f++){const h=Math.max(0,o[f]*l);i.push({pos:S,size:h}),S+=h}return i}function I(o,t,s){return o?.length?V(o,t):Array.from({length:s},(c,l)=>({pos:t*l/s,size:t/s}))}function X(o,t,s){const c=o.cells??[],l=Math.max(c.length,1),i=o.colWidthsMm?.length??Math.max(1,...c.map(n=>Array.isArray(n)?n.length:0)),S=I(o.colWidthsMm,t,i),f=n=>n<=0?0:n>=i?S[S.length-1].pos+S[S.length-1].size:S[n].pos,h=I(o.rowHeightsMm,s,l),T=n=>n<=0?0:n>=l?h[h.length-1].pos+h[h.length-1].size:h[n].pos,d=new Set,L=(n,r)=>`${n}:${r}`,p=[],A=new Set,x=new Set,C=(n,r)=>`v${n}:${r}`,g=(n,r)=>`h${n}:${r}`;c.forEach((n,r)=>{if(!Array.isArray(n))return;let e=0;for(const a of n){for(;e<i&&d.has(L(r,e));)e++;if(e>=i)break;const w=Math.max(1,Math.min(a?.colSpan??1,i-e)),z=Math.max(1,a?.rowSpan??1),m=Math.min(l,r+z),E=Math.min(i,e+w);for(let u=r;u<m;u++)for(let _=e;_<E;_++)d.add(L(u,_));for(let u=e+1;u<E;u++)for(let _=r;_<m;_++)A.add(C(u,_));for(let u=r+1;u<m;u++)for(let _=e;_<E;_++)x.add(g(u,_));const F=f(e),D=T(r);p.push({ri:r,ci:e,cell:a??{},xMm:F,yMm:D,widthMm:f(E)-F,heightMm:T(m)-D}),e=E}});const P=[];for(let n=1;n<i;n++){let r=-1;for(let e=0;e<=l;e++){const a=e<l&&!A.has(C(n,e));a&&r<0&&(r=e),!a&&r>=0&&(P.push({kind:"v",pos:f(n),from:T(r),to:T(e)}),r=-1)}}for(let n=1;n<l;n++){let r=-1;for(let e=0;e<=i;e++){const a=e<i&&!x.has(g(n,e));a&&r<0&&(r=e),!a&&r>=0&&(P.push({kind:"h",pos:T(n),from:f(r),to:f(e)}),r=-1)}}return{columns:S,rows:h,cells:p,edges:P}}exports.CSS_DPI=96;exports.DEFAULT_BORDER_PT=.75;exports.DEFAULT_FONT_FAMILY=N;exports.DEFAULT_FONT_PT=10.5;exports.DEFAULT_STROKE_COLOR=R;exports.DEFAULT_TEXT_COLOR=O;exports.LINE_HEIGHT=1.35;exports.MM_PER_INCH=25.4;exports.PAPER_SIZES=k;exports.SCHEMA_VERSION_MACH=U;exports.mergeComponentStyles=Y;exports.mmToPx=v;exports.mmToPxFactor=M;exports.ptToPx=H;exports.pxToMm=B;exports.resolveBoxBorders=W;exports.resolveFontSize=G;exports.resolveGridLayout=X;exports.resolveLineHeight=K;exports.resolveStroke=$;exports.resolveTextColor=y;exports.round=b;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const Me=require("./component-tree-BjZIp6w9.cjs"),C=require("./grid-geometry-D8ReblRV.cjs"),D=require("./textwrap-OTOUMr4f.cjs"),k=require("./computed-4TnxzgIh.cjs"),E=require("./record-bindings-Ct1HkPrc.cjs"),Be=require("./charts-aCtoswXq.cjs"),Se=require("./matrix-0hywp0-F.cjs"),V=require("./template-serialization-CgqBo6s-.cjs"),j=require("./template-registry-CWnuGqyP.cjs"),Ht=require("./report-params-VTg8MoCp.cjs"),He=require("./param-validation-C-8sRJLq.cjs"),Xe=require("./number-format-CZ2T_5kF.cjs"),xe=require("./dataset-IrlXbUvh.cjs"),Gt=4096,Ge=128*1024;function Vt(e){const t=new Map;let r=0;return{measureMm(o,n){const a=JSON.stringify([o,n.fontSizePt,n.fontFamily,n.bold,n.italic,n.letterSpacingPt]),s=t.get(a);if(s!==void 0)return t.delete(a),t.set(a,s),s;const i=e.measureMm(o,n);if(Number.isFinite(i)&&a.length<=Ge){for(;t.size>=Gt||r+a.length>Ge;){const c=t.keys().next().value;r-=c.length,t.delete(c)}t.set(a,i),r+=a.length}return i}}}class G extends Error{constructor(t,r){super(`报表页数超出上限 ${t}(至少 ${r} 页)`),this.limit=t,this.actual=r,this.code="page-limit",this.name="PaginatePageLimitError"}}class q extends Error{constructor(t,r){super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`),this.limit=t,this.actual=r,this.code="cell-limit",this.name="PaginateCellLimitError"}}class U extends Error{constructor(t,r){super(`报表图表图元数量预计超出上限 ${t}(本次估算 ${r})`),this.limit=t,this.estimated=r,this.code="chart-component-limit",this.name="PaginateChartComponentLimitError"}}const Ee=5e4;function oe(e=Ee){if(!Number.isSafeInteger(e)||e<1||e>1e6)throw new RangeError("maxChartComponents 应为 1..1000000 的安全整数")}function _t(e,t,r){const o=e.chartBinding;if(e.kind!=="chart"||e.grid||e.imageData||e.binding||e.pageAnchor)throw new TypeError("绑定图表不能同时设置图片、网格、记录绑定或页眉页脚");const n=Object.prototype.hasOwnProperty.call(t,o.dataset)?t[o.dataset]:void 0;if(!Array.isArray(n))throw new TypeError(`图表数据集 ${o.dataset} 未提供`);return{...Se.createReportChartData(n,o,r),type:o.type,leftMm:e.leftMm,topMm:e.topMm,widthMm:e.widthMm,heightMm:e.heightMm,title:o.title,showValues:o.showValues}}function Wt(e,t,r=Ee){oe(r);let o=0;return Object.assign(a=>{if(!a.chartBinding)return[a];const s=_t(a,e,t),i=o+(s.categories.length?Be.chartComponentUpperBound(s):1);if(!Number.isSafeInteger(i))throw new RangeError("图表图元估算应为有限安全整数");if(i>r)throw new U(r,i);const c=s.categories.length?Be.createChartComponents(s):[{kind:"text",leftMm:a.leftMm,topMm:a.topMm,widthMm:a.widthMm,heightMm:a.heightMm,text:"—",style:{align:"center",verticalAlign:"middle",color:"#94a3b8",fontSize:10}}];return o+=c.length,c},{used:()=>o})}function zt(e,t){return{member:"body",subtotal:"subtotal",total:"grand-total"}[e?.rows.get(t)?.kind??"member"]}function Jt(e){const t=e.matrix;if(!t.hierarchy)return t;const r=new Map(e.columns.map(n=>[n.field,n.header])),o={sum:"求和",count:"计数",avg:"平均",min:"最小",max:"最大",weightedAvg:"加权平均"};return{...t,hierarchy:{...t.hierarchy,row:{...t.hierarchy.row,labels:t.hierarchy.row?.labels??t.rowFields.map(n=>r.get(n)??n)},column:{...t.hierarchy.column,labels:t.hierarchy.column?.labels??t.columnFields.map(n=>r.get(n)??n)}},measures:t.measures.map(n=>{const a=r.get(n.field)??r.get(n.valueField??n.field);return n.label===void 0&&a?{...n,label:`${a}(${o[n.op]})`}:n})}}function qt(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=Se.createMatrixTable(t,Jt(e)),o=r.columns.map(i=>({...i,widthMm:i.semanticRole==="dimension"?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:i.semanticRole==="dimension"?"center":"right"})),n={...e,columns:o,headerGrid:r.headerGrid,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};e.layout==="wide"&&(n.widthMm=o.reduce((i,c)=>i+c.widthMm,0));const a=r.metadata,s=a?{rows:new WeakMap(r.rows.map((i,c)=>[i,a.rows[c]])),header:{columns:a.columns,rowFields:a.rowFields,rowLabels:a.rowLabels,columnFields:a.columnFields,columnLabels:a.columnLabels}}:void 0;return{list:n,rows:r.rows,...s?{matrix:s}:{}}}function Ut(e,t){if(!e.matrix?.hierarchy||!e.headerGrid)return e.headerGrid;const r=e.paddingMm??1,o=e.headerGrid.cells.map(()=>e.rowHeightMm??0),n=e.columns.map(c=>c.widthMm),a=C.resolveGridLayout({...e.headerGrid,colWidthsMm:n},n.reduce((c,l)=>c+l,0),o.length),s=new WeakMap;for(const{cell:c,ci:l,ri:d,widthMm:f}of a.cells){const u={...E.resolveListHeaderStyle(e,e.columns[l]),...c.style},g=C.resolveFontSize(u).fontSizePt,v=(D.wrapText(c.text??"",Math.max(1,f-r*2),{fontSizePt:g,fontFamily:u.fontFamily,bold:u.bold,italic:u.italic,letterSpacingPt:u.letterSpacing},t).length*g*(u.lineHeight??C.LINE_HEIGHT)*25.4/72+r*2)/(c.rowSpan??1);for(let y=d;y<d+(c.rowSpan??1);y++)o[y]=Math.max(o[y]??0,v);s.set(c,u)}const i=e.headerGrid.cells.map(c=>c.map(l=>l?{...l,style:s.get(l)}:null));return{...e.headerGrid,cells:i,rowHeightsMm:o}}function Xt(e,t,r){const o=new Set,n=e.cells.map((a,s)=>{const i=[];let c=0;for(const l of a){for(;o.has(`${s}:${c}`);)c++;const d=l?.colSpan??1,f=l?.rowSpan??1;let u=0;for(let g=c;g<c+d;g++){t.has(g)&&u++;for(let m=s+1;m<s+f;m++)o.add(`${m}:${g}`)}u&&i.push(l?{...l,colSpan:u}:null),c+=d}return i});return{...e,cells:n,colWidthsMm:r}}function Ye(e){if(!e.columns.some(o=>o.hidden))return e;const t=new Set,r=e.columns.filter((o,n)=>o.hidden?!1:(t.add(n),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:Xt(e.headerGrid,t,r.map(o=>o.widthMm))}:{}}}function*Yt(e){const{page:t}=e;j.validateReportPageFlow(t.components,t.flow);let r=0,o=0;for(const n of j.reportFlowGroups(t.components,t.flow)){e.active();const a=n.band,s=n.components.some(d=>d.kind==="list"&&d.cardinality!=="record"),i=s?0:n.components.reduce((d,f)=>Math.max(d,f.topMm-a.topMm+(f.kind==="list"?e.height(f):f.heightMm)),a.heightMm);let c=Math.max(e.top(),o+a.topMm-r);if(!s&&i>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);!s&&c+i>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let l=c+i;for(const d of n.components){const f=c+d.topMm-a.topMm;d.kind==="list"?(yield*e.list(d,f,u=>{l=s?u:Math.max(l,u)}),e.active()):e.append({...d,topMm:f})}o=l,r=a.topMm+a.heightMm}}function Qt(e){return!!(e.computed?.length||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen||e.matrix||e.tree||e.detail||e.columns.some(t=>t.rules?.length||t.visibleWhen||t.visual))}function Re(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"?Qt(r):!!r.chartBinding))}const Zt=512,Ve=256*1024;function er(){const e=new Map;let t=0,r;return(o,n,a,s)=>{s!==r&&(e.clear(),t=0,r=s);const i=JSON.stringify([o,n,a.fontSizePt,a.fontFamily,a.bold,a.italic,a.letterSpacingPt]),c=e.get(i);if(c)return e.delete(i),e.set(i,c),c.lines.slice();const l=D.wrapText(o,n,a,s),d=i.length+l.reduce((f,u)=>f+u.length,0);if(d<=Ve){for(;e.size>=Zt||t+d>Ve;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(i,{lines:l.slice(),units:d}),t+=d}return l}}const Qe=1e4,_e=25e4;function Ce(e){if(e?.aborted)throw e.reason??new DOMException("标签生成已取消","AbortError")}function Ze(e,t,r){const o=typeof e.copies=="object"?E.readRecordScalar(t,e.copies.field,r):e.copies??1;if(typeof o!="number"||!Number.isSafeInteger(o)||o<1||o>1e3)throw new E.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}]`,"每条记录复制数必须是 1..1000 的数值型整数",r.rowIndex,typeof e.copies=="object"?e.copies.field:void 0);return o}function et(e,t,r){if(e.rowKey===void 0)return;const o=E.readRecordScalar(t,e.rowKey,r);if(typeof o=="string"&&o.trim()||typeof o=="number"&&Number.isFinite(o))return o;throw new E.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`,"业务主键必须是非空字符串或有限数字",r.rowIndex,e.rowKey)}function tr(e){const t=r=>1+(r.grid?.cells.reduce((o,n)=>o+1+n.length+n.reduce((a,s)=>a+(s?.children?.reduce((i,c)=>i+t(c),0)??0),0),0)??0);return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function rr(e,t,r){const o=e.repeat,n=Object.prototype.hasOwnProperty.call(t,o.dataset)?t[o.dataset]:void 0;if(!Array.isArray(n))throw new E.ReportBindingError(`$.datasets.${o.dataset}`,"逐记录标签数据集缺失,应提供对象数组(允许空数组)");const a=new Set,s=r.maxPages??Qe,i=tr(e);let c=0,l=0;for(const[d,f]of n.entries()){if(Ce(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new E.ReportBindingError(`$.datasets.${o.dataset}[${d}]`,"标签记录应为对象",d);const u={rowIndex:d,dataset:o.dataset},g=et(o,f,u);if(g!==void 0){const v=JSON.stringify([typeof g,g]);if(a.has(v))throw new E.ReportBindingError(`$.datasets.${o.dataset}[${d}].${o.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",d,o.rowKey);a.add(v)}const m=Ze(o,f,u);if(c+=m*e.pages.length,l+=m*i,c>s)throw new G(s,c);if(l>_e)throw new E.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${_e},请分批生成`,d)}return n}function or(e,t,r){if(!e.binding)return e;const{binding:o,...n}=e,a=E.resolveComponentBinding(o,t.row,t);if(e.kind==="image"){if(!a)return;if(!E.isLabelImageData(a))throw new E.ReportBindingError(`${r}.binding`,"图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换",t.rowIndex,o.field);return{...n,imageData:a}}return e.kind==="barcode"||e.kind==="qrcode"?(delete n.imageData,{...n,code:{...n.code,value:a},fallbackText:a}):(delete n.lines,delete n.richParagraphs,{...n,text:a})}function nr(e,t,r){if(e.kind!=="text"||e.grid||e.richParagraphs?.length)return e;const o=e.style??{},n=C.resolveFontSize(o).fontSizePt,a=e.text??e.lines?.join(`
|
|
2
|
-
`)??"";if(a.length>16384)throw new E.ReportBindingError(r,"标签文本超过 16384 字符预算,请缩小字段内容",t.rowIndex);const s=t.wrapText(a,e.widthMm,{fontSizePt:n,bold:o.bold,italic:o.italic,fontFamily:o.fontFamily,letterSpacingPt:o.letterSpacing},t.options.measurer??D.heuristicMeasurer),i=s.length*n*C.resolveLineHeight(o)*25.4/72;if(i>e.heightMm+.05)throw new E.ReportBindingError(r,`标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`,t.rowIndex,e.binding?.field);return{...e,lines:s}}function tt(e,t,r){Ce(t.options.signal);const o=or(e,t,r);if(!o)return;let n=o.grid;return n&&(n={...n,cells:n.cells.map((a,s)=>a.map((i,c)=>i?.children?.length?{...i,children:i.children.flatMap((l,d)=>{const f=tt(l,t,`${r}.grid.cells.${s}.${c}.children.${d}`);return f?[f]:[]})}:i))}),nr(n===o.grid?o:{...o,grid:n},t,r)}function ar(e,t,r,o,n,a){return{...e,components:e.components.flatMap((s,i)=>{const c=tt(s,r,`$.pages.${t}.components.${i}`);return c?[{...c,meta:{...c.meta,labelSource:{pageIndex:t,componentIndex:i}}}]:[]}),meta:{...e.meta,record:{dataset:r.dataset,rowIndex:r.rowIndex,...a===void 0?{}:{rowKey:a},copyIndex:o,copyCount:n,templatePageIndex:t}}}}function*sr(e,t,r){const o=[];if(j.validateTemplateRepeat(e,o),o.length)throw new E.ReportBindingError(o[0].path,o[0].message);if(!e.repeat){for(const[i,c]of e.pages.entries())yield{page:c,pageIndex:i};return}const n=e.repeat,a=rr(e,t,r),s=er();for(const[i,c]of a.entries()){const l={row:c,rowIndex:i,dataset:n.dataset,options:r,wrapText:s},d=Ze(n,c,l),f=et(n,c,l);for(let u=0;u<d;u++)for(const[g,m]of e.pages.entries())Ce(r.signal),yield{page:ar(m,g,l,u,d,f),pageIndex:g}}}function ir(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 ee(e,t){const r=t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm);return e.components.reduce((o,n)=>n.kind!=="list"&&n.pageAnchor==="footer"?Math.min(o,n.topMm):o,r)}function X(e){return e.components.reduce((t,r)=>r.kind!=="list"&&r.pageAnchor==="header"?Math.max(t,r.topMm+r.heightMm):t,0)}function rt(e,t){let r=e.textMetrics.get(t);if(!r){const o=C.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:o,fontFamily:t.fontFamily??C.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:o*(t.lineHeight??C.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function cr(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function Te(e,t,r=[],o){const n=e.fontSizePt??C.DEFAULT_FONT_PT,a=e.paddingMm??1,s=e.columns.map(h=>h.align??h.style?.align??e.align??"left"),i=e.columns.map((h,w)=>({...C.mergeComponentStyles({fontSize:n,verticalAlign:"middle"},h.style),align:s[w]==="auto"?"left":s[w]})),c=i.map((h,w)=>s[w]==="auto"?{left:h,center:{...h,align:"center"},right:{...h,align:"right"}}:void 0),l=e.columns.map((h,w)=>h.rules?.map(x=>{const $=c[w];if($)return{left:C.mergeComponentStyles($.left,x.style),center:C.mergeComponentStyles($.center,x.style),right:C.mergeComponentStyles($.right,x.style)};const T=C.mergeComponentStyles(i[w],x.style);return{left:T,center:T,right:T}})),d=e.columns.map(h=>E.resolveListHeaderStyle(e,h)),f=e.columns.map(h=>h.header);let u=e.rowHeightMm??0;for(let h=0;h<f.length;h++){const w=d[h],x=C.resolveFontSize(w).fontSizePt,$=D.wrapText(f[h],e.columns[h].widthMm-a*2,{fontSizePt:x,fontFamily:w.fontFamily??C.DEFAULT_FONT_FAMILY,italic:w.italic,bold:w.bold,letterSpacingPt:w.letterSpacing},t),T=x*(w.lineHeight??C.LINE_HEIGHT)*25.4/72;u=Math.max(u,Math.max($.length,1)*T+a*2)}const g=f.map((h,w)=>({text:h,style:d[w]})),m=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},v=e.columns.map(h=>h.widthMm),y=lr(Ut(e,t),v,{cells:[g],colWidthsMm:v,rowHeightsMm:[u],paddingMm:a});return{fontSizePt:n,paddingMm:a,visuals:V.createColumnVisualResolvers(e.columns,r,o),visibility:e.columns.map(h=>h.visibleWhen?k.compileReportPredicate(h.visibleWhen):void 0),ruleReaders:e.columns.map(h=>h.rules?.map(w=>k.compileReportPredicate(w.when))),cellStyles:i,autoStyles:c,ruleStyles:l,textMetrics:new WeakMap,numberFormats:e.columns.map(h=>E.toExcelNumberFormat(h.format)),derivedFields:new Set(e.computed?.map(h=>h.field)),borderStyle:m,headerHeightMm:y.rowHeightsMm.reduce((h,w)=>h+w,0),headerGrid:y,colWidthsMm:v,columns:e.columns}}function lr(e,t,r){if(!e)return r;if(!e.cells.length)throw new Error("自定义列表表头至少需要一行");const o=e.rowHeightsMm??e.cells.map(()=>r.rowHeightsMm[0]);if(o.length!==e.cells.length||o.some(n=>!Number.isFinite(n)||n<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:o}}function dr(e,t,r){const o=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:o&&(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 Y(e,t,r){const o=e.columns,n=e.tree?.rows.get(t);let a=e.rowHeightFloorMm;const s=new Array(o.length);for(let i=0;i<o.length;i++){const c=o[i],l=e.visibility[i]?.(t)!==!1,d=l?t[c.field]:null,f=e.autoStyles[i]?E.resolveListAutoAlignment(d,c.format,c.semanticRole):"left";let u=e.autoStyles[i]?.[f]??e.cellStyles[i];if(c.rules){for(let x=0;x<c.rules.length;x++)if(e.ruleReaders[i][x](t)){u=e.ruleStyles[i][x][f];break}}const g=c.format?E.formatValue(d,c.format):E.listCellText(d),m=ur(e,c,n);u=fr(e,c,u,n);const v=rt(e,u),y=D.wrapText(g,Math.max(1,c.widthMm-e.paddingMm*2-m),v.measureOptions,r);a=Math.max(a,y.length*v.lineMm+e.paddingMm*2);const h=cr(d),w={text:g,style:u};d!=null&&e.visuals[i]?.apply(w,t),h!==void 0&&(w.value=h),dr(w,c,e.numberFormats[i]),mr(w,c,e,n,m),e.derivedFields.has(c.field)&&(w.derived=!0,w.editable=!1),l||(w.editable=!1),s[i]=w}return{grid:{cells:[s],colWidthsMm:e.colWidthsMm,rowHeightsMm:[a],paddingMm:e.paddingMm},heightMm:a,...e.matrix?{meta:{matrix:{row:e.matrix.rows.get(t)}}}:{}}}function ur(e,t,r){return!r||t.field!==e.tree.list.tree.labelField?0:E.listTreeIndent(e.tree.list,t,r,e.paddingMm)}function fr(e,t,r,o){return!o||t.field!==e.tree.list.tree.labelField||r.align==="left"?r:{...r,align:"left"}}function mr(e,t,r,o,n=0){o&&(n&&(e.indentMm=n),E.applyListTreeMetadata(e,t,o,r.tree.list))}function ot(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*nt(e,t,r=0){const o=t[r];if(!o){for(const a of e)yield{kind:"row",row:a};return}const n=new Map;for(const a of e){const s=ot(a[o.field]),i=n.get(s);i?i.push(a):n.set(s,[a])}for(const a of n.values())yield{kind:"groupHeader",label:(o.headerTemplate??"{value}").replace(/\{value\}/g,E.listCellText(a[0][o.field])),firstRow:a[0],group:o,depth:r,rows:a},yield*nt(a,t,r+1),(o.subtotal?.length||o.aggregates?.length)&&(yield{kind:"subtotal",label:o.subtotalLabel??"小计",rows:a,group:o,depth:r}),yield{kind:"groupEnd",depth:r}}function at(e,t,r,o=[]){const n=[...r.filter(a=>!o.some(s=>s.field===a)).map(a=>({field:a,op:"sum"})),...o];return new Map(n.map(a=>{const s=e.find(c=>c.field===a.field)?.format??{kind:"number",thousands:!0},i=k.aggregateRows(t,{...a,field:a.valueField??a.field});return[a.field,{text:E.formatValue(i,s),...i===null?{}:{value:i},...typeof i=="number"?{numberFormat:E.toExcelNumberFormat(s)}:{}}]}))}function st(e,t){const r=e.findIndex(o=>t.includes(o.field));return r<0?1:r}function J(e,t,r,o,n,a){const s=[],i=Math.max(0,Math.min(a,e.columns.length)),c=C.mergeComponentStyles({fontSize:e.fontSizePt},n);i&&s.push({text:r,colSpan:i,style:{bold:!0,...c}});for(let u=i;u<e.columns.length;u++){const g=e.columns[u],m=o.get(g.field),v=e.autoStyles[u]?.[E.resolveListAutoAlignment(m?.value,g.format)]??e.cellStyles[u];s.push({...m,text:m?.text??"",style:C.mergeComponentStyles(v,n)})}const l={text:r,colSpan:e.columns.length,style:{bold:!0,...c}},d=i?[s]:[[l],s],f=d.map(u=>gr(e,u,t));return{grid:{cells:d,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((u,g)=>u+g,0)}}function gr(e,t,r){let o=e.rowHeightFloorMm,n=0;for(const a of t){let s=0;const i=n+(a.colSpan??1);for(;n<i;n++)s+=e.colWidthsMm[n]??0;const c=rt(e,a.style),l=D.wrapText(a.text??"",s-e.paddingMm*2,c.measureOptions,r);o=Math.max(o,l.length*c.lineMm+e.paddingMm*2)}return o}function hr(e,t,r){const{templatePage:o,current:n,warnings:a,nextId:s,pushCurrent:i}=r,c=()=>ee(o,n),l=Math.max(n.marginTopMm,X(o)),d=o.layout==="wide"?X(o):l,f={id:r.tableId,columnKeys:e.columns.map(p=>p.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}},u=new Map,g=new Map,m={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,...e.meta||t.matrix?{meta:{...e.meta,...t.matrix?{matrix:t.matrix.header}:{}}}:{}},v=p=>n.components.push({...m,topMm:p});if(r.flow&&e.header!==!1&&t.headerHeightMm>c()-l+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的表头高度超出单页可用范围`);let y=Math.max(r.startTop??e.topMm,l);e.header!==!1&&(v(y),y+=t.headerHeightMm+r.mmPerRow);function h(){const p=Math.max(r.flow||o.layout==="wide"?0:e.topMm,d);return(e.header!==!1&&e.headerEveryPage!==!1?p+t.headerHeightMm:d)+[...g.values()].reduce((S,I)=>S+I.heightMm,0)}function w(){const p=o.layout==="wide"?0:n.marginBottomMm;return Math.min(o.heightMm-p,ee(o,n))-h()}function x(p){if(y+p<=c())return;i(),n.components=[],n.heightMm=o.heightMm,o.layout==="wide"&&(n.marginTopMm=0,n.marginBottomMm=0);const b=Math.max(r.flow||o.layout==="wide"?0:e.topMm,d);e.header!==!1&&e.headerEveryPage!==!1?(v(b),y=b+t.headerHeightMm):y=d;for(const S of g.values())T(S,"listgr","group-header")}function $(p,b,S,I){const P=w();if(r.flow&&p.heightMm>P+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的单行高度超出单页可用范围`);p.heightMm>P&&a.push(`列表 ${e.id??e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${P.toFixed(2)}mm,预览与打印可能截断内容`),x(p.heightMm),T(p,b,S,I)}function T(p,b,S,I){const P=p.table?.id??f.id,F=S==="header"?-1:u.get(P)??0;S!=="header"&&u.set(P,F+p.grid.cells.length),n.components.push({kind:"rect",leftMm:e.leftMm,topMm:y,widthMm:e.widthMm,heightMm:p.heightMm,grid:p.grid,nid:s(b),table:{...f,...p.table,role:S,rowIndex:F,...I?{source:I}:{}},style:t.borderStyle,...e.meta||p.meta?{meta:{...e.meta,...p.meta}}:{}}),y+=p.heightMm}function N(p){p<=w()&&x(p)}return{keepTogether:N,placeGridRow:$,setGroupHeader:(p,b)=>{b?g.set(p,b):g.delete(p)},bottom:()=>y}}function pr(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 o=e.revisionField?t[e.revisionField]:void 0,n=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(o!==void 0&&typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o)))throw new Error("业务修订号应为字符串或有限数字");if(n!==void 0&&typeof n!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...o===void 0?{}:{revision:o},...n===void 0?{}:{sourceToken:n}}}function ne(e,t){const r=new Map;if(!e.rowKey)return r;const o=new Set;for(const n of t){const a=pr(e,n),s=JSON.stringify(a.rowKey);if(o.has(s))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);o.add(s),r.set(n,a)}return r}function wr(e,t,r,o,n){if(!e.grandTotal)return;const a=typeof e.grandTotal=="object"?e.grandTotal:void 0,s=ae(e)[0],i=a?.fields??s?.subtotal??[],c=a?.aggregates??s?.aggregates??[];if(i.length===0&&c.length===0){o.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const l=J(r,o.measurer,a?.label??"合计",at(e.columns,t,i,c),a?.style??{},st(e.columns,[...i,...c.map(d=>d.field)]));n.placeGridRow(l,"listgt","grand-total")}function K(e){if(e?.aborted){const t=new Error("报表排版已取消");throw t.name="AbortError",t}}function ae(e){const t=e.groups??(e.groupBy?[e.groupBy]:[]);if(t.length>16)throw new Error("列表最多支持 16 级分组");return t}function Pe(e){const t=Ye(e),r=t.columns.reduce((n,a)=>n+a.widthMm,0),o=r>t.widthMm?t.widthMm/r:1;return o===1?t:{...t,columns:t.columns.map(n=>({...n,widthMm:n.widthMm*o}))}}function yr(e,t,r){const o=e.detail;if(!o)return;const n=new Set;for(const l of t){const d=he(l[o.parentKey]);if(n.has(d))throw new Error("主从明细的主表关联键重复");n.add(d)}const a=r.datasets[o.dataset]??[],s=new Map,i=[];for(const l of a){const d=l[o.foreignKey];if(!it(d)&&o.unmatched==="ignore")continue;const f=he(d);if(!n.has(f)){if(o.unmatched!=="ignore")throw new Error(`明细数据集 ${o.dataset} 存在未关联的业务键`);continue}const u=s.get(f);u?u.push(l):s.set(f,[l]),i.push(l)}const c=Pe({...e,id:`${e.id??e.dataset}:detail`,dataset:o.dataset,rowKey:o.rowKey,revisionField:o.revisionField,sourceTokenField:o.sourceTokenField,computed:void 0,columns:o.columns,headerGrid:void 0,rowHeightMm:o.rowHeightMm??e.rowHeightMm,detail:void 0});return{list:c,inter:{...Te(c,r.measurer,i,r.signal),rowHeightFloorMm:c.rowHeightMm??0},rows:s,sources:ne(c,i)}}function it(e){return typeof e=="string"&&!!e.trim()||typeof e=="number"&&Number.isFinite(e)}function he(e){if(!it(e))throw new Error("主从关联键必须是非空字符串或有限数字");return ot(e)}function*br(e,t,r,o,n){if(!r)return;const a=r.rows.get(he(t[e.detail.parentKey]))??[];if(!a.length)return;const s={id:`${o.tableId}:detail`,columnKeys:r.list.columns.map(i=>i.field),title:e.detail.label};e.detail.label&&n.placeGridRow({...J(r.inter,o.measurer,e.detail.label,new Map,{},r.list.columns.length),table:s},"listdl","group-header"),e.detail.header!==!1&&n.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:s},"listdh","header"),yield*o.takePages();for(const i of a)K(o.signal),n.placeGridRow({...Y(r.inter,i,o.measurer),table:s},"listdr","body",r.sources.get(i)),yield*o.takePages()}function ct(e){if(e.matrix||e.detail||e.groups?.length||e.groupBy||e.rowVisibleWhen)throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");if(e.rowKey&&e.rowKey!==e.tree.idField)throw new Error("树形布局的 rowKey 应与 idField 一致");if(!e.columns.some(t=>t.field===e.tree.labelField&&!t.hidden))throw new Error("树形布局需要可见的标签列");V.validateTreeComputed(e.tree,e.computed)}function vr(e,t,r){ct(e);const o=V.createTreeTable(t,e.tree,{signal:r.signal,computed:e.computed?.length?{fields:e.computed,formula:r.formula}:void 0}),n={...e,rowKey:e.tree.idField},a=ne(n,o.entries.map(c=>c.original)),s=new Map,i=new WeakMap;for(const c of o.entries)s.set(c.row,a.get(c.original)),i.set(c.row,c);return{list:n,rows:o.rows,sources:s,treeRows:i,totalRows:o.leaves}}function Mr(e,t){if(e.cardinality==="record"){if(t.length>1)throw new Error(`单记录区域 ${e.id??e.dataset} 仅允许 0 或 1 行数据`);if(e.tree||e.matrix||e.detail||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen)throw new Error("单记录区域不能配置树、矩阵、主从、分组、总计或行过滤");if(!t.length)return{list:{...e,columns:e.columns.map(r=>({...r,editable:!1}))},rows:[{}],sources:new Map}}}function lt(e,t,r){const o=r.prepared.get(e);if(o)return o;const n=Mr(e,t);if(n)return r.prepared.set(e,n),n;if(e.tree){const c=vr(e,t,r);return r.prepared.set(e,c),c}let a=e.computed?.length?k.computeDataset(t,{fields:e.computed,signal:r.signal,formula:r.formula}).rows:t;const s=a===t?void 0:new Map(a.map((c,l)=>[c,t[l]]));e.rowVisibleWhen&&(a=a.filter(k.compileReportPredicate(e.rowVisibleWhen)));const i=qt(e,a);if(!e.matrix){const c=ne(e,s?a.map(l=>s.get(l)):a);i.sources=s?new Map(a.map(l=>[l,c.get(s.get(l))])):c}return r.prepared.set(e,i),i}function Sr(e,t,r,o){if(!o.flow)return;const{current:n,templatePage:a}=o,s=Math.max(n.marginTopMm,X(a)),i=Math.max(o.startTop??e.topMm,s),c=(e.header===!1?0:t.headerHeightMm)+(r[0]?Y(t,r[0],o.measurer).heightMm:0);i+c<=ee(a,n)+.001||i<=s+.001||(o.pushCurrent(),n.components=[],n.heightMm=a.heightMm,a.layout==="wide"&&(n.marginTopMm=0,n.marginBottomMm=0),o.startTop=Math.max(n.marginTopMm,X(a)))}function*xr(e,t,r){const o=lt(e,t,r),n=o.rows;e=o.list,e.layout==="wide"&&(r.current.widthMm=Math.max(r.current.widthMm,e.leftMm+e.widthMm+r.current.marginRightMm));const a=o.sources??ne(e,n),s=Pe(e),i=ae(s),c={...Te(s,r.measurer,n,r.signal),rowHeightFloorMm:s.rowHeightMm??0,matrix:o.matrix,...o.treeRows?{tree:{list:s,rows:o.treeRows}}:{}};Sr(s,c,n,r);const l=hr(s,c,r),d=yr(s,n,r);let f;for(const u of nt(n,i)){if(K(r.signal),u.kind==="row")l.placeGridRow(f??Y(c,u.row,r.measurer),"listr",zt(o.matrix,u.row),a.get(u.row)),f=void 0,yield*r.takePages(),yield*br(s,u.row,d,r,l);else if(u.kind==="groupHeader"){const g=J(c,r.measurer,u.label,new Map,u.group.headerStyle??{},s.columns.length);f??=Y(c,u.firstRow,r.measurer);const m=i.slice(u.depth+1).reduce((v,y)=>v+J(c,r.measurer,(y.headerTemplate??"{value}").replace(/\{value\}/g,E.listCellText(u.firstRow[y.field])),new Map,y.headerStyle??{},s.columns.length).heightMm,0);u.group.keepWithNext!==!1&&l.keepTogether(g.heightMm+m+f.heightMm),l.placeGridRow(g,"listg","group-header"),u.group.repeatHeader&&l.setGroupHeader(u.depth,g)}else if(u.kind==="subtotal"){const g=u.group.subtotal??[],m=u.group.aggregates??[],v=J(c,r.measurer,u.label,at(s.columns,u.rows,g,m),u.group.subtotalStyle??{},st(s.columns,[...g,...m.map(y=>y.field)]));l.placeGridRow(v,"listst","subtotal")}else l.setGroupHeader(u.depth);yield*r.takePages()}wr(s,o.totalRows??n,c,r,l),r.finished?.(l.bottom()),yield*r.takePages()}function se(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 ie(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(o=>({...o,...o.text===void 0?{}:{text:t(o.text)}}))}))}:{},...e.grid?{grid:{...e.grid,cells:e.grid.cells.map(r=>r.map(o=>o?{...o,...o.text===void 0?{}:{text:t(o.text)},...o.children?{children:o.children.map(n=>ie(n,t))}:{}}:null))}}:{}}}function Er(e){let t=!1;for(const r of e.pages)for(const o of r.components)se(o)&&ie(o,n=>(n.includes("{totalPages}")&&(t=!0),n));return t}function Rr(e,t,r,o,n,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,...e.meta?{meta:e.meta}:{}},i=c=>{const l=c.replace(/\{page\}/g,String(o));return a===void 0?l:l.replace(/\{totalPages\}/g,String(a))};for(const c of r)s.components.push(ie(c,i));if(e.layout==="wide"){const c=s.components.reduce((l,d)=>Math.max(l,d.topMm+d.heightMm),0);s.marginBottomMm=n?e.marginBottomMm??0:0,s.pageHeightMm=Math.max(1,c+s.marginBottomMm)}return s}function ke(e){return e.cells.reduce((t,r)=>t+r.reduce((o,n)=>o+(n?1+(n.children?.reduce((a,s)=>a+dt(s),0)??0):0),0),0)}function dt(e){return e.grid?ke(e.grid):0}function ce(e){for(const t of["maxPages","maxCells","knownTotalPages"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<1))throw new RangeError(`${t} 应为正安全整数`);oe(e.maxChartComponents)}function Cr(e,t){const r=lt(e,t.datasets[e.dataset]??[],t),o=Pe(r.list),n={...Te(o,t.measurer,r.rows,t.signal),rowHeightFloorMm:o.rowHeightMm??0};return(o.header===!1?0:n.headerHeightMm)+r.rows.reduce((a,s)=>a+Y(n,s,t.measurer).heightMm,0)}function*Tr(e){const{templatePage:t,current:r}=e,o=new Map(t.components.map((a,s)=>[a,s])),n=(a,s,i)=>{const c=e.datasets[a.dataset];return Array.isArray(c)||e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id??""} 输出为空`),xr(a,Array.isArray(c)?c:[],{...e,tableId:`${e.tableId}:${o.get(a)}`,startTop:s,finished:i,flow:!!t.flow})};if(t.flow){yield*Yt({page:t,active:()=>K(e.signal),top:()=>Math.max(r.marginTopMm,X(t)),bottom:()=>ee(t,r),append:a=>{r.components.push(...e.resolveChart(a))},nextPage:()=>{e.pushCurrent(),r.components=[],r.heightMm=t.heightMm,t.layout==="wide"&&(r.marginTopMm=0,r.marginBottomMm=0)},takePages:e.takePages,height:a=>Cr(a,e),list:n});return}for(const a of t.components)se(a)||(a.kind==="list"?yield*n(a):r.components.push(...e.resolveChart(a)))}function*Q(e,t,r,o,n,a=new WeakMap,s){let i=0,c=0,l=0;const d=Vt(r.measurer??D.heuristicMeasurer),f=Wt(t,r.signal,r.maxChartComponents),u=g=>`${g}_${(++i).toString(36)}`;for(const{pageIndex:g,page:m}of sr(e,t,r)){K(r.signal);const v=ir(m),y=m.components.filter(se);let h=[];const w=($=!1)=>{if(K(r.signal),r.maxPages!==void 0&&c>=r.maxPages)throw new G(r.maxPages,c+1);if(r.maxCells!==void 0&&(l+=[...v.components,...y].reduce((T,N)=>T+dt(N),0),l>r.maxCells))throw new q(r.maxCells,l);h.push(Rr(m,v,y,++c,$,n))},x=()=>{const $=h;return h=[],$};yield*Tr({templatePage:m,current:v,warnings:o,nextId:u,pushCurrent:w,takePages:x,datasets:t,resolveChart:f,signal:r.signal,formula:r.formula,prepared:a,measurer:d,mmPerRow:r.mmPerRow??0,tableId:`table:${g}`}),w(!0),yield*x()}s&&(s.chartComponents=f.used())}function Pr(e,t,r={}){ce(r);let o=0;for(const n of Q(e,t,{...r,onWarning:void 0},[]))o++;return o}function*kr(e,t,r={}){yield*Ir(e,t,r)}function*Ir(e,t,r,o){ce(r);const n=Er(e),a=new WeakMap;let s=r.knownTotalPages;if(n&&s===void 0){s=0;for(const l of Q(e,t,r,[],void 0,a))s++}const i=[];let c=0;for(const l of Q(e,t,r,i,s,a,o)){for(;c<i.length;c++)r.onWarning?.(i[c]);yield l}}function Ie(e,t,r={}){const o=typeof r=="number"?{mmPerRow:r}:r;ce(o);const n=[],a={chartComponents:0},s=[...Q(e,t,o,n,o.knownTotalPages,void 0,a)];return ft(e,o,s,n,a)}async function ut(e,t,r={}){ce(r),K(r.signal);const o=[],n=[],a={chartComponents:0};let s=performance.now(),i=0;for(const c of Q(e,t,r,o,r.knownTotalPages,void 0,a))n.push(c),(++i>=8||performance.now()-s>=8)&&(await new Promise(l=>setTimeout(l,0)),K(r.signal),s=performance.now(),i=0);return K(r.signal),ft(e,r,n,o,a)}function ft(e,t,r,o,n){for(const a of r)a.components=a.components.map(s=>se(s)?ie(s,i=>i.replace(/\{totalPages\}/g,String(r.length))):s);return o.forEach(a=>t.onWarning?.(a)),{plan:{schemaVersion:Me.RENDER_PLAN_SCHEMA_VERSION,...Re(e)?{requiresRecalculation:!0}:{},pages:r},warnings:o,...n}}function $r(e){const t=e.columns.find(a=>!a.hidden)?.field;if(!t)return{groups:0,total:0};const r=ae(e),o=(a=[],s=[])=>a.includes(t)||s.some(i=>i.field===t),n=typeof e.grandTotal=="object"?e.grandTotal:void 0;return{groups:r.filter(a=>o(a.subtotal,a.aggregates)).length,total:Number(o(n?.fields??r[0]?.subtotal,n?.aggregates??r[0]?.aggregates))}}function Fr(e,t,r){ct(e);const o=V.flattenTreeInput(t[e.dataset]??[],e.tree,r),n=e.columns.filter(s=>!s.hidden).length,a=e.header===!1?0:e.headerGrid?ke(e.headerGrid):n;return o.length*n+a+ +!!e.grandTotal*2*n}function Or(e,t,r={}){if(e.tree)return Fr(e,t,r.signal);if(e.matrix){let c=t[e.dataset]??[];e.computed?.length&&(c=k.computeDataset(c,{fields:e.computed,...r}).rows),e.rowVisibleWhen&&(c=c.filter(k.compileReportPredicate(e.rowVisibleWhen)));const l=Se.estimateMatrixTable(c,e.matrix);return l.cells+(e.header===!1?0:l.columnCount*(e.matrix.hierarchy?e.matrix.columnFields.length+1:1))}const o=t[e.dataset]?.length??0,n=e.columns.filter(c=>!c.hidden).length,a=ae(e).length,s=$r(e);let i=(o*(1+2*a+s.groups)+ +!!e.grandTotal*(1+s.total))*n;if(i+=e.header===!1?0:e.headerGrid?ke(e.headerGrid):n,e.cardinality==="record"&&o===0&&(i+=n),e.detail){const c=t[e.detail.dataset]?.length??0,l=e.detail.columns.filter(d=>!d.hidden).length;i+=(c+o*(+(e.detail.header!==!1)+ +!!e.detail.label))*l}if(!Number.isSafeInteger(i))throw new RangeError("报表单元格估算超出安全整数预算");return i}class mt extends Error{constructor(t){super(t.map(r=>r.message).join(";")),this.issues=t,this.name="ReportValidationError"}}function We(e,t,r){if(!Number.isSafeInteger(e)||e<1||e>r)throw new Error(`校验 ${t} 超出预算`);return e}function Ar(e){if(e.aggregates&&e.scope!=="dataset")throw new Error("仅数据集规则允许汇总");if(e.aggregates&&(!Array.isArray(e.aggregates)||e.aggregates.length>64))throw new Error("校验汇总最多 64 项");const t=new Set;for(const r of e.aggregates??[]){if(k.computationFieldName(r.field),t.has(r.field))throw new Error("校验汇总字段重复");t.add(r.field),r.valueField!==void 0&&k.computationFieldName(r.valueField),r.weightField!==void 0&&k.computationFieldName(r.weightField),k.aggregateRows([],{...r,field:r.valueField??r.field})}}function gt(e){if(!Array.isArray(e)||e.length>256||Object.keys(e).length!==e.length)throw new Error("校验规则最多 256 条且不允许空位");const t=new Set;return e.map(r=>{if(!r||typeof r!="object")throw new Error("校验规则应为声明式对象");if(k.computationFieldName(r.id),t.has(r.id))throw new Error("校验规则 id 重复");if(t.add(r.id),r.field!==void 0&&k.computationFieldName(r.field),r.dataset!==void 0&&k.computationFieldName(r.dataset),typeof r.message!="string"||!r.message.trim()||r.message.length>2048)throw new Error("校验规则需要有界提示文案");if(r.severity!==void 0&&!["error","warning"].includes(r.severity))throw new Error("未知校验严重程度");if(r.scope!==void 0&&!["row","dataset"].includes(r.scope))throw new Error("未知校验范围");Ar(r);const o={nodes:0},n=k.compileReportPredicate(r.assert,o),a=r.when?k.compileReportPredicate(r.when,o):void 0;return{rule:r,assert:n,when:a,checks:o.nodes}})}function ze(e){if(e?.aborted){const t=new Error("报表校验已取消");throw t.name="AbortError",t}}function Nr(e,t,r,o){const n=o&&Object.prototype.hasOwnProperty.call(t,o)?t[o]:void 0;if(n!==void 0&&typeof n!="string"&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("校验定位需要稳定的文本或数值业务键");return{ruleId:e.id,rowIndex:r,...n===void 0?{}:{rowKey:n},field:e.field,severity:e.severity??"error",message:e.message}}function Lr(e,t){const r=t.computed?.length?{fields:t.computed,formula:t.formula,signal:t.signal}:void 0;if(t.tree){const n=V.createTreeTable(e,t.tree,{signal:t.signal,computed:r});if(n.rows.length>1e5)throw new Error("校验展开后数据最多 100000 行");return{rows:n.rows,summaryRows:n.leaves,rowKey:t.tree.idField}}const o=r?k.computeDataset(e,r).rows:e;return{rows:o,summaryRows:o,rowKey:t.rowKey}}function Kr(e,t){const r=new Set;e.forEach(o=>{if(!o||typeof o!="object"||Array.isArray(o))throw new Error("校验数据行应为对象");if(!t)return;const n=Object.prototype.hasOwnProperty.call(o,t)?o[t]:void 0;if(!(typeof n=="string"&&n.trim())&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("校验定位需要稳定业务键");if(r.has(n))throw new Error("校验业务键重复");r.add(n)})}function jr(e,t){return ht(e,t,{checks:0})}function ht(e,t,r){if(!Array.isArray(e)||e.length>1e5)throw new Error("校验数据最多 100000 行");ze(t.signal);const o=We(t.maxChecks??2e6,"maxChecks",1e7),n=We(t.maxIssues??1e3,"maxIssues",1e4);t.rowKey!==void 0&&k.computationFieldName(t.rowKey);const a=Lr(e,t),{rows:s,summaryRows:i,rowKey:c}=a;Kr(s,c);const l=gt(t.rules),d=l.reduce((u,g)=>u+(g.rule.scope==="dataset"?g.checks+i.length*(g.rule.aggregates?.length??0):s.length*g.checks),0);if(r.checks+=d,r.checks>o)throw new Error("整批校验超出 maxChecks 预算");const f=[];for(const u of l)(u.rule.scope==="dataset"?[Object.fromEntries((u.rule.aggregates??[]).map(m=>[m.field,k.aggregateRows(i,{...m,field:m.valueField??m.field})]))]:s).forEach((m,v)=>{if(ze(t.signal),!m||typeof m!="object"||Array.isArray(m))throw new Error("校验数据行应为对象");if(!(u.when&&!u.when(m)||u.assert(m))){if(f.length>=n)throw new Error("校验问题超出 maxIssues 预算,请缩小范围");f.push(Nr(u.rule,m,u.rule.scope==="dataset"?void 0:v,u.rule.scope==="dataset"?void 0:c))}});return f}function pt(e,t="allow"){if(!["allow","block"].includes(t))throw new Error("未知校验警告策略");if(!Array.isArray(e)||e.length>1e4||e.some(r=>!r||!["error","warning"].includes(r.severity)||typeof r.ruleId!="string"||!r.ruleId.trim()||typeof r.message!="string"||!r.message.trim()))throw new Error("校验问题结构无效");if(e.some(r=>r.severity==="error"||t==="block"))throw new mt(e)}function Je(e,t,r){const o=e.get(t);if(o&&JSON.stringify(o)!==JSON.stringify(r))throw new Error("同一数据集的校验计算/业务键存在歧义,请统一绑定");e.set(t,r)}function Dr(e,t,r,o=[]){gt(t.rules);const n=[],a={checks:0};for(const[i,c]of e.entries()){const l=new Map;for(const d of c.template.pages)for(const f of d.components)f.kind==="list"&&(Je(l,f.dataset,{rowKey:f.tree?.idField??f.rowKey,computed:f.computed,tree:f.tree}),f.detail&&Je(l,f.detail.dataset,{rowKey:f.detail.rowKey}));for(const[d,f]of l){const u=t.rules.filter(g=>!g.dataset||g.dataset===d);if(u.length&&(n.push(...ht(c.datasets[d]??[],{...t,rules:u,...f,formula:o[i],signal:r},a).map(g=>({...g,dataset:d,sourceScope:c.sourceScope}))),n.length>(t.maxIssues??1e3)))throw new Error("整批候选校验问题超出 maxIssues 预算")}}const s=new Set(e.flatMap(i=>i.template.pages.flatMap(c=>c.components.flatMap(l=>l.kind==="list"?[l.dataset,...l.detail?[l.detail.dataset]:[]]:[]))));if(t.rules.some(i=>i.dataset&&!s.has(i.dataset)))throw new Error("校验目标数据集不存在");return n}function wt(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function yt(e,t,r){const o=e.grid;if(!o)return null;const n=o.cells[t];if(!n)return null;const s=C.resolveGridLayout(o,e.widthMm,e.heightMm).cells.filter(c=>c.ri===t).findIndex(c=>c.ci===r),i=n[s];return i?{cell:i,sourceColumnIndex:s}:null}function Br(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function Hr(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 Gr(e,t){if(e.derived)return"derived";if(e.editable===!1)return"cell";if(e.formula!==void 0)return"formula";if(e.children?.length||e.richParagraphs?.length)return"complex";if(t.table&&t.table.role!=="body"&&e.editable!==!0)return"structure"}function Vr(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 _r(e,t,r){if(e.derived)return;if(e.source)return{...e.source};const o=t.table?.source,n=t.table?.columnKeys[r.columnIndex];if(!(!o||o.rowKey===void 0||n===void 0))return{...o,rowKey:o.rowKey,field:n}}function bt(e,t,r){const o=Br(r),n=Gr(r,e);return{address:{...t},cell:r,component:e,value:o,valueType:Hr(r,o),table:Vr(e,t),source:_r(r,e,t),editable:n===void 0,readOnlyReason:n}}function le(e,t){if(!wt(t))return null;const r=e.pages[t.pageIndex]?.components[t.componentIndex];if(!r)return null;const o=yt(r,t.rowIndex,t.columnIndex);return o?bt(r,t,o.cell):null}function B(e){const t=new Map;return r=>{if(!wt(r))return null;const o=e.pages[r.pageIndex]?.components[r.componentIndex];if(!o?.grid)return null;let n=t.get(o);if(!n){const s=new Map;n=new Map;for(const i of C.resolveGridLayout(o.grid,o.widthMm,o.heightMm).cells){const c=s.get(i.ri)??0;s.set(i.ri,c+1);const l=o.grid.cells[i.ri]?.[c];l&&n.set(`${i.ri}:${i.ci}`,l)}t.set(o,n)}const a=n.get(`${r.rowIndex}:${r.columnIndex}`);return a?bt(o,r,a):null}}class M extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function Wr(e,t){let r=e.trim();const o=t&&r.endsWith("%");if(o&&(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 M("number");return Number(r)/(o?100:1)}function zr(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new M("number");const r=typeof e=="number"?e:Wr(e,Xe.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new M("number");return r}function Jr(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 M("boolean")}function $e(e,t){return e.valueType==="number"?zr(t,e):e.valueType==="boolean"?Jr(t):t===null?null:String(t)}function qr(e,t){const r=t.cell.text,n=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(a=>a.includes(r??""));return n?n[e?0:1]:String(e)}function _(e,t){return t===null?"":typeof t=="boolean"?qr(t,e):typeof t=="number"?Xe.formatExcelNumber(t,e.cell.numberFormat):String(t)}function Ur(e,t,r){const o=le(e,t);if(!o)throw new M("missing");return W(o,r)}function W(e,t){if(!e.editable)throw new M("readonly");const r=$e(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:r,text:_(e,r)}}function Xr(e,t){const r=e.table,o=t.table;return!r||!o||r.columnKey===void 0?!1:r.id===o.id&&r.rowIndex===o.rowIndex&&r.role===o.role&&r.columnKey===o.columnKey}function vt(e,t,r){const o=e.grid,{rowIndex:n,columnIndex:a}=t.address,s=yt(e,n,a),i=[...o.cells],c=[...i[n]],l=_(t,r.value),d={...s.cell,value:r.value,text:l,rawText:l};return c[s.sourceColumnIndex]=d,i[n]=c,{...e,grid:{...o,cells:i}}}function Yr(e,t){const r=e.table?.columnKeys,o=t.table?.columnKey;return r&&o!==void 0?r.flatMap((n,a)=>n===o?[a]:[]):[]}function Qr(e,t,r,o,n,a){const s=t.table,i=n.table;if(!s||!i||s.id!==i.id||s.role!==i.role||!t.grid)return t;const c=i.rowIndex-s.rowIndex;if(c<0||c>=t.grid.cells.length)return t;let l=t;for(const d of Yr(t,n)){const f=le(e,{pageIndex:r,componentIndex:o,rowIndex:c,columnIndex:d});f?.editable&&Xr(n,f)&&(l=vt(l,f,a))}return l}function Zr(e,t,r,o,n,a){const s=n.address;return n.table?.columnKey!==void 0?Qr(e,t,r,o,n,a):s.pageIndex===r&&s.componentIndex===o?vt(t,n,a):t}function de(e,t){const r=t.source;if(!r)return!1;const o=e.source;return!o||["sourceScope","datasetId","rowKey","field","revision","sourceToken"].some(n=>!Object.is(o[n],r[n]))}function eo(e,t){const r=le(e,t.address);if(!r)throw new M("missing");if(!r.editable)throw new M("readonly");if(de(r,t))throw new M("conflict");if(!Object.is(r.value,t.previousValue)||(r.cell.text??"")!==t.previousText)throw new M("conflict");const o=$e(r,t.value),n={...t,value:o,text:_(r,o)};if(Object.is(o,r.value)&&n.text===r.cell.text)return e;const a=e.pages.map((s,i)=>{const c=s.components.map((l,d)=>Zr(e,l,i,d,r,n));return c.every((l,d)=>l===s.components[d])?s:{...s,components:c}});return{...e,pages:a}}function Mt(e){const t=[];for(const r of e.template.pages)for(const o of r.components)o.kind==="list"&&(t.push(o.tree?{...o,rowKey:o.tree.idField}:o),o.detail&&t.push({...o.detail,relation:{detail:o.detail,parentRows:e.datasets[o.dataset]??[]}}));return t}function z(e){return JSON.stringify([e.sourceScope,e.datasetId])}function qe(e){return JSON.stringify([e.sourceScope,e.datasetId,e.rowKey])}function St(e){const t=new Map,r=new Set;return e.forEach((o,n)=>{for(const a of Mt(o)){if(!a.rowKey)continue;const s=a.relation,i=s?new Set(s.parentRows.map(c=>JSON.stringify(c[s.detail.parentKey]))):void 0;(o.datasets[a.dataset]??[]).forEach((c,l)=>{if(s&&!i.has(JSON.stringify(c[s.detail.foreignKey])))return;const d=c[a.rowKey];if(typeof d!="string"&&typeof d!="number")return;const f=`${n}:${a.dataset}:${l}:${a.rowKey}`;if(r.has(f))return;r.add(f);const u=qe({sourceScope:o.sourceScope,datasetId:a.dataset,rowKey:d}),g=t.get(u)??[];g.push({partIndex:n,dataset:a.dataset,rowIndex:l,row:c,binding:a}),t.set(u,g)})}}),o=>{const n=t.get(qe(o));if(!n?.length)throw new M("missing");if(new Set(n.map(a=>`${a.partIndex}:${a.dataset}`)).size!==n.length)throw new M("conflict");return n}}function xt(e,t){const r=e.map(n=>({...n,datasets:{...n.datasets}})),o=new Set;for(const{row:n,field:a,value:s}of t){const i=r[n.partIndex],c=JSON.stringify([n.partIndex,n.dataset]);o.has(c)||(i.datasets[n.dataset]=[...i.datasets[n.dataset]],o.add(c)),i.datasets[n.dataset][n.rowIndex]={...i.datasets[n.dataset][n.rowIndex],[a]:s}}for(const n of o){const[a,s]=JSON.parse(n);k.forkComputedDataset(e[a].datasets[s],r[a].datasets[s])}return r}function to(e,t,r){const o=[],n=new Set;return e.forEach((a,s)=>{for(const i of Mt(a))t.has(z({sourceScope:a.sourceScope,datasetId:i.dataset}))&&(a.datasets[i.dataset]??[]).forEach((c,l)=>{const d={partIndex:s,dataset:i.dataset,rowIndex:l,row:c,binding:i};for(const[f,u]of[[i.revisionField,r.revision],[i.sourceTokenField,r.sourceToken]]){if(!f||u===void 0)continue;const g=`${s}:${i.dataset}:${l}:${f}`;n.has(g)||(n.add(g),o.push({row:d,field:f,value:u}))}})}),o}function Et(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const o=new Set(t.edits.flatMap(n=>n.source?[z(n.source)]:[]));return Fe(e,new Map([...o].map(n=>[n,r])))}function Fe(e,t){if(!t.size)return e;function r(a){const s=a.datasetId&&t.get(z({...a,datasetId:a.datasetId}));return!s||(s.revision===void 0||Object.is(s.revision,a.revision))&&(s.sourceToken===void 0||s.sourceToken===a.sourceToken)?a:{...a,...s.revision!==void 0?{revision:s.revision}:{},...s.sourceToken!==void 0?{sourceToken:s.sourceToken}:{}}}function o(a){const s=a.map(i=>{const c=i.table?.source?r(i.table.source):void 0,l=i.table&&c!==i.table.source?{...i.table,source:c}:i.table,d=i.grid?.cells.map(u=>{const g=u.map(m=>{if(!m)return m;const v=m.source?r(m.source):void 0,y=m.children?o(m.children):void 0;return v===m.source&&y===m.children?m:{...m,source:v,children:y}});return g.some((m,v)=>m!==u[v])?g:u}),f=i.grid&&d?.some((u,g)=>u!==i.grid.cells[g])?{...i.grid,cells:d}:i.grid;return l!==i.table||f!==i.grid?{...i,table:l,grid:f}:i});return s.some((i,c)=>i!==a[c])?s:a}const n=e.pages.map(a=>{const s=o(a.components);return s!==a.components?{...a,components:s}:a});return n.some((a,s)=>a!==e.pages[s])?{...e,pages:n}:e}function ro(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function Ue(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):ro(e.address)}function oo(e,t){if(!t.length)return e;const r=new Map(t.map(c=>[Ue(c),c])),o=new Set(t.flatMap(c=>c.table?[c.table.id]:[])),n=new Set(t.map(c=>`${c.address.pageIndex}:${c.address.componentIndex}`)),a=B(e);function s(c,l,d){const f=c.grid;if(!f||!n.has(`${l}:${d}`)&&!o.has(c.table?.id??""))return c;const u=new Map,g=new Map;for(const m of C.resolveGridLayout(f,c.widthMm,c.heightMm).cells){const v=g.get(m.ri)??0;g.set(m.ri,v+1);const y=a({pageIndex:l,componentIndex:d,rowIndex:m.ri,columnIndex:m.ci}),h=y&&r.get(Ue(y));if(!h||!y.editable)continue;const w=u.get(m.ri)??[...f.cells[m.ri]],x=_(y,h.value);Object.is(y.value,h.value)&&x===y.cell.text||(w[v]={...m.cell,value:h.value,text:x,rawText:x},u.set(m.ri,w))}return u.size?{...c,grid:{...f,cells:f.cells.map((m,v)=>u.get(v)??m)}}:c}const i=e.pages.map((c,l)=>{const d=c.components.map((f,u)=>s(f,l,u));return d.every((f,u)=>f===c.components[u])?c:{...c,components:d}});return i.every((c,l)=>c===e.pages[l])?e:{...e,pages:i}}function A(e){const t=e.source;if(t)return JSON.stringify([t.sourceScope,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 o=e.address;return JSON.stringify([o.pageIndex,o.componentIndex,o.rowIndex,o.columnIndex])}function no(e,t,r){if(typeof r!="string"||!r.trim()||!Array.isArray(t))throw new M("missing");if(t.length>1e4)throw new M("limit");const o=new Set,n=B(e),a=t.map(({address:s,value:i})=>{const c=n(s);if(!c)throw new M("missing");const l=W(c,i),d=A(l);if(o.has(d))throw new M("duplicate");return o.add(d),l});return{requestId:r,edits:a}}function ao(e,t){if(t.edits.length>1e4)throw new M("limit");const r=B(e),o=new Set,n=t.edits.map(a=>{const s=r(a.address);if(!s)throw new M("missing");const i=A(a);if(o.has(i))throw new M("duplicate");if(o.add(i),de(s,a)||!Object.is(s.value,a.previousValue)||(s.cell.text??"")!==a.previousText)throw new M("conflict");return W(s,a.value)});return oo(e,n)}function so(e){const t=new Map;for(const r of e){const o=A(r),n=t.get(o),a=n?{...r,previousValue:n.previousValue,previousText:n.previousText}:{...r};Object.is(a.previousValue,a.value)?t.delete(o):t.set(o,a)}return[...t.values()]}function Rt(e){const t=new Map,r=B(e);return e.pages.forEach((o,n)=>o.components.forEach((a,s)=>{if(!(!a.grid||a.table?.role!=="body"))for(let i=0;i<a.grid.cells.length;i++)for(let c=0;c<a.table.columnKeys.length;c++){const l=r({pageIndex:n,componentIndex:s,rowIndex:i,columnIndex:c});l?.source&&l.editable&&t.set(A(l),l)}})),t}function io(e,t,r){const o=Rt(e),n=B(e);return t.map(a=>{const s=a.source?o.get(A(a)):n(a.address);if(!s||A(s)!==A(a))throw new M("missing");return{address:{...s.address},value:a[r]}})}function Ct(e,t){if(++e.nodes>1e6||t>128)throw new M("limit")}function te(e,t){const r=Object.getOwnPropertyDescriptor(e,t);if(!r||r.get||r.set)throw new M("conflict");return r.value}function Oe(e){if(Object.getOwnPropertyDescriptor(e,"toJSON"))throw new M("conflict");const t=Object.getPrototypeOf(e);if(Array.isArray(e)&&(t!==Array.prototype||Object.keys(e).length!==e.length))throw new M("conflict");if(!(e instanceof Date)&&!Array.isArray(e)&&t!==Object.prototype&&t!==null)throw new M("conflict");for(const r of Reflect.ownKeys(e))if(!(Array.isArray(e)&&r==="length")){if(typeof r=="symbol"||!Object.getOwnPropertyDescriptor(e,r)?.enumerable)throw new M("conflict");if(e instanceof Date||Array.isArray(e)&&!/^(0|[1-9]\d*)$/.test(r))throw new M("conflict")}}function Tt(e,t,r,o,n){if(Ct(o,n),typeof e=="function"||typeof e=="symbol")throw new M("conflict");if(e===null||typeof e!="object")return;if(Oe(e),r.has(e))throw new M("conflict");r.add(e);const a=Object.keys(e),s=a.map(i=>te(e,i));t.push({object:e,prototype:Object.getPrototypeOf(e),keys:a,values:s,...e instanceof Date?{date:Date.prototype.getTime.call(e)}:{},...Array.isArray(e)?{length:e.length}:{}});for(const i of s)Tt(i,t,r,o,n+1);r.delete(e)}function co(e){const{object:t,keys:r,values:o}=e;if(Oe(t),Object.getPrototypeOf(t)!==e.prototype||Object.getOwnPropertyDescriptor(t,"toJSON")||e.date!==void 0&&!Object.is(Date.prototype.getTime.call(t),e.date)||e.length!==void 0&&t.length!==e.length)return!1;const n=Object.keys(t);return n.length===r.length&&r.every((a,s)=>n[s]===a&&Object.is(te(t,a),o[s]))}function lo(e){const t=[];return Tt(e,t,new Set,{nodes:0},0),()=>{try{return t.every(co)}catch{return!1}}}function re(e,t,r,o=!1){if(Ct(t,r),o){if(typeof e=="function"||typeof e=="symbol")throw new M("conflict");e!==null&&typeof e=="object"&&Oe(e)}if(e===null||typeof e!="object")return e;if(e instanceof Date)return new Date(Date.prototype.getTime.call(e));if(Array.isArray(e)){const n=[];for(let a=0;a<e.length;a++)n[a]=re(te(e,String(a)),t,r+1,o);return n}return Object.fromEntries(Object.keys(e).map(n=>[n,re(te(e,n),t,r+1,o)]))}function uo(e){return re(e,{nodes:0},0,!0)}function fo(e){const t=re(e,{nodes:0},0);for(const r of t)for(const o of Object.values(r.datasets))k.registerComputedDataset(o);return t}async function mo(e,t,r={}){return(await Pt(e,t,r)).plan}async function Pt(e,t,r={}){return ut(e,t,{...r,knownTotalPages:void 0})}const pe=new WeakMap;function go(e){return pe.get(e)}function Z(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function kt(e,t){return e[t]===void 0?"":e[t]}function ho(e,t){if(t.edits.length>1e4)throw new M("limit");const r=B(e),o=new Set,n=[],a=t.edits.map(s=>{const i=r(s.address);if(!i?.source)throw new M("missing");const c=A(s);if(o.has(c))throw new M("duplicate");if(o.add(c),de(i,s)||!Object.is(i.value,s.previousValue)||(i.cell.text??"")!==s.previousText)throw new M("conflict");return n.push(i),W(i,s.value)});return{batch:{requestId:t.requestId,edits:a},contexts:n}}function po(e,t){const r=St(e);return t.flatMap(o=>{if(!o.source)throw new M("missing");return r(o.source).map(n=>{if(!Object.is(kt(n.row,o.source.field),o.previousValue))throw new M("conflict");if(n.binding.rowKey===o.source.field)throw new M("readonly");return{row:n,field:o.source.field,value:o.value}})})}function me(e,t,r){const o={...e,value:t,source:{...e.source,...r?.revision===void 0?{}:{revision:r.revision},...r?.sourceToken===void 0?{}:{sourceToken:r.sourceToken}}};return o.cell={...e.cell,value:o.value,text:_(o,o.value)},o}function wo(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return[...e];const o=new Set(t.edits.flatMap(n=>n.source?[z(n.source)]:[]));return xt(e,to(e,o,r))}function yo(e,t,r){const o=new Set(t.edits.map(n=>z(n.source)));for(const n of o)e.set(n,{...e.get(n),...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}});return o}function Ae(e,t){let r=t.parts;const o=t.rebuild,n=[...t.validationFormulas??[]];let a=lo(r),s=e,i;const c=new Map,l=new Map;function d(g){if(g!==s)throw new M("conflict");if(i)return i;if(!a?.())throw new M("conflict");return fo(r)}async function f(g,m,v,y={}){Z(y.signal),m={requestId:m.requestId,edits:m.edits.map(b=>({...b,address:{...b.address},source:b.source?{...b.source}:void 0,table:b.table?{...b.table}:void 0}))},v=v.map(b=>({...b,address:{...b.address},source:b.source?{...b.source}:void 0,table:b.table?{...b.table}:void 0,cell:{...b.cell}})),await new Promise(b=>setTimeout(b,0)),Z(y.signal);const h=d(g),w=xt(h,po(h,m.edits)),x=Fe(await o(w,y.signal),l);Z(y.signal);let $=!1,T=[],N="allow",L=!1;function p(b){return L=!0,T=Object.freeze(Dr(w,b,y.signal,n).map(S=>Object.freeze({...S}))),L=!1,N=b.warningPolicy??"allow",T}return y.validation&&p(y.validation),{plan:x,get validationIssues(){return T},validate:p,commit(b){if(Z(y.signal),$||s!==g)throw new M("conflict");if(b?.conflicts?.length)throw new M("conflict");if(L)throw new Error("候选规则校验未完成,不能提交");pt(T,N);const S=wo(w,m,b),I=Et(x,m,b);if(b){const P=yo(l,m,b);for(const[F,H]of c)P.has(z(H.source))&&c.set(F,me(H,H.value,b))}return v.forEach((P,F)=>c.set(A(P),me(P,m.edits[F].value,b))),$=!0,i=S,r=void 0,a=void 0,s=I,pe.set(s,u),s}}}const u={get plan(){return s},async prepare(g,m,v){const y=ho(g,m);return f(g,y.batch,y.contexts,v)},async prepareHistory(g,m,v,y,h){if(!y.trim()||m.length>1e4)throw new M("limit");const w=d(g),x=St(w),$=Rt(g),T=new Set,L=m.map(S=>{if(!S.source)throw new M("missing");const I=A(S);if(T.has(I))throw new M("duplicate");T.add(I);const P=$.get(I)??c.get(I);if(!P?.source)throw new M("missing");const F=x(P.source)[0];return me(P,kt(F.row,P.source.field))}).map((S,I)=>({context:S,edit:W(S,m[I][v])})).filter(({edit:S})=>!Object.is(S.previousValue,S.value)),p={requestId:y,edits:L.map(({edit:S})=>S)},b=L.map(({context:S})=>S);return{batch:p,contexts:b,prepared:await f(g,p,b,h)}}};return pe.set(e,u),u}function bo(e){const t=Ie(e.template,e.datasets,e.pagination).plan;return Ae(t,{validationFormulas:[e.pagination?.formula],parts:[{template:e.template,datasets:e.datasets}],rebuild:(r,o)=>mo(r[0].template,r[0].datasets,{...e.pagination,signal:o})})}let vo=0;function It(){return`report-${Date.now()}-${++vo}`}function we(e,t,r){if(!r?.aborted)try{const o=e?.({...t});o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}function $t(e){const t=e.taskId??It(),r=(o,n,a)=>{we(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:n,...a===void 0?{}:{reportId:a}},e.signal)};return{taskId:t,progress(o,n,a){we(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:"started",completed:n,total:a},e.signal)},async run(o,n,a){r(o,"started",a);try{const s=await n();return r(o,"completed",a),s}catch(s){throw r(o,"failed",a),s}},runSync(o,n,a){r(o,"started",a);try{const s=n();return r(o,"completed",a),s}catch(s){throw r(o,"failed",a),s}}}}function Ne(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e,r=o=>typeof o=="string"&&o.trim().length>0&&o.length<=256;return!r(t.datasetId)||!r(t.field)||t.tableId!==void 0&&!r(t.tableId)||t.reportScope!==void 0&&(typeof t.reportScope!="string"||!t.reportScope.trim()||t.reportScope.length>4096)?!1:t.rowKey===void 0?!0:typeof t.rowKey=="string"?t.rowKey.trim().length>0&&t.rowKey.length<=1024:typeof t.rowKey=="number"&&Number.isFinite(t.rowKey)}function Ft(e){return e==="missing-source"||e==="not-applicable"||e==="not-calculable"}function Ot(e){return e.target!==void 0&&!Ne(e.target)?!1:e.valueState===void 0||Ft(e.valueState)&&e.target!==void 0}function Mo(e,t){if(xe.validateDatasetRows([],e),!Ne(t))throw new Error("数据说明目标无效");const r=e.fields.find(n=>n.field===t.field);if(!r)throw new Error("数据说明字段未在契约中声明");const o=[];return r.description&&o.push({code:"field-definition",severity:"info",message:r.description,target:{...t}}),r.calculation&&o.push({code:"field-calculation",severity:"info",message:r.calculation.description,target:{...t}}),o}function Le(e,t,r={}){const o=new Map;for(const a of e.pages)for(const s of a.components){if(s.kind!=="list"||s.tree?.input!=="nested")continue;const i=o.get(s.dataset);if(i&&(i.childrenField??"children")!==(s.tree.childrenField??"children"))throw new Error("同一数据集的嵌套树应使用相同 childrenField");o.set(s.dataset,s.tree)}if(!o.size)return t;const n={...t};for(const[a,s]of o){const i=Math.min(s.maxRows??1e5,r.maxRows??1/0);n[a]=V.flattenTreeInput(t[a]??[],{...s,maxRows:i},r.signal)}return n}function So(e,t,r={}){return Object.values(Le(e,t,r)).reduce((o,n)=>o+n.length,0)}function xo(e,t,r){const o=xe.datasetJsonSchema(r),n=e?.pages.flatMap(i=>i.components).find(i=>i.kind==="list"&&i.dataset===t&&i.tree?.input==="nested");if(!n||n.kind!=="list"||!n.tree)return o;const a=o.items,s=n.tree.childrenField??"children";return{...o,items:{$ref:"#/$defs/treeNode"},$defs:{treeNode:{...a,properties:{...a.properties,[s]:{anyOf:[{type:"null"},{type:"array",items:{$ref:"#/$defs/treeNode"}}]}}}}}}function Ke(e,t){return JSON.stringify([e,t])}function je(e,t,r){return r===void 0?Ke(e,t):JSON.stringify(["shared",r])}function At(e,t,r){return e.map(o=>{const n=o.table?{...o.table,id:r(o.table.id),...o.table.source?{source:{...o.table.source,sourceScope:t}}:{}}:void 0,a=o.grid?.cells.map(s=>s.map(i=>!i||!i.source&&!i.children?i:{...i,...i.source?{source:{...i.source,sourceScope:t}}:{},...i.children?{children:At(i.children,t,r)}:{}}));return n||a?{...o,...n?{table:n}:{},...a?{grid:{...o.grid,cells:a}}:{}}:o})}function ye(e){return oe(e.maxChartComponents),{maxPages:e.maxPages,maxCells:e.maxCells,maxChartComponents:e.maxChartComponents??Ee,usedPages:0,usedCells:0,usedChartComponents:0}}function Eo(e,t){if(!e.repeat)return!1;const r=Object.prototype.hasOwnProperty.call(t,e.repeat.dataset)?t[e.repeat.dataset]:void 0;return Array.isArray(r)&&r.length===0}function Ro(e){const t=r=>r.grid?.cells.reduce((o,n)=>o+n.reduce((a,s)=>a+(s?1+(s.children?.reduce((i,c)=>i+t(c),0)??0):0),0),0)??0;return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function be(e,t){return e===void 0?void 0:e-t}function ge(e,t){return e===void 0?t:Math.max(1,Math.min(e,t??e))}function Nt(e,t,r,o,n){oe(e?.maxChartComponents);const a=be(t.maxPages,t.usedPages),s=t.maxChartComponents-t.usedChartComponents;if(a!==void 0&&a<1&&r.pages.length&&!Eo(r,o))throw new G(0,1);if(s<1&&r.pages.some(i=>i.components.some(c=>c.kind!=="list"&&c.chartBinding)))throw new U(s,1);return{...e,signal:n??e?.signal,maxPages:ge(a,e?.maxPages),maxCells:ge(be(t.maxCells,t.usedCells),e?.maxCells),maxChartComponents:ge(s,e?.maxChartComponents)}}function Lt(e,t){const r=Ro(t.plan),o=be(e.maxCells,e.usedCells);if(o!==void 0&&r>o)throw new q(o,r);e.usedPages+=t.plan.pages.length,e.usedCells+=r,e.usedChartComponents+=t.chartComponents}function Kt(e,t){return e instanceof G&&t.maxPages!==void 0&&(e.limit===t.maxPages-t.usedPages||e.limit===0)?new G(t.maxPages,t.usedPages+e.actual):e instanceof q&&t.maxCells!==void 0?new q(t.maxCells,t.usedCells+e.actual):e instanceof U&&e.limit===t.maxChartComponents-t.usedChartComponents?new U(t.maxChartComponents,t.usedChartComponents+e.estimated):e}function Co(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...o}=e;return{...o,load:async n=>{const a=await t(n);O(n.signal);try{return r(a,n)}catch(s){throw new R("validate",`报表 ${n.reportId} 数据映射失败`,s)}}}}class R extends Error{constructor(t,r,o){super(r),this.name="ReportSourceError",this.code=t,this.cause=o}}function ue(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function O(e){if(e?.aborted)throw ue(e)}function ve(e,t){return t?new Promise((r,o)=>{const n=()=>t.removeEventListener("abort",a),a=()=>{n(),o(ue(t))};t.addEventListener("abort",a,{once:!0}),t.aborted&&a(),Promise.resolve(e).then(s=>{n(),r(s)},s=>{n(),o(s)})}):Promise.resolve(e)}function To(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new R("validate",`报表 ${t} 的数据集应为对象`);for(const[r,o]of Object.entries(e))if(!Array.isArray(o)||o.some(n=>!n||typeof n!="object"||Array.isArray(n)))throw new R("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function Po(e,t,r){const{reportId:o,signal:n}=t;try{const a=await ve(e(t),n);O(n);const s=j.validateReportTemplate(a);if(!s.ok)throw new R("validate",`报表 ${o} 模板校验失败:${s.errors.slice(0,3).map(i=>`${i.path}: ${i.message}`).join("; ")}`);return r.push(...s.warnings.map(i=>`${o}: ${i.path}: ${i.message}`)),a}catch(a){throw n?.aborted?ue(n):a instanceof R?a:a instanceof j.ReportTemplateError?new R("validate",`报表 ${o} 模板校验失败:${a.message}`,a):new R("fetch",`报表 ${o} 模板加载失败:${a instanceof Error?a.message:String(a)}`,a)}}async function ko(e,t,r,o){const n=t.signal;let a;try{if(e.load)a=await ve(e.load(t),n);else if(e.provider){const s=await ve(e.provider.query(t),n);O(n),Io(s,r),a=s.datasets,o?.(r,s)}else a=e.datasets??{}}catch(s){throw n?.aborted?ue(n):s instanceof R?s:new R("fetch",`报表 ${r} 取数失败:${s instanceof Error?s.message:String(s)}`,s)}return O(n),a}function Io(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new R("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new R("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 R("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`);if(e.diagnostics?.some(r=>!Ot(r)))throw new R("validate",`报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`)}function $o(e,t,r,o,n){try{t=Le(o,t,{maxRows:e.dataValidation?.maxRows,signal:n})}catch(a){throw new R("validate",`报表 ${r} 树形数据无效:${a instanceof Error?a.message:String(a)}`,a)}for(const[a,s]of Object.entries(e.dataSchema??{})){let i;try{i=xe.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0,s,{...e.dataValidation,path:`$.datasets.${a}`})}catch(c){throw new R("config",`报表 ${r} 数据集 ${a} 字段契约配置无效`,c)}if(!i.ok)throw new R("validate",`报表 ${r} 数据集 ${a} 不符合字段契约:${i.issues[0]?.message}`,{issues:i.issues})}}async function Fo(e,t,r,o,n){try{let a;try{a=uo(e)}catch{}const s=a??e,i=Nt(t.pagination,o,s.template,s.datasets,n),c=a?await ut(s.template,s.datasets,i):Ie(s.template,s.datasets,i);return Lt(o,c),{result:c,part:s}}catch(a){O(n);const s=Kt(a,o);throw new R("validate",`报表 ${r} 排版失败:${s instanceof Error?s.message:String(s)}`,s)}}function jt(e,t,r,o,n){const a=new Map,s=i=>{let c=a.get(i);return c===void 0&&(c=JSON.stringify([r,o,i]),a.set(i,c)),c};for(const i of t.pages)e.push({...i,meta:{...i.meta,reportScope:Ke(r,o)},components:At(i.components,n??je(r,o),s)})}async function Oo(e,t,r,o,n){const a=[],s=ye(o);for(const[l,d]of e.entries()){O(n);try{const f=await Pt(d.template,d.datasets,Nt(t[l]?.pagination,s,d.template,d.datasets,n));Lt(s,f),jt(a,f.plan,l,r[l],d.sourceScope)}catch(f){throw Kt(f,s)}}const i={schemaVersion:Me.RENDER_PLAN_SCHEMA_VERSION,...e.some(l=>Re(l.template))?{requiresRecalculation:!0}:{},pages:a},c=j.validateRenderPlan(i);if(!c.ok)throw new R("validate",`重算渲染计划校验失败:${c.errors[0]?.message}`);return i}function Ao(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new R("config","maxPages 应为正安全整数");if(t.maxCells!==void 0&&(!Number.isSafeInteger(t.maxCells)||t.maxCells<1))throw new R("config","maxCells 应为正安全整数");try{ye(t)}catch(n){throw new R("config","maxChartComponents 应为 1..1000000 的安全整数",n)}function r(n){const a=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(!a)throw new R("config",`未注册报表 ${n}`);if(a.sourceScope!==void 0&&(typeof a.sourceScope!="string"||!a.sourceScope.trim()||a.sourceScope.length>512))throw new R("config","sourceScope 应为不超过 512 字符的非空字符串");return a}return Object.assign(async({reportIds:n,params:a,signal:s,onWarning:i,onQueryResult:c,...l})=>{O(s);const d=$t({...l,signal:s}),f=[...n],u={...a};if(f.length===0)throw new R("config","缺少报表 ID");const g=f.map(r),m=d.runSync("validate",()=>g.map(p=>He.assertReportParams(p.params??(typeof p.template=="function"?[]:p.template.params)??[],u))),v=[],y=[],h=ye(t),w=[];for(const[p,b]of g.entries()){O(s);const S=f[p],I={reportId:S,params:m[p],signal:s},P=typeof b.template=="function"?await d.run("query",()=>Po(b.template,I,w),S):b.template;I.params=d.runSync("validate",()=>He.assertReportParams(b.params??P.params??[],I.params),S);const F=await d.run("query",()=>ko(b,I,S,(fe,Bt)=>c?.(fe,Bt,p)),S);d.runSync("validate",()=>{To(F,S),t.onDatasets?.(S,F,P),$o(b,F,S,P,s)},S),O(s);const H=je(p,S,b.sourceScope),{result:De,part:Dt}=await d.run("layout",()=>Fo({template:P,datasets:F,sourceScope:H},b,S,h,s),S);y.push(Dt),jt(v,De.plan,p,S,H),w.push(...De.warnings.map(fe=>`${S}: ${fe}`))}O(s);const x={schemaVersion:Me.RENDER_PLAN_SCHEMA_VERSION,...y.some(p=>Re(p.template))?{requiresRecalculation:!0}:{},pages:v},$=d.runSync("validate",()=>{const p=j.validateRenderPlan(x);if(!p.ok)throw new R("validate",`渲染计划校验失败:${p.errors.slice(0,3).map(b=>`${b.path}: ${b.message}`).join("; ")}`);return p});w.push(...$.warnings.map(p=>`${p.path}: ${p.message}`));const T=g.map(p=>({...p,pagination:{...p.pagination}})),N={maxPages:t.maxPages,maxCells:t.maxCells,maxChartComponents:t.maxChartComponents};try{Ae(x,{parts:y,validationFormulas:T.map(p=>p.pagination?.formula),rebuild:(p,b)=>Oo(p,T,f,N,b)})}catch{w.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const L=i??t.onWarning??(p=>console.warn("[mach-report]",p));for(const p of w)O(s),L(p);return O(s),x},{getParamDefs:n=>Ht.getReportParamDefs(e,n)})}function No(e,t){const r=t.maxNodes??1e6;if(![t.maxBytes,r].every(d=>Number.isSafeInteger(d)&&d>0))throw t.error("budget","快照预算应为正安全整数");let o=0,n=0;const a=new Set;function s(d){if(n+=d,n>t.maxBytes)throw t.error("budget","快照超过字节预算")}function i(d,f){if(++o>r||f>64)throw t.error("budget","快照节点或深度超过预算");if(o%1024===0&&t.check?.(),typeof d=="string")return s(d.length+2),d;if(d===null||typeof d=="boolean"||typeof d=="number"&&Number.isFinite(d))return s(String(d).length),d;if(!d||typeof d!="object"||a.has(d))throw t.error("input","快照应为无循环的有限 JSON 值");return c(d,f)}function c(d,f){const u=Array.isArray(d),g=Object.getPrototypeOf(d);if(g!==(u?Array.prototype:Object.prototype)&&!(g===null&&!u)||Object.getOwnPropertySymbols(d).length)throw t.error("input","快照应为普通 JSON 对象");const m=Object.getOwnPropertyNames(d).filter(h=>!(u&&h==="length"));if(u&&(m.length!==d.length||m.some((h,w)=>h!==String(w))))throw t.error("input","快照数组应为连续数组");a.add(d),s(2);const v=Object.create(null);let y=0;for(const h of m){const w=Object.getOwnPropertyDescriptor(d,h);if(w.get||w.set||!w.enumerable||["__proto__","constructor","prototype"].includes(h))throw t.error("input","快照不允许访问器或危险键");w.value===void 0&&!u||(s((y++?1:0)+(u?0:h.length+3)),v[h]=i(w.value===void 0?null:w.value,f+1))}return a.delete(d),u?m.map(h=>v[h]):v}t.check?.();const l=JSON.stringify(i(e,0));if(new TextEncoder().encode(l).byteLength>t.maxBytes)throw t.error("budget","快照超过字节预算");return JSON.parse(l)}exports.DEFAULT_LABEL_PAGE_LIMIT=Qe;exports.PaginateCellLimitError=q;exports.PaginateChartComponentLimitError=U;exports.PaginatePageLimitError=G;exports.ReportCellEditError=M;exports.ReportSourceError=R;exports.ReportValidationError=mt;exports.applyReportCellEdit=eo;exports.applyReportCellEditBatch=ao;exports.applyReportEditResult=Et;exports.applyReportSourceMetadata=Fe;exports.assertReportValidation=pt;exports.countTemplatePages=Pr;exports.createReportCellEdit=Ur;exports.createReportCellEditBatch=no;exports.createReportCellResolver=B;exports.createReportEditSession=bo;exports.createReportSource=Ao;exports.createReportTaskReporter=$t;exports.defineReport=Co;exports.editFromContext=W;exports.estimateListLayoutCells=Or;exports.explainDatasetField=Mo;exports.formatReportCellEdit=_;exports.getReportCellContext=le;exports.getReportEditSession=go;exports.hasValidDataExplanation=Ot;exports.isReportDataTarget=Ne;exports.isReportValueState=Ft;exports.notifyReportTaskEvent=we;exports.paginateTemplate=Ie;exports.paginateTemplatePages=kr;exports.parseReportCellInput=$e;exports.projectListColumns=Ye;exports.registerReportEditSession=Ae;exports.relocateReportCellEdits=io;exports.reportCellEditKey=A;exports.reportOccurrenceScope=Ke;exports.reportSourceScope=je;exports.reportTaskId=It;exports.snapshotReportJson=No;exports.sourceChanged=de;exports.summarizeReportCellEdits=so;exports.templateDatasetJsonSchema=xo;exports.templateDatasetRowCount=So;exports.templateValidationDatasets=Le;exports.validateReportDataset=jr;
|
package/dist/matrix-0hywp0-F.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h=require("./computed-4TnxzgIh.cjs");function A(e,r,t){if(!Array.isArray(e)||Object.getPrototypeOf(e)!==Array.prototype||e.length>r)throw new TypeError(`${t}应为有界普通数组`);if(Reflect.ownKeys(e).length!==e.length+1)throw new TypeError(`${t}不支持自定义数组方法或迭代器`);const l=[];for(let a=0;a<e.length;a++){const n=Object.getOwnPropertyDescriptor(e,String(a));if(!n||!Object.prototype.hasOwnProperty.call(n,"value"))throw new TypeError(`${t}不支持空洞或访问器`);l.push(n.value)}return l}function m(e,r,t){if(e===void 0)return r;if(!Number.isSafeInteger(e)||Number(e)<1||Number(e)>t)throw new RangeError("图表预算超出允许范围");return Number(e)}function N(e){if(!e||typeof e!="object"||Array.isArray(e))throw new TypeError("图表绑定应为对象");if(h.computationFieldName(e.dataset),h.computationFieldName(e.categoryField),!["bar","line","stackedBar","percentBar"].includes(e.type))throw new TypeError("图表类型无效");if(e.sort!==void 0&&!["asc","desc"].includes(e.sort))throw new TypeError("图表排序无效");if(e.title!==void 0&&(typeof e.title!="string"||e.title.length>512))throw new TypeError("图表标题过长");if(e.showValues!==void 0&&typeof e.showValues!="boolean")throw new TypeError("图表数值标签应为布尔值");if(!Array.isArray(e.measures)||!e.measures.length||e.measures.length>12)throw new RangeError("图表支持 1–12 个度量");for(const r of A(e.measures,12,"图表度量"))O(r);m(e.maxRows,1e5,1e5),m(e.maxCategories,200,200)}function O(e){if(!e||typeof e!="object"||Array.isArray(e))throw new TypeError("图表度量应为对象");if(e.field!==void 0&&h.computationFieldName(e.field),e.weightField!==void 0&&h.computationFieldName(e.weightField),e.label!==void 0&&(typeof e.label!="string"||e.label.length>256))throw new TypeError("图表系列名称过长");if(e.color!==void 0&&!/^#[\da-f]{6}$/i.test(e.color))throw new TypeError("图表颜色应为 #RRGGBB");h.createAggregateAccumulator(e)}function T(e){if(e==null)return{key:"null",label:"—"};if(typeof e!="string"&&typeof e!="boolean"&&!(typeof e=="number"&&Number.isFinite(e)))throw new TypeError("图表分类应为文本、布尔或有限数字");const r=String(e);if(r.length>512)throw new RangeError("图表分类名称过长");return{key:JSON.stringify([typeof e,e]),label:r}}function j(e){if(e===null)return null;const r=Number(e);if(!Number.isFinite(r))throw new RangeError("聚合结果超出图表有限数值范围");return r}function L(e,r,t){if(t?.aborted){const s=new Error("图表数据处理已取消");throw s.name="AbortError",s}N(r);const l=A(r.measures,12,"图表度量");if(!Array.isArray(e)||e.length>m(r.maxRows,1e5,1e5))throw new RangeError("图表数据超出行数预算");const a=new Map,n=m(r.maxCategories,200,200);for(let s=0;s<e.length;s++){if(t?.aborted){const f=new Error("图表数据处理已取消");throw f.name="AbortError",f}const c=e[s];if(!c||typeof c!="object"||Array.isArray(c))throw new TypeError("图表数据行应为对象");const i=T(Object.prototype.hasOwnProperty.call(c,r.categoryField)?c[r.categoryField]:null);let u=a.get(i.key);if(!u){if(a.size>=n)throw new RangeError("图表分类超出预算,请明确筛选或聚合数据");u={label:i.label,accumulators:l.map(h.createAggregateAccumulator)},a.set(i.key,u)}u.accumulators.forEach(f=>f.add(c))}const o=[...a.values()];return r.sort&&o.sort((s,c)=>(r.sort==="desc"?-1:1)*(s.label<c.label?-1:s.label>c.label?1:0)),{categories:o.map(s=>s.label),series:l.map((s,c)=>({name:s.label??`${s.field??"记录"} · ${s.op}`,values:o.map(i=>j(i.accumulators[c].value())),...s.color?{color:s.color}:{}}))}}function $(e,r){const t=()=>r.measures.map(c=>h.createAggregateAccumulator(c)),l=new Map,a=new Map,n=new Map,o=r.totals?t():void 0,s=(c,i)=>c?.forEach(u=>u.add(i));for(const c of e){const i=r.row(c),u=r.column(c);a.has(u.key)||a.set(u.key,u.label);let f=l.get(i.key);f||(f={label:i.label,cells:new Map,...r.totals?{totals:t()}:{}},l.set(i.key,f)),r.check(l.size,a.size);let d=f.cells.get(u.key);if(d||(d=t(),f.cells.set(u.key,d)),s(d,c),!r.totals)continue;let y=n.get(u.key);y||(y=t(),n.set(u.key,y)),s(f.totals,c),s(y,c),s(o,c)}return{groups:l,columns:a,columnTotals:n,totals:o}}function w(e,r){return JSON.stringify([e.slice(0,r.length),r.map(t=>[t===null?"null":typeof t,t])])}function x(e,r){return r.map(t=>{const l=Object.prototype.hasOwnProperty.call(e,t)?e[t]:null;if(l==null)return null;if(typeof l=="string"||typeof l=="boolean"||typeof l=="number"&&Number.isFinite(l))return l;throw new Error("矩阵维度必须是有限 JSON 标量")})}function z(e,r,t){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("矩阵层级应为对象");for(const l of[e.emptyLabel,e.subtotalLabel,e.totalLabel])if(l!==void 0&&typeof l!="string")throw new Error("矩阵层级标签应为字符串");E(e.row,r.length),E(e.column,t.length)}function E(e,r){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("矩阵轴配置应为对象");if(e.labels!==void 0&&(!Array.isArray(e.labels)||e.labels.length!==r||e.labels.some(t=>typeof t!="string")))throw new Error("矩阵维度标签必须与维度字段一一对应");if(e.sort!==void 0&&(!Array.isArray(e.sort)||e.sort.length>r||e.sort.some(t=>!["source","asc","desc"].includes(t))))throw new Error("矩阵维度排序应为 source、asc 或 desc");if(e.subtotals!==void 0&&(!Array.isArray(e.subtotals)||new Set(e.subtotals).size!==e.subtotals.length||e.subtotals.some(t=>!Number.isInteger(t)||t<1||t>=r)))throw new Error("矩阵小计深度应唯一且位于 1 至末级之前")}}function F(e,r,t){return{fields:e,options:r??{},hierarchy:t,root:{values:[],children:new Map},leaves:0,expanded:0}}function k(e,r){const t=x(r,e.fields);let l=e.root;for(let a=1;a<=t.length;a++){const n=t.slice(0,a),o=w(e.fields,n);let s=l.children.get(o);s||(s={values:n,children:new Map},l.children.set(o,s),a===t.length?(e.leaves++,e.expanded++):e.options.subtotals?.includes(a)&&e.expanded++),l=s}}function P(e,r){if(e===r)return 0;if(e===null)return-1;if(r===null)return 1;if(typeof e=="number"&&typeof r=="number")return e-r;const t=`${typeof e}:${e}`,l=`${typeof r}:${r}`;return t<l?-1:1}function B(e,r){const t=[...e.children.values()];return r&&r!=="source"&&t.sort((l,a)=>P(l.values[l.values.length-1],a.values[a.values.length-1])*(r==="desc"?-1:1)),t}function b(e,r,t){return{key:w(e.fields,r),kind:t,depth:r.length,fields:e.fields.slice(0,r.length),values:r,labels:r.map(l=>l===null?e.hierarchy.emptyLabel??"(空)":String(l))}}function M(e,r){const t=[];function l(a){for(const n of B(a,e.options.sort?.[a.values.length]))n.children.size?(l(n),e.options.subtotals?.includes(n.values.length)&&t.push(b(e,n.values,"subtotal"))):t.push(b(e,n.values,"member"))}return l(e.root),r&&e.leaves&&t.push(b(e,[],"total")),t}function R(e,r,t){const l=x(r,e.fields),a=[w(e.fields,l),...(e.options.subtotals??[]).map(n=>w(e.fields,l.slice(0,n)))];return t&&a.push(w(e.fields,[])),a}function I(e,r,t){if(!(e.kind!=="member"&&r>e.depth))return e.kind==="total"?{key:"total",text:t.totalLabel??"合计",rowSpan:0}:e.kind==="subtotal"&&r===e.depth?{key:e.key,text:t.subtotalLabel??"小计",rowSpan:0}:{key:JSON.stringify(e.values.slice(0,r+1).map(l=>[typeof l,l])),text:e.labels[r],rowSpan:1}}function K(e,r){const t=e.columnFields.length+1,l=e.rowFields.length,a=Array.from({length:t},()=>Array(l+r.length).fill(null));for(let n=0;n<e.columnFields.length;n++){let o;r.forEach((s,c)=>{const i=I(s,n,e.hierarchy);if(!i){o=void 0;return}if(o?.key===i.key){o.cell.colSpan=(o.cell.colSpan??1)+1;return}const u={text:i.text,rowSpan:i.rowSpan||e.columnFields.length-n,editable:!1,derived:!0};a[n][l+c]=u,o={key:i.key,cell:u}})}return e.rowFields.forEach((n,o)=>{a[0][o]={text:e.hierarchy.row?.labels?.[o]??n,rowSpan:t,editable:!1,derived:!0}}),r.forEach((n,o)=>{const s=e.measures[n.measure];a[t-1][l+o]={text:s.label??`${s.field} (${s.op})`,editable:!1,derived:!0}}),{cells:a.map(n=>n.filter(o=>o!==null)),colWidthsMm:[...e.rowFields.map(()=>e.rowWidthMm??40),...r.map(()=>e.columnWidthMm??28)]}}function v(e,r,t,l){const a=+(!!r.totals&&e>0),n=t.expanded+a,o=(l.expanded+a)*r.measures.length+r.rowFields.length;if(n>(r.maxRows??1e3)||l.expanded+a>(r.maxColumns??200))throw new Error("矩阵层级展开数量超出预算(包含小计/总计)");if(n*o>(r.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算");return{rowCount:n,columnCount:o,cells:n*o}}function S(e,r){if(!Array.isArray(e)||e.length>(r.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const t=F(r.rowFields,r.hierarchy.row,r.hierarchy),l=F(r.columnFields,r.hierarchy.column,r.hierarchy);if(e.length*(1+(t.options.subtotals?.length??0)+ +!!r.totals)*(1+(l.options.subtotals?.length??0)+ +!!r.totals)*r.measures.length>(r.maxAggregateUpdates??1e7))throw new Error("矩阵聚合更新超出 maxAggregateUpdates 预算");let n=v(0,r,t,l);for(const o of e){if(!o||typeof o!="object"||Array.isArray(o))throw new Error("矩阵数据行应为对象");k(t,o),k(l,o),n=v(e.length,r,t,l)}return{row:t,column:l,shape:n}}function H(e,r){return S(e,r).shape}function J(e,r,t){const l=new Map;for(const a of e){const n=R(t.row,a,!!r.totals),o=R(t.column,a,!!r.totals);for(const s of n){let c=l.get(s);c||(c=new Map,l.set(s,c));for(const i of o){let u=c.get(i);u||(u=r.measures.map(f=>h.createAggregateAccumulator({...f,field:f.valueField??f.field})),c.set(i,u)),u.forEach(f=>f.add(a))}}}return l}function _(e,r){return e.flatMap((t,l)=>r.measures.map((a,n)=>({...t,field:t.kind==="total"?`total_${n}`:`c${l}_${n}`,measure:n,measureField:a.field,valueField:a.valueField??a.field,operation:a.op})))}function D(e,r){return e.kind==="total"?r.hierarchy.totalLabel??"合计":[...e.labels,...e.kind==="subtotal"?[r.hierarchy.subtotalLabel??"小计"]:[]].join(" / ")}function V(e,r){return[...r.rowFields.map((t,l)=>({field:`r${l}`,header:r.hierarchy.row?.labels?.[l]??t,semanticRole:"dimension"})),...e.map(t=>{const l=r.measures[t.measure];return{field:t.field,header:`${D(t,r)} · ${l.label??`${l.field} (${l.op})`}`,semanticRole:"measure",...l.digits===void 0?{}:{format:{kind:"number",digits:l.digits}}}})]}function W(e,r,t,l){return e.map(a=>{const n={};t.rowFields.forEach((o,s)=>{n[`r${s}`]=a.kind==="total"?s===0?t.hierarchy.totalLabel??"合计":null:a.labels[s]??(s===a.depth?t.hierarchy.subtotalLabel??"小计":null)});for(const o of r)n[o.field]=l.get(a.key)?.get(o.key)?.[o.measure]?.value()??(t.measures[o.measure].op==="count"?0:null);return n})}function G(e,r){const t=S(e,r),l=M(t.row,!!r.totals),a=_(M(t.column,!!r.totals),r),n=J(e,r,t);return{columns:V(a,r),rows:W(l,a,r,n),headerGrid:K(r,a),metadata:{rowFields:[...r.rowFields],rowLabels:[...r.hierarchy.row?.labels??r.rowFields],columnFields:[...r.columnFields],columnLabels:[...r.hierarchy.column?.labels??r.columnFields],rows:l,columns:a}}}function g(e,r){const t=r.map(l=>Object.prototype.hasOwnProperty.call(e,l)?e[l]:null);if(t.some(l=>l!=null&&typeof l!="string"&&typeof l!="boolean"&&!(typeof l=="number"&&Number.isFinite(l))))throw new Error("矩阵维度必须是有限 JSON 标量");return{key:JSON.stringify(t.map(l=>[typeof l,l??null])),label:t.map(l=>l==null?"":String(l)).join(" / ")}}function U(e){for(const r of["maxRows","maxColumns","maxInputRows","maxCells","maxAggregateUpdates"])if(e[r]!==void 0&&(!Number.isSafeInteger(e[r])||e[r]<1))throw new Error("矩阵预算应为正安全整数");for(const r of["columnWidthMm","rowWidthMm"])if(e[r]!==void 0&&(!Number.isFinite(e[r])||e[r]<=0))throw new Error("矩阵列宽应为正数")}function p(e){if(!e||!Array.isArray(e.rowFields)||!Array.isArray(e.columnFields)||!Array.isArray(e.measures))throw new Error("矩阵需要行维度、列维度和度量数组");for(const t of[e.rowFields,e.columnFields])if(t.some(l=>typeof l!="string"||!l.trim())||new Set(t).size!==t.length)throw new Error("矩阵维度字段应非空且唯一");if(U(e),!e.rowFields.length||!e.columnFields.length||e.rowFields.length>16||e.columnFields.length>16)throw new Error("矩阵需要 1–16 个行/列维度");if(!e.measures.length||e.measures.length>32)throw new Error("矩阵需要 1–32 个度量");if(e.measures.map(t=>{if(!t||typeof t!="object")throw new Error("矩阵度量应为对象");if(h.createAggregateAccumulator({...t,field:t.valueField??t.field}),t.label!==void 0&&typeof t.label!="string")throw new Error("矩阵度量标签应为字符串");return t.field}).some(t=>typeof t!="string"||!t.trim()))throw new Error("矩阵度量字段应非空");e.hierarchy!==void 0&&z(e.hierarchy,e.rowFields,e.columnFields)}function C(e,r){if(p(r),r.hierarchy)return H(e,r);if(!Array.isArray(e)||e.length>(r.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const t=new Set,l=new Set;for(const o of e){if(!o||typeof o!="object"||Array.isArray(o))throw new Error("矩阵数据行应为对象");if(t.add(g(o,r.rowFields).key),l.add(g(o,r.columnFields).key),t.size>(r.maxRows??1e3)||l.size>(r.maxColumns??200))throw new Error("矩阵维度数量超出预算");if((t.size+ +!!r.totals)*((l.size+ +!!r.totals)*r.measures.length+1)>(r.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算")}const a=t.size+ +(!!r.totals&&e.length>0),n=(l.size+ +!!r.totals)*r.measures.length+1;return{rowCount:a,columnCount:n,cells:a*n}}function q(e,r){if(r?.hierarchy)return p(r),G(e,r);C(e,r);const t=$(e,{row:o=>g(o,r.rowFields),column:o=>g(o,r.columnFields),measures:r.measures.map(o=>({...o,field:o.valueField??o.field})),totals:r.totals,check:()=>{}}),l=[...t.groups.values()].map(o=>({rowLabel:o.label})),a=[{field:"rowLabel",header:r.rowHeader??r.rowFields.join(" / "),semanticRole:"dimension"}],n={rowLabel:"合计"};return r.measures.forEach((o,s)=>{const c=[...t.columns.entries()].map(([i,u],f)=>({key:i,label:u,field:`c${f}_${s}`}));r.totals&&c.push({key:"",label:"合计",field:`total_${s}`});for(const i of c){const u=i.field===`total_${s}`;a.push({field:i.field,header:`${i.label} · ${o.label??`${o.field} (${o.op})`}`,semanticRole:"measure",...o.digits===void 0?{}:{format:{kind:"number",digits:o.digits}}});let f=0;for(const d of t.groups.values())l[f++][i.field]=(u?d.totals?.[s]:d.cells.get(i.key)?.[s])?.value()??(o.op==="count"?0:null);n[i.field]=(u?t.totals?.[s]:t.columnTotals.get(i.key)?.[s])?.value()??(o.op==="count"?0:null)}}),r.totals&&e.length&&l.push(n),{rows:l,columns:a}}exports.accumulatePivotRows=$;exports.chartArray=A;exports.createMatrixTable=q;exports.createReportChartData=L;exports.estimateMatrixTable=C;exports.validateMatrixOptions=p;exports.validateReportChartBinding=N;
|