@agile-team/mach-report 2.16.0 → 2.18.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 +25 -12
- package/dist/{ExcelBindingWizard-CP6h2x1f.cjs → ExcelBindingWizard-Czn3C2yE.cjs} +1 -1
- package/dist/{ExcelBindingWizard-HhB3hAJE.js → ExcelBindingWizard-DMGZj6I6.js} +3 -3
- package/dist/ParamEditor-KzDQvbHY.js +732 -0
- package/dist/ParamEditor-oDfD8LgE.cjs +1 -0
- package/dist/{ReportBatchPanel-ruxcbfY6.js → ReportBatchPanel-BJK7PvZ4.js} +39 -39
- package/dist/ReportBatchPanel-DnmNRssu.cjs +1 -0
- package/dist/ReportParamPanel-mQkeN70Q.js +1020 -0
- package/dist/ReportParamPanel-sOANVRz-.cjs +1 -0
- package/dist/ReportPreview-BxWWTUL5.js +5583 -0
- package/dist/ReportPreview-Yf99omi3.cjs +6 -0
- package/dist/{ReportTemplateLibrary-DcwrH-63.js → ReportTemplateLibrary-BFjB08Wu.js} +1 -1
- package/dist/{ReportTemplateLibrary-BDlNT8JN.cjs → ReportTemplateLibrary-BO42QnWd.cjs} +1 -1
- package/dist/RuleEditor-CqxT1a-W.js +2337 -0
- package/dist/RuleEditor-D7YWigD9.cjs +1 -0
- package/dist/{TemplateOutlinePanel-CGrT5DFN.cjs → TemplateOutlinePanel-B0XX350V.cjs} +1 -1
- package/dist/{TemplateOutlinePanel-SXCjaPKR.js → TemplateOutlinePanel-zG0DrsIB.js} +2 -2
- package/dist/{TemplateReusePanel-6Z3wRFz8.cjs → TemplateReusePanel-BD0HSKp_.cjs} +1 -1
- package/dist/{TemplateReusePanel-lHLOS9Wn.js → TemplateReusePanel-Czwe5GbC.js} +2 -2
- package/dist/{TemplateReviewPanel-Dpk7sLcF.cjs → TemplateReviewPanel-CA5sdffM.cjs} +1 -1
- package/dist/{TemplateReviewPanel-CJ9PLc48.js → TemplateReviewPanel-NhmQI65C.js} +2 -2
- package/dist/analytics.cjs +1 -1
- package/dist/analytics.d.cts +163 -42
- package/dist/analytics.d.ts +163 -42
- package/dist/analytics.js +76 -141
- package/dist/artifact-integrity.json +110 -108
- package/dist/assets-2eC3mOcV.js +232 -0
- package/dist/assets-B0Hxn4l6.cjs +1 -0
- package/dist/{auto-uVBjX1j5.cjs → auto-B0EZFIK1.cjs} +1 -1
- package/dist/{auto-YR7a4BtF.js → auto-BlchZ1b8.js} +10 -10
- package/dist/{batch-WzDIXJAt.js → batch-DGCt44XM.js} +1 -1
- package/dist/{batch-z6Aw5GEY.cjs → batch-DYcokH4v.cjs} +1 -1
- package/dist/charts-Dlv8j2AG.js +141 -0
- package/dist/charts-aCtoswXq.cjs +1 -0
- package/dist/codes.cjs +9 -9
- package/dist/codes.d.cts +54 -0
- package/dist/codes.d.ts +54 -0
- package/dist/codes.js +12097 -13668
- package/dist/column-visual-BpgQVWwT.js +238 -0
- package/dist/column-visual-CtYxnBCP.cjs +1 -0
- package/dist/component-tree-6TV7W6Yj.cjs +1 -0
- package/dist/component-tree-CvW4lzpv.js +67 -0
- package/dist/computed-4TnxzgIh.cjs +1 -0
- package/dist/computed-C8NRZQss.js +739 -0
- package/dist/data-bar-Ce38juRZ.cjs +1 -0
- package/dist/data-bar-PtjXhMgN.js +9 -0
- package/dist/dataset-DL83majE.js +161 -0
- package/dist/dataset-IrlXbUvh.cjs +1 -0
- package/dist/designer--TKECSEc.cjs +2 -0
- package/dist/designer-d6hJS41w.js +5683 -0
- package/dist/designer.cjs +1 -1
- package/dist/designer.d.cts +835 -45
- package/dist/designer.d.ts +835 -45
- package/dist/designer.js +23 -20
- package/dist/{encoding-BYF9ZTl9.cjs → encoding-B--eZpp1.cjs} +1 -1
- package/dist/{encoding-BOGq4qYL.js → encoding-mctOLocI.js} +2 -2
- package/dist/{font-loader-EKLzOJxf.cjs → font-loader-DBBJ5KE9.cjs} +1 -1
- package/dist/{font-loader-CzI1GuBc.js → font-loader-DW8tIaNp.js} +1 -1
- package/dist/index-CPh6tqge.js +1575 -0
- package/dist/index-CUNw7dL9.cjs +1 -0
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +534 -16
- package/dist/index.d.ts +534 -16
- package/dist/index.js +1393 -955
- package/dist/json-snapshot-By4ZVVUt.js +1967 -0
- package/dist/json-snapshot-jiXff4lc.cjs +2 -0
- package/dist/matrix-0hywp0-F.cjs +1 -0
- package/dist/matrix-Dy-tyY7E.js +381 -0
- package/dist/param-validation-C-8sRJLq.cjs +1 -0
- package/dist/param-validation-CnDEd2l-.js +333 -0
- package/dist/{pdf-DJ5S6ukC.js → pdf-CKROKygt.js} +1845 -1845
- package/dist/{pdf-ByVCb1i6.cjs → pdf-DqyxJ96U.cjs} +47 -47
- package/dist/pdf.cjs +1 -1
- package/dist/pdf.d.cts +66 -0
- package/dist/pdf.d.ts +66 -0
- package/dist/pdf.js +2 -2
- package/dist/{plugin-C2j5_mhx.js → plugin-ByjF2kiV.js} +5 -5
- package/dist/{plugin-Dr39GBRG.cjs → plugin-DM1M2wlI.cjs} +1 -1
- package/dist/prefill-B8H9qwE4.js +371 -0
- package/dist/prefill-D7EswyTI.cjs +1 -0
- package/dist/{prepared-DqtpvRTn.js → prepared-BE-4jfX5.js} +2 -2
- package/dist/{prepared-DdrjLC7L.cjs → prepared-CGVphji3.cjs} +1 -1
- package/dist/{protocol-BzwMP4Vw.cjs → protocol-ByRVzzQG.cjs} +1 -1
- package/dist/{protocol-kt4Iy6-3.js → protocol-Cr81vFSQ.js} +3 -3
- package/dist/{record-bindings-CZWBJ1fU.js → record-bindings-DEJtmo3p.js} +67 -107
- package/dist/record-bindings-ehjnCDHt.cjs +1 -0
- package/dist/{region-binding-workflow-CWNvIjkV.js → region-binding-workflow-CBg0l_tj.js} +2 -2
- package/dist/{region-binding-workflow-CqSMxQ4p.cjs → region-binding-workflow-D05tOYn3.cjs} +1 -1
- package/dist/report-encoding-worker.cjs +1 -1
- package/dist/report-encoding-worker.js +1 -1
- package/dist/{report-params-B1RzkhJj.js → report-params-D9tBuM9B.js} +1 -1
- package/dist/{report-params-WDGrA4oP.cjs → report-params-VTg8MoCp.cjs} +1 -1
- package/dist/runtime-CDA6d263.cjs +1 -0
- package/dist/runtime-CEMvybO7.js +170 -0
- package/dist/sbom.cdx.json +1 -1
- package/dist/server/node.d.cts +121 -7
- package/dist/server/node.d.ts +121 -7
- package/dist/server-node.cjs +4 -4
- package/dist/server-node.js +3446 -2115
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +417 -29
- package/dist/server.d.ts +417 -29
- package/dist/server.js +787 -544
- package/dist/sha256-BDQ1Qk7A.js +158 -0
- package/dist/sha256-DgZAKXqI.cjs +1 -0
- package/dist/style.css +1 -1
- package/dist/template-bindings-Cg5oBLFT.cjs +1 -0
- package/dist/template-bindings-TKnXM7ll.js +62 -0
- package/dist/{template-catalog-BtR2JmCL.js → template-catalog-CmbWOJqy.js} +16 -16
- package/dist/template-catalog-Utu4GP09.cjs +1 -0
- package/dist/{template-fragments-BVsbxs4a.cjs → template-fragments-C_zSHJAa.cjs} +1 -1
- package/dist/{template-fragments-By0aZC1D.js → template-fragments-DWgo9tlZ.js} +2 -2
- package/dist/{template-outline-BwRV_eRo.cjs → template-outline-DWkzZXVC.cjs} +1 -1
- package/dist/{template-outline-cnWfT_LK.js → template-outline-DiADphlq.js} +1 -1
- package/dist/{template-registry-Cw3vRTX2.js → template-registry-BIhIHOab.js} +319 -314
- package/dist/template-registry-DzWswQI5.cjs +1 -0
- package/dist/vue/async.d.cts +636 -35
- package/dist/vue/async.d.ts +636 -35
- package/dist/vue/index.d.cts +746 -67
- package/dist/vue/index.d.ts +746 -67
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +94 -89
- package/dist/{workbook-session-Cbts-22R.cjs → workbook-session-B94EwVa_.cjs} +1 -1
- package/dist/{workbook-session-BeSO8PFB.js → workbook-session-BoScoOg-.js} +2 -2
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +75 -7
- package/dist/worker.d.ts +75 -7
- package/dist/worker.js +4 -4
- package/dist/xlsx.cjs +4 -4
- package/dist/xlsx.d.cts +208 -15
- package/dist/xlsx.d.ts +208 -15
- package/dist/xlsx.js +288 -252
- package/package.json +1 -1
- package/dist/ParamEditor-CUQLgoxa.cjs +0 -1
- package/dist/ParamEditor-OKesP_nO.js +0 -594
- package/dist/ReportBatchPanel-cZCAMAwH.cjs +0 -1
- package/dist/ReportPreview-BcDKCLiK.js +0 -4834
- package/dist/ReportPreview-Bk9nLfO9.cjs +0 -6
- package/dist/RuleEditor-BX5S8RSF.cjs +0 -1
- package/dist/RuleEditor-CGl9XY2s.js +0 -2037
- package/dist/assets-CqIbfbTr.js +0 -126
- package/dist/assets-e4YSke8n.cjs +0 -1
- package/dist/capabilities-DDwXr_cA.js +0 -103
- package/dist/capabilities-DNLyZdNw.cjs +0 -1
- package/dist/component-tree-Ca6YYfHq.js +0 -61
- package/dist/component-tree-DkGLEfZC.cjs +0 -1
- package/dist/computed-C-4C2S5h.js +0 -521
- package/dist/computed-CGV2a809.cjs +0 -1
- package/dist/config-Dg_o8e7m.cjs +0 -1
- package/dist/config-XQ4qrQ7Q.js +0 -844
- package/dist/dataset-BkRmwgeJ.cjs +0 -1
- package/dist/dataset-H5pFuQGU.js +0 -121
- package/dist/designer-BfQSahxq.js +0 -5163
- package/dist/designer-CPPdeM5_.cjs +0 -2
- package/dist/diagnostic-notification-B9K9We3h.cjs +0 -1
- package/dist/diagnostic-notification-qGAYZdkB.js +0 -7
- package/dist/drill-CsdjgkRM.cjs +0 -1
- package/dist/drill-DIGsZfyB.js +0 -145
- package/dist/json-snapshot-D6ioHth9.js +0 -1702
- package/dist/json-snapshot-DknkjvxP.cjs +0 -2
- package/dist/matrix-CGRGkn5s.js +0 -112
- package/dist/matrix-gEO7ZM_u.cjs +0 -1
- package/dist/param-validation-C3HlcLLO.cjs +0 -1
- package/dist/param-validation-Do7Eg8Zv.js +0 -181
- package/dist/record-bindings-DUX1VMlR.cjs +0 -1
- package/dist/runtime-BjKBI530.js +0 -168
- package/dist/runtime-CBFEPKEs.cjs +0 -1
- package/dist/sha256-BshdOkCC.cjs +0 -1
- package/dist/sha256-DTG-Gq8i.js +0 -157
- package/dist/template-bindings-C2SpvsMU.js +0 -58
- package/dist/template-bindings-CEtWyiLX.cjs +0 -1
- package/dist/template-catalog-C2NLdrwB.cjs +0 -1
- package/dist/template-registry-C62vpv4a.cjs +0 -1
- package/dist/tree-BX380Rr7.cjs +0 -1
- package/dist/tree-CjVZLRw7.js +0 -172
|
@@ -0,0 +1,1967 @@
|
|
|
1
|
+
import { R as te } from "./component-tree-CvW4lzpv.js";
|
|
2
|
+
import { r as re, L as ve, b as Gt, i as Vt, f as N, D as Ve } from "./style-67OqfNed.js";
|
|
3
|
+
import { w as z, h as We } from "./textwrap-BEIg2w8y.js";
|
|
4
|
+
import { e as Me, k as L, b as Se, n as K, o as Wt, q as Jt } from "./computed-C8NRZQss.js";
|
|
5
|
+
import { c as Je, R as I, g as ze, b as zt, i as _t, l as xe, t as _e, h as qe, f as Ue, j as qt, k as Ut } from "./record-bindings-DEJtmo3p.js";
|
|
6
|
+
import { a as Xt, c as Yt } from "./charts-Dlv8j2AG.js";
|
|
7
|
+
import { b as Qt, c as Zt, e as er } from "./matrix-Dy-tyY7E.js";
|
|
8
|
+
import { r as oe } from "./grid-geometry-BNptEcMm.js";
|
|
9
|
+
import { f as Xe, b as tr, d as rr, c as Ye } from "./column-visual-BpgQVWwT.js";
|
|
10
|
+
import { i as or, r as nr, j as ar, b as Qe, v as sr, R as ir } from "./template-registry-BIhIHOab.js";
|
|
11
|
+
import { g as cr } from "./report-params-D9tBuM9B.js";
|
|
12
|
+
import { a as Oe } from "./param-validation-CnDEd2l-.js";
|
|
13
|
+
import { f as lr, i as dr } from "./number-format-BA_KwrZe.js";
|
|
14
|
+
import { v as Ze, d as ur } from "./dataset-DL83majE.js";
|
|
15
|
+
const fr = 4096, Ae = 128 * 1024;
|
|
16
|
+
function mr(e) {
|
|
17
|
+
const t = /* @__PURE__ */ new Map();
|
|
18
|
+
let r = 0;
|
|
19
|
+
return { measureMm(o, n) {
|
|
20
|
+
const a = JSON.stringify([o, n.fontSizePt, n.fontFamily, n.bold, n.italic, n.letterSpacingPt]), s = t.get(a);
|
|
21
|
+
if (s !== void 0)
|
|
22
|
+
return t.delete(a), t.set(a, s), s;
|
|
23
|
+
const i = e.measureMm(o, n);
|
|
24
|
+
if (Number.isFinite(i) && a.length <= Ae) {
|
|
25
|
+
for (; t.size >= fr || r + a.length > Ae; ) {
|
|
26
|
+
const c = t.keys().next().value;
|
|
27
|
+
r -= c.length, t.delete(c);
|
|
28
|
+
}
|
|
29
|
+
t.set(a, i), r += a.length;
|
|
30
|
+
}
|
|
31
|
+
return i;
|
|
32
|
+
} };
|
|
33
|
+
}
|
|
34
|
+
class G extends Error {
|
|
35
|
+
constructor(t, r) {
|
|
36
|
+
super(`报表页数超出上限 ${t}(至少 ${r} 页)`), this.limit = t, this.actual = r, this.code = "page-limit", this.name = "PaginatePageLimitError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class X extends Error {
|
|
40
|
+
constructor(t, r) {
|
|
41
|
+
super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`), this.limit = t, this.actual = r, this.code = "cell-limit", this.name = "PaginateCellLimitError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class Y extends Error {
|
|
45
|
+
constructor(t, r) {
|
|
46
|
+
super(`报表图表图元数量预计超出上限 ${t}(本次估算 ${r})`), this.limit = t, this.estimated = r, this.code = "chart-component-limit", this.name = "PaginateChartComponentLimitError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const Ce = 5e4;
|
|
50
|
+
function ne(e = Ce) {
|
|
51
|
+
if (!Number.isSafeInteger(e) || e < 1 || e > 1e6) throw new RangeError("maxChartComponents 应为 1..1000000 的安全整数");
|
|
52
|
+
}
|
|
53
|
+
function hr(e, t, r) {
|
|
54
|
+
const o = e.chartBinding;
|
|
55
|
+
if (e.kind !== "chart" || e.grid || e.imageData || e.binding || e.pageAnchor) throw new TypeError("绑定图表不能同时设置图片、网格、记录绑定或页眉页脚");
|
|
56
|
+
const n = Object.prototype.hasOwnProperty.call(t, o.dataset) ? t[o.dataset] : void 0;
|
|
57
|
+
if (!Array.isArray(n)) throw new TypeError(`图表数据集 ${o.dataset} 未提供`);
|
|
58
|
+
return { ...Qt(n, o, r), type: o.type, leftMm: e.leftMm, topMm: e.topMm, widthMm: e.widthMm, heightMm: e.heightMm, title: o.title, showValues: o.showValues };
|
|
59
|
+
}
|
|
60
|
+
function gr(e, t, r = Ce) {
|
|
61
|
+
ne(r);
|
|
62
|
+
let o = 0;
|
|
63
|
+
return Object.assign((a) => {
|
|
64
|
+
if (!a.chartBinding) return [a];
|
|
65
|
+
const s = hr(a, e, t), i = o + (s.categories.length ? Xt(s) : 1);
|
|
66
|
+
if (!Number.isSafeInteger(i)) throw new RangeError("图表图元估算应为有限安全整数");
|
|
67
|
+
if (i > r) throw new Y(r, i);
|
|
68
|
+
const c = s.categories.length ? Yt(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 } }];
|
|
69
|
+
return o += c.length, c;
|
|
70
|
+
}, { used: () => o });
|
|
71
|
+
}
|
|
72
|
+
function pr(e, t) {
|
|
73
|
+
return { member: "body", subtotal: "subtotal", total: "grand-total" }[e?.rows.get(t)?.kind ?? "member"];
|
|
74
|
+
}
|
|
75
|
+
function wr(e) {
|
|
76
|
+
const t = e.matrix;
|
|
77
|
+
if (!t.hierarchy) return t;
|
|
78
|
+
const r = new Map(e.columns.map((n) => [n.field, n.header])), o = { sum: "求和", count: "计数", avg: "平均", min: "最小", max: "最大", weightedAvg: "加权平均" };
|
|
79
|
+
return { ...t, hierarchy: {
|
|
80
|
+
...t.hierarchy,
|
|
81
|
+
row: { ...t.hierarchy.row, labels: t.hierarchy.row?.labels ?? t.rowFields.map((n) => r.get(n) ?? n) },
|
|
82
|
+
column: { ...t.hierarchy.column, labels: t.hierarchy.column?.labels ?? t.columnFields.map((n) => r.get(n) ?? n) }
|
|
83
|
+
}, measures: t.measures.map((n) => {
|
|
84
|
+
const a = r.get(n.field) ?? r.get(n.valueField ?? n.field);
|
|
85
|
+
return n.label === void 0 && a ? { ...n, label: `${a}(${o[n.op]})` } : n;
|
|
86
|
+
}) };
|
|
87
|
+
}
|
|
88
|
+
function yr(e, t) {
|
|
89
|
+
if (!e.matrix) return { list: e, rows: t };
|
|
90
|
+
if (e.detail || e.groupBy || e.groups?.length || e.grandTotal) throw new Error("矩阵不能同时配置普通分组、总计或主从明细");
|
|
91
|
+
const r = Zt(t, wr(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 };
|
|
92
|
+
e.layout === "wide" && (n.widthMm = o.reduce((i, c) => i + c.widthMm, 0));
|
|
93
|
+
const a = r.metadata, s = a ? { rows: new WeakMap(r.rows.map((i, c) => [i, a.rows[c]])), header: {
|
|
94
|
+
columns: a.columns,
|
|
95
|
+
rowFields: a.rowFields,
|
|
96
|
+
rowLabels: a.rowLabels,
|
|
97
|
+
columnFields: a.columnFields,
|
|
98
|
+
columnLabels: a.columnLabels
|
|
99
|
+
} } : void 0;
|
|
100
|
+
return { list: n, rows: r.rows, ...s ? { matrix: s } : {} };
|
|
101
|
+
}
|
|
102
|
+
function br(e, t) {
|
|
103
|
+
if (!e.matrix?.hierarchy || !e.headerGrid) return e.headerGrid;
|
|
104
|
+
const r = e.paddingMm ?? 1, o = e.headerGrid.cells.map(() => e.rowHeightMm ?? 0), n = e.columns.map((c) => c.widthMm), a = oe({ ...e.headerGrid, colWidthsMm: n }, n.reduce((c, l) => c + l, 0), o.length), s = /* @__PURE__ */ new WeakMap();
|
|
105
|
+
for (const { cell: c, ci: l, ri: d, widthMm: f } of a.cells) {
|
|
106
|
+
const u = { ...Je(e, e.columns[l]), ...c.style }, h = re(u).fontSizePt, v = (z(c.text ?? "", Math.max(1, f - r * 2), { fontSizePt: h, fontFamily: u.fontFamily, bold: u.bold, italic: u.italic, letterSpacingPt: u.letterSpacing }, t).length * h * (u.lineHeight ?? ve) * 25.4 / 72 + r * 2) / (c.rowSpan ?? 1);
|
|
107
|
+
for (let y = d; y < d + (c.rowSpan ?? 1); y++) o[y] = Math.max(o[y] ?? 0, v);
|
|
108
|
+
s.set(c, u);
|
|
109
|
+
}
|
|
110
|
+
const i = e.headerGrid.cells.map((c) => c.map((l) => l ? { ...l, style: s.get(l) } : null));
|
|
111
|
+
return { ...e.headerGrid, cells: i, rowHeightsMm: o };
|
|
112
|
+
}
|
|
113
|
+
function vr(e, t, r) {
|
|
114
|
+
const o = /* @__PURE__ */ new Set(), n = e.cells.map((a, s) => {
|
|
115
|
+
const i = [];
|
|
116
|
+
let c = 0;
|
|
117
|
+
for (const l of a) {
|
|
118
|
+
for (; o.has(`${s}:${c}`); ) c++;
|
|
119
|
+
const d = l?.colSpan ?? 1, f = l?.rowSpan ?? 1;
|
|
120
|
+
let u = 0;
|
|
121
|
+
for (let h = c; h < c + d; h++) {
|
|
122
|
+
t.has(h) && u++;
|
|
123
|
+
for (let m = s + 1; m < s + f; m++)
|
|
124
|
+
o.add(`${m}:${h}`);
|
|
125
|
+
}
|
|
126
|
+
u && i.push(l ? { ...l, colSpan: u } : null), c += d;
|
|
127
|
+
}
|
|
128
|
+
return i;
|
|
129
|
+
});
|
|
130
|
+
return { ...e, cells: n, colWidthsMm: r };
|
|
131
|
+
}
|
|
132
|
+
function Mr(e) {
|
|
133
|
+
if (!e.columns.some((o) => o.hidden)) return e;
|
|
134
|
+
const t = /* @__PURE__ */ new Set(), r = e.columns.filter((o, n) => o.hidden ? !1 : (t.add(n), !0));
|
|
135
|
+
if (!r.length) throw new Error("列表至少需要一列可见列");
|
|
136
|
+
return {
|
|
137
|
+
...e,
|
|
138
|
+
columns: r,
|
|
139
|
+
...e.headerGrid ? {
|
|
140
|
+
headerGrid: vr(
|
|
141
|
+
e.headerGrid,
|
|
142
|
+
t,
|
|
143
|
+
r.map((o) => o.widthMm)
|
|
144
|
+
)
|
|
145
|
+
} : {}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function* Sr(e) {
|
|
149
|
+
const { page: t } = e;
|
|
150
|
+
or(t.components, t.flow);
|
|
151
|
+
let r = 0, o = 0;
|
|
152
|
+
for (const n of nr(t.components, t.flow)) {
|
|
153
|
+
e.active();
|
|
154
|
+
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);
|
|
155
|
+
let c = Math.max(e.top(), o + a.topMm - r);
|
|
156
|
+
if (!s && i > e.bottom() - e.top() + 1e-3) throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);
|
|
157
|
+
!s && c + i > e.bottom() + 1e-3 && (e.nextPage(), yield* e.takePages(), e.active(), c = e.top());
|
|
158
|
+
let l = c + i;
|
|
159
|
+
for (const d of n.components) {
|
|
160
|
+
const f = c + d.topMm - a.topMm;
|
|
161
|
+
d.kind === "list" ? (yield* e.list(d, f, (u) => {
|
|
162
|
+
l = s ? u : Math.max(l, u);
|
|
163
|
+
}), e.active()) : e.append({ ...d, topMm: f });
|
|
164
|
+
}
|
|
165
|
+
o = l, r = a.topMm + a.heightMm;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function xr(e) {
|
|
169
|
+
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));
|
|
170
|
+
}
|
|
171
|
+
function ae(e) {
|
|
172
|
+
return e.pages.some((t) => t.components.some((r) => r.kind === "list" ? xr(r) : !!r.chartBinding));
|
|
173
|
+
}
|
|
174
|
+
const Cr = 512, Ne = 256 * 1024;
|
|
175
|
+
function kr() {
|
|
176
|
+
const e = /* @__PURE__ */ new Map();
|
|
177
|
+
let t = 0, r;
|
|
178
|
+
return (o, n, a, s) => {
|
|
179
|
+
s !== r && (e.clear(), t = 0, r = s);
|
|
180
|
+
const i = JSON.stringify([o, n, a.fontSizePt, a.fontFamily, a.bold, a.italic, a.letterSpacingPt]), c = e.get(i);
|
|
181
|
+
if (c)
|
|
182
|
+
return e.delete(i), e.set(i, c), c.lines.slice();
|
|
183
|
+
const l = z(o, n, a, s), d = i.length + l.reduce((f, u) => f + u.length, 0);
|
|
184
|
+
if (d <= Ne) {
|
|
185
|
+
for (; e.size >= Cr || t + d > Ne; ) {
|
|
186
|
+
const f = e.keys().next().value;
|
|
187
|
+
t -= e.get(f).units, e.delete(f);
|
|
188
|
+
}
|
|
189
|
+
e.set(i, { lines: l.slice(), units: d }), t += d;
|
|
190
|
+
}
|
|
191
|
+
return l;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const Er = 1e4, Ke = 25e4;
|
|
195
|
+
function ke(e) {
|
|
196
|
+
if (e?.aborted) throw e.reason ?? new DOMException("标签生成已取消", "AbortError");
|
|
197
|
+
}
|
|
198
|
+
function et(e, t, r) {
|
|
199
|
+
const o = typeof e.copies == "object" ? ze(t, e.copies.field, r) : e.copies ?? 1;
|
|
200
|
+
if (typeof o != "number" || !Number.isSafeInteger(o) || o < 1 || o > 1e3) throw new I(`$.datasets.${r.dataset}[${r.rowIndex}]`, "每条记录复制数必须是 1..1000 的数值型整数", r.rowIndex, typeof e.copies == "object" ? e.copies.field : void 0);
|
|
201
|
+
return o;
|
|
202
|
+
}
|
|
203
|
+
function tt(e, t, r) {
|
|
204
|
+
if (e.rowKey === void 0) return;
|
|
205
|
+
const o = ze(t, e.rowKey, r);
|
|
206
|
+
if (typeof o == "string" && o.trim() || typeof o == "number" && Number.isFinite(o)) return o;
|
|
207
|
+
throw new I(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`, "业务主键必须是非空字符串或有限数字", r.rowIndex, e.rowKey);
|
|
208
|
+
}
|
|
209
|
+
function Tr(e) {
|
|
210
|
+
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);
|
|
211
|
+
return e.pages.reduce((r, o) => r + o.components.reduce((n, a) => n + t(a), 0), 0);
|
|
212
|
+
}
|
|
213
|
+
function Pr(e, t, r) {
|
|
214
|
+
const o = e.repeat, n = Object.prototype.hasOwnProperty.call(t, o.dataset) ? t[o.dataset] : void 0;
|
|
215
|
+
if (!Array.isArray(n)) throw new I(`$.datasets.${o.dataset}`, "逐记录标签数据集缺失,应提供对象数组(允许空数组)");
|
|
216
|
+
const a = /* @__PURE__ */ new Set(), s = r.maxPages ?? Er, i = Tr(e);
|
|
217
|
+
let c = 0, l = 0;
|
|
218
|
+
for (const [d, f] of n.entries()) {
|
|
219
|
+
if (ke(r.signal), !f || typeof f != "object" || Array.isArray(f)) throw new I(`$.datasets.${o.dataset}[${d}]`, "标签记录应为对象", d);
|
|
220
|
+
const u = { rowIndex: d, dataset: o.dataset }, h = tt(o, f, u);
|
|
221
|
+
if (h !== void 0) {
|
|
222
|
+
const v = JSON.stringify([typeof h, h]);
|
|
223
|
+
if (a.has(v)) throw new I(`$.datasets.${o.dataset}[${d}].${o.rowKey}`, "业务主键重复;请先确认记录来源,避免重复打印标签", d, o.rowKey);
|
|
224
|
+
a.add(v);
|
|
225
|
+
}
|
|
226
|
+
const m = et(o, f, u);
|
|
227
|
+
if (c += m * e.pages.length, l += m * i, c > s) throw new G(s, c);
|
|
228
|
+
if (l > Ke) throw new I("$.repeat", `标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Ke},请分批生成`, d);
|
|
229
|
+
}
|
|
230
|
+
return n;
|
|
231
|
+
}
|
|
232
|
+
function Rr(e, t, r) {
|
|
233
|
+
if (!e.binding) return e;
|
|
234
|
+
const { binding: o, ...n } = e, a = zt(o, t.row, t);
|
|
235
|
+
if (e.kind === "image") {
|
|
236
|
+
if (!a) return;
|
|
237
|
+
if (!_t(a)) throw new I(`${r}.binding`, "图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换", t.rowIndex, o.field);
|
|
238
|
+
return { ...n, imageData: a };
|
|
239
|
+
}
|
|
240
|
+
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 });
|
|
241
|
+
}
|
|
242
|
+
function $r(e, t, r) {
|
|
243
|
+
if (e.kind !== "text" || e.grid || e.richParagraphs?.length) return e;
|
|
244
|
+
const o = e.style ?? {}, n = re(o).fontSizePt, a = e.text ?? e.lines?.join(`
|
|
245
|
+
`) ?? "";
|
|
246
|
+
if (a.length > 16384) throw new I(r, "标签文本超过 16384 字符预算,请缩小字段内容", t.rowIndex);
|
|
247
|
+
const s = t.wrapText(a, e.widthMm, { fontSizePt: n, bold: o.bold, italic: o.italic, fontFamily: o.fontFamily, letterSpacingPt: o.letterSpacing }, t.options.measurer ?? We), i = s.length * n * Gt(o) * 25.4 / 72;
|
|
248
|
+
if (i > e.heightMm + 0.05) throw new I(r, `标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`, t.rowIndex, e.binding?.field);
|
|
249
|
+
return { ...e, lines: s };
|
|
250
|
+
}
|
|
251
|
+
function rt(e, t, r) {
|
|
252
|
+
ke(t.options.signal);
|
|
253
|
+
const o = Rr(e, t, r);
|
|
254
|
+
if (!o) return;
|
|
255
|
+
let n = o.grid;
|
|
256
|
+
return n && (n = { ...n, cells: n.cells.map((a, s) => a.map((i, c) => i?.children?.length ? { ...i, children: i.children.flatMap((l, d) => {
|
|
257
|
+
const f = rt(l, t, `${r}.grid.cells.${s}.${c}.children.${d}`);
|
|
258
|
+
return f ? [f] : [];
|
|
259
|
+
}) } : i)) }), $r(n === o.grid ? o : { ...o, grid: n }, t, r);
|
|
260
|
+
}
|
|
261
|
+
function Ir(e, t, r, o, n, a) {
|
|
262
|
+
return {
|
|
263
|
+
...e,
|
|
264
|
+
components: e.components.flatMap((s, i) => {
|
|
265
|
+
const c = rt(s, r, `$.pages.${t}.components.${i}`);
|
|
266
|
+
return c ? [{ ...c, meta: { ...c.meta, labelSource: { pageIndex: t, componentIndex: i } } }] : [];
|
|
267
|
+
}),
|
|
268
|
+
meta: { ...e.meta, record: { dataset: r.dataset, rowIndex: r.rowIndex, ...a === void 0 ? {} : { rowKey: a }, copyIndex: o, copyCount: n, templatePageIndex: t } }
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function* Fr(e, t, r) {
|
|
272
|
+
const o = [];
|
|
273
|
+
if (ar(e, o), o.length) throw new I(o[0].path, o[0].message);
|
|
274
|
+
if (!e.repeat) {
|
|
275
|
+
for (const [i, c] of e.pages.entries()) yield { page: c, pageIndex: i };
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const n = e.repeat, a = Pr(e, t, r), s = kr();
|
|
279
|
+
for (const [i, c] of a.entries()) {
|
|
280
|
+
const l = { row: c, rowIndex: i, dataset: n.dataset, options: r, wrapText: s }, d = et(n, c, l), f = tt(n, c, l);
|
|
281
|
+
for (let u = 0; u < d; u++) for (const [h, m] of e.pages.entries())
|
|
282
|
+
ke(r.signal), yield { page: Ir(m, h, l, u, d, f), pageIndex: h };
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function Or(e) {
|
|
286
|
+
return {
|
|
287
|
+
widthMm: e.widthMm,
|
|
288
|
+
heightMm: e.heightMm,
|
|
289
|
+
marginTopMm: e.marginTopMm ?? 0,
|
|
290
|
+
marginBottomMm: e.marginBottomMm ?? 0,
|
|
291
|
+
marginLeftMm: e.marginLeftMm ?? 0,
|
|
292
|
+
marginRightMm: e.marginRightMm ?? 0,
|
|
293
|
+
components: []
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function Q(e, t) {
|
|
297
|
+
const r = t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
|
|
298
|
+
return e.components.reduce((o, n) => n.kind !== "list" && n.pageAnchor === "footer" ? Math.min(o, n.topMm) : o, r);
|
|
299
|
+
}
|
|
300
|
+
function V(e) {
|
|
301
|
+
return e.components.reduce((t, r) => r.kind !== "list" && r.pageAnchor === "header" ? Math.max(t, r.topMm + r.heightMm) : t, 0);
|
|
302
|
+
}
|
|
303
|
+
function ot(e, t) {
|
|
304
|
+
let r = e.textMetrics.get(t);
|
|
305
|
+
if (!r) {
|
|
306
|
+
const o = re(t).fontSizePt;
|
|
307
|
+
r = {
|
|
308
|
+
measureOptions: {
|
|
309
|
+
fontSizePt: o,
|
|
310
|
+
fontFamily: t.fontFamily ?? Ve,
|
|
311
|
+
italic: t.italic,
|
|
312
|
+
bold: t.bold,
|
|
313
|
+
letterSpacingPt: t.letterSpacing
|
|
314
|
+
},
|
|
315
|
+
lineMm: o * (t.lineHeight ?? ve) * 25.4 / 72
|
|
316
|
+
}, e.textMetrics.set(t, r);
|
|
317
|
+
}
|
|
318
|
+
return r;
|
|
319
|
+
}
|
|
320
|
+
function Ar(e) {
|
|
321
|
+
if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
|
|
322
|
+
}
|
|
323
|
+
function Ee(e, t, r = [], o) {
|
|
324
|
+
const n = e.fontSizePt ?? Vt, a = e.paddingMm ?? 1, s = e.columns.map((g) => g.align ?? g.style?.align ?? e.align ?? "left"), i = e.columns.map((g, w) => ({
|
|
325
|
+
...N({
|
|
326
|
+
fontSize: n,
|
|
327
|
+
verticalAlign: "middle"
|
|
328
|
+
}, g.style),
|
|
329
|
+
align: s[w] === "auto" ? "left" : s[w]
|
|
330
|
+
})), c = i.map((g, w) => s[w] === "auto" ? { left: g, center: { ...g, align: "center" }, right: { ...g, align: "right" } } : void 0), l = e.columns.map((g, w) => g.rules?.map((x) => {
|
|
331
|
+
const P = c[w];
|
|
332
|
+
if (P) return {
|
|
333
|
+
left: N(P.left, x.style),
|
|
334
|
+
center: N(P.center, x.style),
|
|
335
|
+
right: N(P.right, x.style)
|
|
336
|
+
};
|
|
337
|
+
const E = N(i[w], x.style);
|
|
338
|
+
return { left: E, center: E, right: E };
|
|
339
|
+
})), d = e.columns.map((g) => Je(e, g)), f = e.columns.map((g) => g.header);
|
|
340
|
+
let u = e.rowHeightMm ?? 0;
|
|
341
|
+
for (let g = 0; g < f.length; g++) {
|
|
342
|
+
const w = d[g], x = re(w).fontSizePt, P = z(
|
|
343
|
+
f[g],
|
|
344
|
+
e.columns[g].widthMm - a * 2,
|
|
345
|
+
{ fontSizePt: x, fontFamily: w.fontFamily ?? Ve, italic: w.italic, bold: w.bold, letterSpacingPt: w.letterSpacing },
|
|
346
|
+
t
|
|
347
|
+
), E = x * (w.lineHeight ?? ve) * 25.4 / 72;
|
|
348
|
+
u = Math.max(u, Math.max(P.length, 1) * E + a * 2);
|
|
349
|
+
}
|
|
350
|
+
const h = f.map((g, w) => ({
|
|
351
|
+
text: g,
|
|
352
|
+
style: d[w]
|
|
353
|
+
})), m = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, v = e.columns.map((g) => g.widthMm), y = Nr(br(e, t), v, {
|
|
354
|
+
cells: [h],
|
|
355
|
+
colWidthsMm: v,
|
|
356
|
+
rowHeightsMm: [u],
|
|
357
|
+
paddingMm: a
|
|
358
|
+
});
|
|
359
|
+
return {
|
|
360
|
+
fontSizePt: n,
|
|
361
|
+
paddingMm: a,
|
|
362
|
+
visuals: rr(e.columns, r, o),
|
|
363
|
+
visibility: e.columns.map((g) => g.visibleWhen ? L(g.visibleWhen) : void 0),
|
|
364
|
+
ruleReaders: e.columns.map((g) => g.rules?.map((w) => L(w.when))),
|
|
365
|
+
cellStyles: i,
|
|
366
|
+
autoStyles: c,
|
|
367
|
+
ruleStyles: l,
|
|
368
|
+
textMetrics: /* @__PURE__ */ new WeakMap(),
|
|
369
|
+
numberFormats: e.columns.map((g) => _e(g.format)),
|
|
370
|
+
derivedFields: new Set(e.computed?.map((g) => g.field)),
|
|
371
|
+
borderStyle: m,
|
|
372
|
+
headerHeightMm: y.rowHeightsMm.reduce((g, w) => g + w, 0),
|
|
373
|
+
headerGrid: y,
|
|
374
|
+
colWidthsMm: v,
|
|
375
|
+
columns: e.columns
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function Nr(e, t, r) {
|
|
379
|
+
if (!e) return r;
|
|
380
|
+
if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
|
|
381
|
+
const o = e.rowHeightsMm ?? e.cells.map(() => r.rowHeightsMm[0]);
|
|
382
|
+
if (o.length !== e.cells.length || o.some((n) => !Number.isFinite(n) || n <= 0)) throw new Error("自定义列表表头行高无效");
|
|
383
|
+
return { ...e, colWidthsMm: t, rowHeightsMm: o };
|
|
384
|
+
}
|
|
385
|
+
function Kr(e, t, r) {
|
|
386
|
+
const o = t.format?.kind === "number" || t.format?.kind === "percent";
|
|
387
|
+
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);
|
|
388
|
+
}
|
|
389
|
+
function W(e, t, r) {
|
|
390
|
+
const o = e.columns, n = e.tree?.rows.get(t);
|
|
391
|
+
let a = e.rowHeightFloorMm;
|
|
392
|
+
const s = new Array(o.length);
|
|
393
|
+
for (let i = 0; i < o.length; i++) {
|
|
394
|
+
const c = o[i], l = e.visibility[i]?.(t) !== !1, d = l ? t[c.field] : null, f = e.autoStyles[i] ? qe(d, c.format, c.semanticRole) : "left";
|
|
395
|
+
let u = e.autoStyles[i]?.[f] ?? e.cellStyles[i];
|
|
396
|
+
if (c.rules) {
|
|
397
|
+
for (let x = 0; x < c.rules.length; x++)
|
|
398
|
+
if (e.ruleReaders[i][x](t)) {
|
|
399
|
+
u = e.ruleStyles[i][x][f];
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const h = c.format ? Ue(d, c.format) : xe(d), m = jr(e, c, n);
|
|
404
|
+
u = Lr(e, c, u, n);
|
|
405
|
+
const v = ot(e, u), y = z(h, Math.max(1, c.widthMm - e.paddingMm * 2 - m), v.measureOptions, r);
|
|
406
|
+
a = Math.max(a, y.length * v.lineMm + e.paddingMm * 2);
|
|
407
|
+
const g = Ar(d), w = { text: h, style: u };
|
|
408
|
+
d != null && e.visuals[i]?.apply(w, t), g !== void 0 && (w.value = g), Kr(w, c, e.numberFormats[i]), Hr(w, c, e, n, m), e.derivedFields.has(c.field) && (w.derived = !0, w.editable = !1), l || (w.editable = !1), s[i] = w;
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
grid: { cells: [s], colWidthsMm: e.colWidthsMm, rowHeightsMm: [a], paddingMm: e.paddingMm },
|
|
412
|
+
heightMm: a,
|
|
413
|
+
...e.matrix ? { meta: { matrix: { row: e.matrix.rows.get(t) } } } : {}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function jr(e, t, r) {
|
|
417
|
+
return !r || t.field !== e.tree.list.tree.labelField ? 0 : qt(e.tree.list, t, r, e.paddingMm);
|
|
418
|
+
}
|
|
419
|
+
function Lr(e, t, r, o) {
|
|
420
|
+
return !o || t.field !== e.tree.list.tree.labelField || r.align === "left" ? r : { ...r, align: "left" };
|
|
421
|
+
}
|
|
422
|
+
function Hr(e, t, r, o, n = 0) {
|
|
423
|
+
o && (n && (e.indentMm = n), Ut(e, t, o, r.tree.list));
|
|
424
|
+
}
|
|
425
|
+
function nt(e) {
|
|
426
|
+
if (e != null && typeof e != "string" && typeof e != "boolean" && !(typeof e == "number" && Number.isFinite(e))) throw new Error("分组字段应为有限 JSON 标量");
|
|
427
|
+
return JSON.stringify([typeof e, e ?? null]);
|
|
428
|
+
}
|
|
429
|
+
function* at(e, t, r = 0) {
|
|
430
|
+
const o = t[r];
|
|
431
|
+
if (!o) {
|
|
432
|
+
for (const a of e) yield { kind: "row", row: a };
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const n = /* @__PURE__ */ new Map();
|
|
436
|
+
for (const a of e) {
|
|
437
|
+
const s = nt(a[o.field]), i = n.get(s);
|
|
438
|
+
i ? i.push(a) : n.set(s, [a]);
|
|
439
|
+
}
|
|
440
|
+
for (const a of n.values())
|
|
441
|
+
yield { kind: "groupHeader", label: (o.headerTemplate ?? "{value}").replace(/\{value\}/g, xe(a[0][o.field])), firstRow: a[0], group: o, depth: r, rows: a }, yield* at(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 };
|
|
442
|
+
}
|
|
443
|
+
function st(e, t, r, o = []) {
|
|
444
|
+
const n = [...r.filter((a) => !o.some((s) => s.field === a)).map((a) => ({ field: a, op: "sum" })), ...o];
|
|
445
|
+
return new Map(n.map((a) => {
|
|
446
|
+
const s = e.find((c) => c.field === a.field)?.format ?? { kind: "number", thousands: !0 }, i = Se(t, { ...a, field: a.valueField ?? a.field });
|
|
447
|
+
return [a.field, { text: Ue(i, s), ...i === null ? {} : { value: i }, ...typeof i == "number" ? { numberFormat: _e(s) } : {} }];
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
function it(e, t) {
|
|
451
|
+
const r = e.findIndex((o) => t.includes(o.field));
|
|
452
|
+
return r < 0 ? 1 : r;
|
|
453
|
+
}
|
|
454
|
+
function B(e, t, r, o, n, a) {
|
|
455
|
+
const s = [], i = Math.max(0, Math.min(a, e.columns.length)), c = N({ fontSize: e.fontSizePt }, n);
|
|
456
|
+
i && s.push({ text: r, colSpan: i, style: { bold: !0, ...c } });
|
|
457
|
+
for (let u = i; u < e.columns.length; u++) {
|
|
458
|
+
const h = e.columns[u], m = o.get(h.field), v = e.autoStyles[u]?.[qe(m?.value, h.format)] ?? e.cellStyles[u];
|
|
459
|
+
s.push({ ...m, text: m?.text ?? "", style: N(v, n) });
|
|
460
|
+
}
|
|
461
|
+
const l = { text: r, colSpan: e.columns.length, style: { bold: !0, ...c } }, d = i ? [s] : [[l], s], f = d.map((u) => Dr(e, u, t));
|
|
462
|
+
return {
|
|
463
|
+
grid: { cells: d, colWidthsMm: e.colWidthsMm, rowHeightsMm: f, paddingMm: e.paddingMm },
|
|
464
|
+
heightMm: f.reduce((u, h) => u + h, 0)
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function Dr(e, t, r) {
|
|
468
|
+
let o = e.rowHeightFloorMm, n = 0;
|
|
469
|
+
for (const a of t) {
|
|
470
|
+
let s = 0;
|
|
471
|
+
const i = n + (a.colSpan ?? 1);
|
|
472
|
+
for (; n < i; n++) s += e.colWidthsMm[n] ?? 0;
|
|
473
|
+
const c = ot(e, a.style), l = z(a.text ?? "", s - e.paddingMm * 2, c.measureOptions, r);
|
|
474
|
+
o = Math.max(o, l.length * c.lineMm + e.paddingMm * 2);
|
|
475
|
+
}
|
|
476
|
+
return o;
|
|
477
|
+
}
|
|
478
|
+
function Br(e, t, r) {
|
|
479
|
+
const { templatePage: o, current: n, warnings: a, nextId: s, pushCurrent: i } = r, c = () => Q(o, n), l = Math.max(n.marginTopMm, V(o)), d = o.layout === "wide" ? V(o) : l, f = {
|
|
480
|
+
id: r.tableId,
|
|
481
|
+
columnKeys: e.columns.map((p) => p.field),
|
|
482
|
+
...e.layout === void 0 ? {} : { layout: e.layout },
|
|
483
|
+
...e.title === void 0 ? {} : { title: e.title }
|
|
484
|
+
}, u = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), m = {
|
|
485
|
+
kind: "rect",
|
|
486
|
+
leftMm: e.leftMm,
|
|
487
|
+
topMm: 0,
|
|
488
|
+
widthMm: e.widthMm,
|
|
489
|
+
heightMm: t.headerHeightMm,
|
|
490
|
+
grid: t.headerGrid,
|
|
491
|
+
nid: s("listh"),
|
|
492
|
+
table: { ...f, role: "header", rowIndex: -1 },
|
|
493
|
+
style: t.borderStyle,
|
|
494
|
+
...e.meta || t.matrix ? { meta: { ...e.meta, ...t.matrix ? { matrix: t.matrix.header } : {} } } : {}
|
|
495
|
+
}, v = (p) => n.components.push({ ...m, topMm: p });
|
|
496
|
+
if (r.flow && e.header !== !1 && t.headerHeightMm > c() - l + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的表头高度超出单页可用范围`);
|
|
497
|
+
let y = Math.max(r.startTop ?? e.topMm, l);
|
|
498
|
+
e.header !== !1 && (v(y), y += t.headerHeightMm + r.mmPerRow);
|
|
499
|
+
function g() {
|
|
500
|
+
const p = Math.max(r.flow || o.layout === "wide" ? 0 : e.topMm, d);
|
|
501
|
+
return (e.header !== !1 && e.headerEveryPage !== !1 ? p + t.headerHeightMm : d) + [...h.values()].reduce((S, T) => S + T.heightMm, 0);
|
|
502
|
+
}
|
|
503
|
+
function w() {
|
|
504
|
+
const p = o.layout === "wide" ? 0 : n.marginBottomMm;
|
|
505
|
+
return Math.min(o.heightMm - p, Q(o, n)) - g();
|
|
506
|
+
}
|
|
507
|
+
function x(p) {
|
|
508
|
+
if (y + p <= c()) return;
|
|
509
|
+
i(), n.components = [], n.heightMm = o.heightMm, o.layout === "wide" && (n.marginTopMm = 0, n.marginBottomMm = 0);
|
|
510
|
+
const b = Math.max(r.flow || o.layout === "wide" ? 0 : e.topMm, d);
|
|
511
|
+
e.header !== !1 && e.headerEveryPage !== !1 ? (v(b), y = b + t.headerHeightMm) : y = d;
|
|
512
|
+
for (const S of h.values()) E(S, "listgr", "group-header");
|
|
513
|
+
}
|
|
514
|
+
function P(p, b, S, T) {
|
|
515
|
+
const k = w();
|
|
516
|
+
if (r.flow && p.heightMm > k + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的单行高度超出单页可用范围`);
|
|
517
|
+
p.heightMm > k && a.push(`列表 ${e.id ?? e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${k.toFixed(2)}mm,预览与打印可能截断内容`), x(p.heightMm), E(p, b, S, T);
|
|
518
|
+
}
|
|
519
|
+
function E(p, b, S, T) {
|
|
520
|
+
const k = p.table?.id ?? f.id, R = S === "header" ? -1 : u.get(k) ?? 0;
|
|
521
|
+
S !== "header" && u.set(k, R + p.grid.cells.length), n.components.push({
|
|
522
|
+
kind: "rect",
|
|
523
|
+
leftMm: e.leftMm,
|
|
524
|
+
topMm: y,
|
|
525
|
+
widthMm: e.widthMm,
|
|
526
|
+
heightMm: p.heightMm,
|
|
527
|
+
grid: p.grid,
|
|
528
|
+
nid: s(b),
|
|
529
|
+
table: { ...f, ...p.table, role: S, rowIndex: R, ...T ? { source: T } : {} },
|
|
530
|
+
style: t.borderStyle,
|
|
531
|
+
...e.meta || p.meta ? { meta: { ...e.meta, ...p.meta } } : {}
|
|
532
|
+
}), y += p.heightMm;
|
|
533
|
+
}
|
|
534
|
+
function O(p) {
|
|
535
|
+
p <= w() && x(p);
|
|
536
|
+
}
|
|
537
|
+
return { keepTogether: O, placeGridRow: P, setGroupHeader: (p, b) => {
|
|
538
|
+
b ? h.set(p, b) : h.delete(p);
|
|
539
|
+
}, bottom: () => y };
|
|
540
|
+
}
|
|
541
|
+
function Gr(e, t) {
|
|
542
|
+
if (!e.rowKey) return;
|
|
543
|
+
const r = t[e.rowKey];
|
|
544
|
+
if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r)))
|
|
545
|
+
throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);
|
|
546
|
+
const o = e.revisionField ? t[e.revisionField] : void 0, n = e.sourceTokenField ? t[e.sourceTokenField] : void 0;
|
|
547
|
+
if (o !== void 0 && typeof o != "string" && !(typeof o == "number" && Number.isFinite(o))) throw new Error("业务修订号应为字符串或有限数字");
|
|
548
|
+
if (n !== void 0 && typeof n != "string") throw new Error("来源令牌应为字符串");
|
|
549
|
+
return { datasetId: e.dataset, rowKey: r, ...o === void 0 ? {} : { revision: o }, ...n === void 0 ? {} : { sourceToken: n } };
|
|
550
|
+
}
|
|
551
|
+
function se(e, t) {
|
|
552
|
+
const r = /* @__PURE__ */ new Map();
|
|
553
|
+
if (!e.rowKey) return r;
|
|
554
|
+
const o = /* @__PURE__ */ new Set();
|
|
555
|
+
for (const n of t) {
|
|
556
|
+
const a = Gr(e, n), s = JSON.stringify(a.rowKey);
|
|
557
|
+
if (o.has(s)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);
|
|
558
|
+
o.add(s), r.set(n, a);
|
|
559
|
+
}
|
|
560
|
+
return r;
|
|
561
|
+
}
|
|
562
|
+
function Vr(e, t, r, o, n) {
|
|
563
|
+
if (!e.grandTotal) return;
|
|
564
|
+
const a = typeof e.grandTotal == "object" ? e.grandTotal : void 0, s = ie(e)[0], i = a?.fields ?? s?.subtotal ?? [], c = a?.aggregates ?? s?.aggregates ?? [];
|
|
565
|
+
if (i.length === 0 && c.length === 0) {
|
|
566
|
+
o.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const l = B(r, o.measurer, a?.label ?? "合计", st(e.columns, t, i, c), a?.style ?? {}, it(e.columns, [...i, ...c.map((d) => d.field)]));
|
|
570
|
+
n.placeGridRow(l, "listgt", "grand-total");
|
|
571
|
+
}
|
|
572
|
+
function J(e) {
|
|
573
|
+
if (e?.aborted) {
|
|
574
|
+
const t = new Error("报表排版已取消");
|
|
575
|
+
throw t.name = "AbortError", t;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function ie(e) {
|
|
579
|
+
const t = e.groups ?? (e.groupBy ? [e.groupBy] : []);
|
|
580
|
+
if (t.length > 16) throw new Error("列表最多支持 16 级分组");
|
|
581
|
+
return t;
|
|
582
|
+
}
|
|
583
|
+
function Te(e) {
|
|
584
|
+
const t = Mr(e), r = t.columns.reduce((n, a) => n + a.widthMm, 0), o = r > t.widthMm ? t.widthMm / r : 1;
|
|
585
|
+
return o === 1 ? t : { ...t, columns: t.columns.map((n) => ({ ...n, widthMm: n.widthMm * o })) };
|
|
586
|
+
}
|
|
587
|
+
function Wr(e, t, r) {
|
|
588
|
+
const o = e.detail;
|
|
589
|
+
if (!o) return;
|
|
590
|
+
const n = /* @__PURE__ */ new Set();
|
|
591
|
+
for (const l of t) {
|
|
592
|
+
const d = he(l[o.parentKey]);
|
|
593
|
+
if (n.has(d)) throw new Error("主从明细的主表关联键重复");
|
|
594
|
+
n.add(d);
|
|
595
|
+
}
|
|
596
|
+
const a = r.datasets[o.dataset] ?? [], s = /* @__PURE__ */ new Map(), i = [];
|
|
597
|
+
for (const l of a) {
|
|
598
|
+
const d = l[o.foreignKey];
|
|
599
|
+
if (!ct(d) && o.unmatched === "ignore") continue;
|
|
600
|
+
const f = he(d);
|
|
601
|
+
if (!n.has(f)) {
|
|
602
|
+
if (o.unmatched !== "ignore") throw new Error(`明细数据集 ${o.dataset} 存在未关联的业务键`);
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
const u = s.get(f);
|
|
606
|
+
u ? u.push(l) : s.set(f, [l]), i.push(l);
|
|
607
|
+
}
|
|
608
|
+
const c = Te({ ...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 });
|
|
609
|
+
return { list: c, inter: { ...Ee(c, r.measurer, i, r.signal), rowHeightFloorMm: c.rowHeightMm ?? 0 }, rows: s, sources: se(c, i) };
|
|
610
|
+
}
|
|
611
|
+
function ct(e) {
|
|
612
|
+
return typeof e == "string" && !!e.trim() || typeof e == "number" && Number.isFinite(e);
|
|
613
|
+
}
|
|
614
|
+
function he(e) {
|
|
615
|
+
if (!ct(e)) throw new Error("主从关联键必须是非空字符串或有限数字");
|
|
616
|
+
return nt(e);
|
|
617
|
+
}
|
|
618
|
+
function* Jr(e, t, r, o, n) {
|
|
619
|
+
if (!r) return;
|
|
620
|
+
const a = r.rows.get(he(t[e.detail.parentKey])) ?? [];
|
|
621
|
+
if (!a.length) return;
|
|
622
|
+
const s = { id: `${o.tableId}:detail`, columnKeys: r.list.columns.map((i) => i.field), title: e.detail.label };
|
|
623
|
+
e.detail.label && n.placeGridRow({ ...B(r.inter, o.measurer, e.detail.label, /* @__PURE__ */ 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();
|
|
624
|
+
for (const i of a)
|
|
625
|
+
J(o.signal), n.placeGridRow({ ...W(r.inter, i, o.measurer), table: s }, "listdr", "body", r.sources.get(i)), yield* o.takePages();
|
|
626
|
+
}
|
|
627
|
+
function lt(e) {
|
|
628
|
+
if (e.matrix || e.detail || e.groups?.length || e.groupBy || e.rowVisibleWhen) throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");
|
|
629
|
+
if (e.rowKey && e.rowKey !== e.tree.idField) throw new Error("树形布局的 rowKey 应与 idField 一致");
|
|
630
|
+
if (!e.columns.some((t) => t.field === e.tree.labelField && !t.hidden)) throw new Error("树形布局需要可见的标签列");
|
|
631
|
+
tr(e.tree, e.computed);
|
|
632
|
+
}
|
|
633
|
+
function zr(e, t, r) {
|
|
634
|
+
lt(e);
|
|
635
|
+
const o = Ye(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 = se(n, o.entries.map((c) => c.original)), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap();
|
|
636
|
+
for (const c of o.entries)
|
|
637
|
+
s.set(c.row, a.get(c.original)), i.set(c.row, c);
|
|
638
|
+
return { list: n, rows: o.rows, sources: s, treeRows: i, totalRows: o.leaves };
|
|
639
|
+
}
|
|
640
|
+
function _r(e, t) {
|
|
641
|
+
if (e.cardinality === "record") {
|
|
642
|
+
if (t.length > 1) throw new Error(`单记录区域 ${e.id ?? e.dataset} 仅允许 0 或 1 行数据`);
|
|
643
|
+
if (e.tree || e.matrix || e.detail || e.groups?.length || e.groupBy || e.grandTotal || e.rowVisibleWhen) throw new Error("单记录区域不能配置树、矩阵、主从、分组、总计或行过滤");
|
|
644
|
+
if (!t.length) return { list: { ...e, columns: e.columns.map((r) => ({ ...r, editable: !1 })) }, rows: [{}], sources: /* @__PURE__ */ new Map() };
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function dt(e, t, r) {
|
|
648
|
+
const o = r.prepared.get(e);
|
|
649
|
+
if (o) return o;
|
|
650
|
+
const n = _r(e, t);
|
|
651
|
+
if (n)
|
|
652
|
+
return r.prepared.set(e, n), n;
|
|
653
|
+
if (e.tree) {
|
|
654
|
+
const c = zr(e, t, r);
|
|
655
|
+
return r.prepared.set(e, c), c;
|
|
656
|
+
}
|
|
657
|
+
let a = e.computed?.length ? Me(t, { fields: e.computed, signal: r.signal, formula: r.formula }).rows : t;
|
|
658
|
+
const s = a === t ? void 0 : new Map(a.map((c, l) => [c, t[l]]));
|
|
659
|
+
e.rowVisibleWhen && (a = a.filter(L(e.rowVisibleWhen)));
|
|
660
|
+
const i = yr(e, a);
|
|
661
|
+
if (!e.matrix) {
|
|
662
|
+
const c = se(e, s ? a.map((l) => s.get(l)) : a);
|
|
663
|
+
i.sources = s ? new Map(a.map((l) => [l, c.get(s.get(l))])) : c;
|
|
664
|
+
}
|
|
665
|
+
return r.prepared.set(e, i), i;
|
|
666
|
+
}
|
|
667
|
+
function qr(e, t, r, o) {
|
|
668
|
+
if (!o.flow) return;
|
|
669
|
+
const { current: n, templatePage: a } = o, s = Math.max(n.marginTopMm, V(a)), i = Math.max(o.startTop ?? e.topMm, s), c = (e.header === !1 ? 0 : t.headerHeightMm) + (r[0] ? W(t, r[0], o.measurer).heightMm : 0);
|
|
670
|
+
i + c <= Q(a, n) + 1e-3 || i <= s + 1e-3 || (o.pushCurrent(), n.components = [], n.heightMm = a.heightMm, a.layout === "wide" && (n.marginTopMm = 0, n.marginBottomMm = 0), o.startTop = Math.max(n.marginTopMm, V(a)));
|
|
671
|
+
}
|
|
672
|
+
function* Ur(e, t, r) {
|
|
673
|
+
const o = dt(e, t, r), n = o.rows;
|
|
674
|
+
e = o.list, e.layout === "wide" && (r.current.widthMm = Math.max(r.current.widthMm, e.leftMm + e.widthMm + r.current.marginRightMm));
|
|
675
|
+
const a = o.sources ?? se(e, n), s = Te(e), i = ie(s), c = { ...Ee(s, r.measurer, n, r.signal), rowHeightFloorMm: s.rowHeightMm ?? 0, matrix: o.matrix, ...o.treeRows ? { tree: { list: s, rows: o.treeRows } } : {} };
|
|
676
|
+
qr(s, c, n, r);
|
|
677
|
+
const l = Br(s, c, r), d = Wr(s, n, r);
|
|
678
|
+
let f;
|
|
679
|
+
for (const u of at(n, i)) {
|
|
680
|
+
if (J(r.signal), u.kind === "row")
|
|
681
|
+
l.placeGridRow(f ?? W(c, u.row, r.measurer), "listr", pr(o.matrix, u.row), a.get(u.row)), f = void 0, yield* r.takePages(), yield* Jr(s, u.row, d, r, l);
|
|
682
|
+
else if (u.kind === "groupHeader") {
|
|
683
|
+
const h = B(c, r.measurer, u.label, /* @__PURE__ */ new Map(), u.group.headerStyle ?? {}, s.columns.length);
|
|
684
|
+
f ??= W(c, u.firstRow, r.measurer);
|
|
685
|
+
const m = i.slice(u.depth + 1).reduce((v, y) => v + B(c, r.measurer, (y.headerTemplate ?? "{value}").replace(/\{value\}/g, xe(u.firstRow[y.field])), /* @__PURE__ */ new Map(), y.headerStyle ?? {}, s.columns.length).heightMm, 0);
|
|
686
|
+
u.group.keepWithNext !== !1 && l.keepTogether(h.heightMm + m + f.heightMm), l.placeGridRow(h, "listg", "group-header"), u.group.repeatHeader && l.setGroupHeader(u.depth, h);
|
|
687
|
+
} else if (u.kind === "subtotal") {
|
|
688
|
+
const h = u.group.subtotal ?? [], m = u.group.aggregates ?? [], v = B(c, r.measurer, u.label, st(s.columns, u.rows, h, m), u.group.subtotalStyle ?? {}, it(s.columns, [...h, ...m.map((y) => y.field)]));
|
|
689
|
+
l.placeGridRow(v, "listst", "subtotal");
|
|
690
|
+
} else l.setGroupHeader(u.depth);
|
|
691
|
+
yield* r.takePages();
|
|
692
|
+
}
|
|
693
|
+
Vr(s, o.totalRows ?? n, c, r, l), r.finished?.(l.bottom()), yield* r.takePages();
|
|
694
|
+
}
|
|
695
|
+
function ce(e) {
|
|
696
|
+
return e.kind !== "list" && (e.pageAnchor !== void 0 || e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}")));
|
|
697
|
+
}
|
|
698
|
+
function le(e, t) {
|
|
699
|
+
return {
|
|
700
|
+
...e,
|
|
701
|
+
...e.text === void 0 ? {} : { text: t(e.text) },
|
|
702
|
+
...e.lines ? { lines: e.lines.map(t) } : {},
|
|
703
|
+
...e.richParagraphs ? { richParagraphs: e.richParagraphs.map((r) => ({ ...r, segments: r.segments.map((o) => ({ ...o, ...o.text === void 0 ? {} : { text: t(o.text) } })) })) } : {},
|
|
704
|
+
...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) => le(n, t)) } : {} } : null)) } } : {}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function Xr(e) {
|
|
708
|
+
let t = !1;
|
|
709
|
+
for (const r of e.pages) for (const o of r.components) ce(o) && le(o, (n) => (n.includes("{totalPages}") && (t = !0), n));
|
|
710
|
+
return t;
|
|
711
|
+
}
|
|
712
|
+
function Yr(e, t, r, o, n, a) {
|
|
713
|
+
const s = {
|
|
714
|
+
pageWidthMm: t.widthMm,
|
|
715
|
+
pageHeightMm: t.heightMm,
|
|
716
|
+
...e.layout === void 0 ? {} : { layout: e.layout },
|
|
717
|
+
marginTopMm: t.marginTopMm,
|
|
718
|
+
marginBottomMm: t.marginBottomMm,
|
|
719
|
+
marginLeftMm: t.marginLeftMm,
|
|
720
|
+
marginRightMm: t.marginRightMm,
|
|
721
|
+
components: t.components,
|
|
722
|
+
...e.meta ? { meta: e.meta } : {}
|
|
723
|
+
}, i = (c) => {
|
|
724
|
+
const l = c.replace(/\{page\}/g, String(o));
|
|
725
|
+
return a === void 0 ? l : l.replace(/\{totalPages\}/g, String(a));
|
|
726
|
+
};
|
|
727
|
+
for (const c of r) s.components.push(le(c, i));
|
|
728
|
+
if (e.layout === "wide") {
|
|
729
|
+
const c = s.components.reduce((l, d) => Math.max(l, d.topMm + d.heightMm), 0);
|
|
730
|
+
s.marginBottomMm = n ? e.marginBottomMm ?? 0 : 0, s.pageHeightMm = Math.max(1, c + s.marginBottomMm);
|
|
731
|
+
}
|
|
732
|
+
return s;
|
|
733
|
+
}
|
|
734
|
+
function Pe(e) {
|
|
735
|
+
return e.cells.reduce((t, r) => t + r.reduce((o, n) => o + (n ? 1 + (n.children?.reduce((a, s) => a + ut(s), 0) ?? 0) : 0), 0), 0);
|
|
736
|
+
}
|
|
737
|
+
function ut(e) {
|
|
738
|
+
return e.grid ? Pe(e.grid) : 0;
|
|
739
|
+
}
|
|
740
|
+
function Re(e) {
|
|
741
|
+
for (const t of ["maxPages", "maxCells", "knownTotalPages"]) if (e[t] !== void 0 && (!Number.isSafeInteger(e[t]) || e[t] < 1)) throw new RangeError(`${t} 应为正安全整数`);
|
|
742
|
+
ne(e.maxChartComponents);
|
|
743
|
+
}
|
|
744
|
+
function Qr(e, t) {
|
|
745
|
+
const r = dt(e, t.datasets[e.dataset] ?? [], t), o = Te(r.list), n = { ...Ee(o, t.measurer, r.rows, t.signal), rowHeightFloorMm: o.rowHeightMm ?? 0 };
|
|
746
|
+
return (o.header === !1 ? 0 : n.headerHeightMm) + r.rows.reduce((a, s) => a + W(n, s, t.measurer).heightMm, 0);
|
|
747
|
+
}
|
|
748
|
+
function* Zr(e) {
|
|
749
|
+
const { templatePage: t, current: r } = e, o = new Map(t.components.map((a, s) => [a, s])), n = (a, s, i) => {
|
|
750
|
+
const c = e.datasets[a.dataset];
|
|
751
|
+
return Array.isArray(c) || e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id ?? ""} 输出为空`), Ur(a, Array.isArray(c) ? c : [], { ...e, tableId: `${e.tableId}:${o.get(a)}`, startTop: s, finished: i, flow: !!t.flow });
|
|
752
|
+
};
|
|
753
|
+
if (t.flow) {
|
|
754
|
+
yield* Sr({
|
|
755
|
+
page: t,
|
|
756
|
+
active: () => J(e.signal),
|
|
757
|
+
top: () => Math.max(r.marginTopMm, V(t)),
|
|
758
|
+
bottom: () => Q(t, r),
|
|
759
|
+
append: (a) => {
|
|
760
|
+
r.components.push(...e.resolveChart(a));
|
|
761
|
+
},
|
|
762
|
+
nextPage: () => {
|
|
763
|
+
e.pushCurrent(), r.components = [], r.heightMm = t.heightMm, t.layout === "wide" && (r.marginTopMm = 0, r.marginBottomMm = 0);
|
|
764
|
+
},
|
|
765
|
+
takePages: e.takePages,
|
|
766
|
+
height: (a) => Qr(a, e),
|
|
767
|
+
list: n
|
|
768
|
+
});
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
for (const a of t.components)
|
|
772
|
+
ce(a) || (a.kind === "list" ? yield* n(a) : r.components.push(...e.resolveChart(a)));
|
|
773
|
+
}
|
|
774
|
+
function* Z(e, t, r, o, n, a = /* @__PURE__ */ new WeakMap(), s) {
|
|
775
|
+
let i = 0, c = 0, l = 0;
|
|
776
|
+
const d = mr(r.measurer ?? We), f = gr(t, r.signal, r.maxChartComponents), u = (h) => `${h}_${(++i).toString(36)}`;
|
|
777
|
+
for (const { pageIndex: h, page: m } of Fr(e, t, r)) {
|
|
778
|
+
J(r.signal);
|
|
779
|
+
const v = Or(m), y = m.components.filter(ce);
|
|
780
|
+
let g = [];
|
|
781
|
+
const w = (P = !1) => {
|
|
782
|
+
if (J(r.signal), r.maxPages !== void 0 && c >= r.maxPages) throw new G(r.maxPages, c + 1);
|
|
783
|
+
if (r.maxCells !== void 0 && (l += [...v.components, ...y].reduce((E, O) => E + ut(O), 0), l > r.maxCells))
|
|
784
|
+
throw new X(r.maxCells, l);
|
|
785
|
+
g.push(Yr(m, v, y, ++c, P, n));
|
|
786
|
+
}, x = () => {
|
|
787
|
+
const P = g;
|
|
788
|
+
return g = [], P;
|
|
789
|
+
};
|
|
790
|
+
yield* Zr({
|
|
791
|
+
templatePage: m,
|
|
792
|
+
current: v,
|
|
793
|
+
warnings: o,
|
|
794
|
+
nextId: u,
|
|
795
|
+
pushCurrent: w,
|
|
796
|
+
takePages: x,
|
|
797
|
+
datasets: t,
|
|
798
|
+
resolveChart: f,
|
|
799
|
+
signal: r.signal,
|
|
800
|
+
formula: r.formula,
|
|
801
|
+
prepared: a,
|
|
802
|
+
measurer: d,
|
|
803
|
+
mmPerRow: r.mmPerRow ?? 0,
|
|
804
|
+
tableId: `table:${h}`
|
|
805
|
+
}), w(!0), yield* x();
|
|
806
|
+
}
|
|
807
|
+
s && (s.chartComponents = f.used());
|
|
808
|
+
}
|
|
809
|
+
function dn(e, t, r = {}) {
|
|
810
|
+
Re(r);
|
|
811
|
+
let o = 0;
|
|
812
|
+
for (const n of Z(e, t, { ...r, onWarning: void 0 }, [])) o++;
|
|
813
|
+
return o;
|
|
814
|
+
}
|
|
815
|
+
function* un(e, t, r = {}) {
|
|
816
|
+
yield* ft(e, t, r);
|
|
817
|
+
}
|
|
818
|
+
function* ft(e, t, r, o) {
|
|
819
|
+
Re(r);
|
|
820
|
+
const n = Xr(e), a = /* @__PURE__ */ new WeakMap();
|
|
821
|
+
let s = r.knownTotalPages;
|
|
822
|
+
if (n && s === void 0) {
|
|
823
|
+
s = 0;
|
|
824
|
+
for (const l of Z(e, t, r, [], void 0, a)) s++;
|
|
825
|
+
}
|
|
826
|
+
const i = [];
|
|
827
|
+
let c = 0;
|
|
828
|
+
for (const l of Z(e, t, r, i, s, a, o)) {
|
|
829
|
+
for (; c < i.length; c++) r.onWarning?.(i[c]);
|
|
830
|
+
yield l;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function mt(e, t, r = {}) {
|
|
834
|
+
const o = typeof r == "number" ? { mmPerRow: r } : r;
|
|
835
|
+
Re(o);
|
|
836
|
+
const n = [], a = { chartComponents: 0 }, s = [...Z(e, t, o, n, o.knownTotalPages, void 0, a)];
|
|
837
|
+
for (const i of s) i.components = i.components.map((c) => ce(c) ? le(c, (l) => l.replace(/\{totalPages\}/g, String(s.length))) : c);
|
|
838
|
+
return n.forEach((i) => o.onWarning?.(i)), { plan: { schemaVersion: te, ...ae(e) ? { requiresRecalculation: !0 } : {}, pages: s }, warnings: n, ...a };
|
|
839
|
+
}
|
|
840
|
+
function eo(e) {
|
|
841
|
+
const t = e.columns.find((a) => !a.hidden)?.field;
|
|
842
|
+
if (!t) return { groups: 0, total: 0 };
|
|
843
|
+
const r = ie(e), o = (a = [], s = []) => a.includes(t) || s.some((i) => i.field === t), n = typeof e.grandTotal == "object" ? e.grandTotal : void 0;
|
|
844
|
+
return { groups: r.filter((a) => o(a.subtotal, a.aggregates)).length, total: Number(o(n?.fields ?? r[0]?.subtotal, n?.aggregates ?? r[0]?.aggregates)) };
|
|
845
|
+
}
|
|
846
|
+
function to(e, t, r) {
|
|
847
|
+
lt(e);
|
|
848
|
+
const o = Xe(t[e.dataset] ?? [], e.tree, r), n = e.columns.filter((s) => !s.hidden).length, a = e.header === !1 ? 0 : e.headerGrid ? Pe(e.headerGrid) : n;
|
|
849
|
+
return o.length * n + a + +!!e.grandTotal * 2 * n;
|
|
850
|
+
}
|
|
851
|
+
function fn(e, t, r = {}) {
|
|
852
|
+
if (e.tree) return to(e, t, r.signal);
|
|
853
|
+
if (e.matrix) {
|
|
854
|
+
let c = t[e.dataset] ?? [];
|
|
855
|
+
e.computed?.length && (c = Me(c, { fields: e.computed, ...r }).rows), e.rowVisibleWhen && (c = c.filter(L(e.rowVisibleWhen)));
|
|
856
|
+
const l = er(c, e.matrix);
|
|
857
|
+
return l.cells + (e.header === !1 ? 0 : l.columnCount * (e.matrix.hierarchy ? e.matrix.columnFields.length + 1 : 1));
|
|
858
|
+
}
|
|
859
|
+
const o = t[e.dataset]?.length ?? 0, n = e.columns.filter((c) => !c.hidden).length, a = ie(e).length, s = eo(e);
|
|
860
|
+
let i = (o * (1 + 2 * a + s.groups) + +!!e.grandTotal * (1 + s.total)) * n;
|
|
861
|
+
if (i += e.header === !1 ? 0 : e.headerGrid ? Pe(e.headerGrid) : n, e.cardinality === "record" && o === 0 && (i += n), e.detail) {
|
|
862
|
+
const c = t[e.detail.dataset]?.length ?? 0, l = e.detail.columns.filter((d) => !d.hidden).length;
|
|
863
|
+
i += (c + o * (+(e.detail.header !== !1) + +!!e.detail.label)) * l;
|
|
864
|
+
}
|
|
865
|
+
if (!Number.isSafeInteger(i)) throw new RangeError("报表单元格估算超出安全整数预算");
|
|
866
|
+
return i;
|
|
867
|
+
}
|
|
868
|
+
class ro extends Error {
|
|
869
|
+
constructor(t) {
|
|
870
|
+
super(t.map((r) => r.message).join(";")), this.issues = t, this.name = "ReportValidationError";
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function je(e, t, r) {
|
|
874
|
+
if (!Number.isSafeInteger(e) || e < 1 || e > r) throw new Error(`校验 ${t} 超出预算`);
|
|
875
|
+
return e;
|
|
876
|
+
}
|
|
877
|
+
function oo(e) {
|
|
878
|
+
if (e.aggregates && e.scope !== "dataset") throw new Error("仅数据集规则允许汇总");
|
|
879
|
+
if (e.aggregates && (!Array.isArray(e.aggregates) || e.aggregates.length > 64)) throw new Error("校验汇总最多 64 项");
|
|
880
|
+
const t = /* @__PURE__ */ new Set();
|
|
881
|
+
for (const r of e.aggregates ?? []) {
|
|
882
|
+
if (K(r.field), t.has(r.field)) throw new Error("校验汇总字段重复");
|
|
883
|
+
t.add(r.field), r.valueField !== void 0 && K(r.valueField), r.weightField !== void 0 && K(r.weightField), Se([], { ...r, field: r.valueField ?? r.field });
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function ht(e) {
|
|
887
|
+
if (!Array.isArray(e) || e.length > 256 || Object.keys(e).length !== e.length) throw new Error("校验规则最多 256 条且不允许空位");
|
|
888
|
+
const t = /* @__PURE__ */ new Set();
|
|
889
|
+
return e.map((r) => {
|
|
890
|
+
if (!r || typeof r != "object") throw new Error("校验规则应为声明式对象");
|
|
891
|
+
if (K(r.id), t.has(r.id)) throw new Error("校验规则 id 重复");
|
|
892
|
+
if (t.add(r.id), r.field !== void 0 && K(r.field), r.dataset !== void 0 && K(r.dataset), typeof r.message != "string" || !r.message.trim() || r.message.length > 2048) throw new Error("校验规则需要有界提示文案");
|
|
893
|
+
if (r.severity !== void 0 && !["error", "warning"].includes(r.severity)) throw new Error("未知校验严重程度");
|
|
894
|
+
if (r.scope !== void 0 && !["row", "dataset"].includes(r.scope)) throw new Error("未知校验范围");
|
|
895
|
+
oo(r);
|
|
896
|
+
const o = { nodes: 0 }, n = L(r.assert, o), a = r.when ? L(r.when, o) : void 0;
|
|
897
|
+
return { rule: r, assert: n, when: a, checks: o.nodes };
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
function Le(e) {
|
|
901
|
+
if (e?.aborted) {
|
|
902
|
+
const t = new Error("报表校验已取消");
|
|
903
|
+
throw t.name = "AbortError", t;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
function no(e, t, r, o) {
|
|
907
|
+
const n = o && Object.prototype.hasOwnProperty.call(t, o) ? t[o] : void 0;
|
|
908
|
+
if (n !== void 0 && typeof n != "string" && !(typeof n == "number" && Number.isFinite(n))) throw new Error("校验定位需要稳定的文本或数值业务键");
|
|
909
|
+
return { ruleId: e.id, rowIndex: r, ...n === void 0 ? {} : { rowKey: n }, field: e.field, severity: e.severity ?? "error", message: e.message };
|
|
910
|
+
}
|
|
911
|
+
function ao(e, t) {
|
|
912
|
+
const r = t.computed?.length ? { fields: t.computed, formula: t.formula, signal: t.signal } : void 0;
|
|
913
|
+
if (t.tree) {
|
|
914
|
+
const n = Ye(e, t.tree, { signal: t.signal, computed: r });
|
|
915
|
+
if (n.rows.length > 1e5) throw new Error("校验展开后数据最多 100000 行");
|
|
916
|
+
return { rows: n.rows, summaryRows: n.leaves, rowKey: t.tree.idField };
|
|
917
|
+
}
|
|
918
|
+
const o = r ? Me(e, r).rows : e;
|
|
919
|
+
return { rows: o, summaryRows: o, rowKey: t.rowKey };
|
|
920
|
+
}
|
|
921
|
+
function so(e, t) {
|
|
922
|
+
const r = /* @__PURE__ */ new Set();
|
|
923
|
+
e.forEach((o) => {
|
|
924
|
+
if (!o || typeof o != "object" || Array.isArray(o)) throw new Error("校验数据行应为对象");
|
|
925
|
+
if (!t) return;
|
|
926
|
+
const n = Object.prototype.hasOwnProperty.call(o, t) ? o[t] : void 0;
|
|
927
|
+
if (!(typeof n == "string" && n.trim()) && !(typeof n == "number" && Number.isFinite(n))) throw new Error("校验定位需要稳定业务键");
|
|
928
|
+
if (r.has(n)) throw new Error("校验业务键重复");
|
|
929
|
+
r.add(n);
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
function mn(e, t) {
|
|
933
|
+
return gt(e, t, { checks: 0 });
|
|
934
|
+
}
|
|
935
|
+
function gt(e, t, r) {
|
|
936
|
+
if (!Array.isArray(e) || e.length > 1e5) throw new Error("校验数据最多 100000 行");
|
|
937
|
+
Le(t.signal);
|
|
938
|
+
const o = je(t.maxChecks ?? 2e6, "maxChecks", 1e7), n = je(t.maxIssues ?? 1e3, "maxIssues", 1e4);
|
|
939
|
+
t.rowKey !== void 0 && K(t.rowKey);
|
|
940
|
+
const a = ao(e, t), { rows: s, summaryRows: i, rowKey: c } = a;
|
|
941
|
+
so(s, c);
|
|
942
|
+
const l = ht(t.rules), d = l.reduce((u, h) => u + (h.rule.scope === "dataset" ? h.checks + i.length * (h.rule.aggregates?.length ?? 0) : s.length * h.checks), 0);
|
|
943
|
+
if (r.checks += d, r.checks > o) throw new Error("整批校验超出 maxChecks 预算");
|
|
944
|
+
const f = [];
|
|
945
|
+
for (const u of l)
|
|
946
|
+
(u.rule.scope === "dataset" ? [Object.fromEntries((u.rule.aggregates ?? []).map((m) => [m.field, Se(i, { ...m, field: m.valueField ?? m.field })]))] : s).forEach((m, v) => {
|
|
947
|
+
if (Le(t.signal), !m || typeof m != "object" || Array.isArray(m)) throw new Error("校验数据行应为对象");
|
|
948
|
+
if (!(u.when && !u.when(m) || u.assert(m))) {
|
|
949
|
+
if (f.length >= n) throw new Error("校验问题超出 maxIssues 预算,请缩小范围");
|
|
950
|
+
f.push(no(u.rule, m, u.rule.scope === "dataset" ? void 0 : v, u.rule.scope === "dataset" ? void 0 : c));
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
return f;
|
|
954
|
+
}
|
|
955
|
+
function io(e, t = "allow") {
|
|
956
|
+
if (!["allow", "block"].includes(t)) throw new Error("未知校验警告策略");
|
|
957
|
+
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("校验问题结构无效");
|
|
958
|
+
if (e.some((r) => r.severity === "error" || t === "block")) throw new ro(e);
|
|
959
|
+
}
|
|
960
|
+
function He(e, t, r) {
|
|
961
|
+
const o = e.get(t);
|
|
962
|
+
if (o && JSON.stringify(o) !== JSON.stringify(r)) throw new Error("同一数据集的校验计算/业务键存在歧义,请统一绑定");
|
|
963
|
+
e.set(t, r);
|
|
964
|
+
}
|
|
965
|
+
function co(e, t, r, o = []) {
|
|
966
|
+
ht(t.rules);
|
|
967
|
+
const n = [], a = { checks: 0 };
|
|
968
|
+
for (const [i, c] of e.entries()) {
|
|
969
|
+
const l = /* @__PURE__ */ new Map();
|
|
970
|
+
for (const d of c.template.pages) for (const f of d.components)
|
|
971
|
+
f.kind === "list" && (He(l, f.dataset, { rowKey: f.tree?.idField ?? f.rowKey, computed: f.computed, tree: f.tree }), f.detail && He(l, f.detail.dataset, { rowKey: f.detail.rowKey }));
|
|
972
|
+
for (const [d, f] of l) {
|
|
973
|
+
const u = t.rules.filter((h) => !h.dataset || h.dataset === d);
|
|
974
|
+
if (u.length && (n.push(...gt(c.datasets[d] ?? [], { ...t, rules: u, ...f, formula: o[i], signal: r }, a).map((h) => ({ ...h, dataset: d, sourceScope: c.sourceScope }))), n.length > (t.maxIssues ?? 1e3)))
|
|
975
|
+
throw new Error("整批候选校验问题超出 maxIssues 预算");
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
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] : []] : []))));
|
|
979
|
+
if (t.rules.some((i) => i.dataset && !s.has(i.dataset))) throw new Error("校验目标数据集不存在");
|
|
980
|
+
return n;
|
|
981
|
+
}
|
|
982
|
+
function pt(e) {
|
|
983
|
+
return !e || typeof e != "object" ? !1 : [e.pageIndex, e.componentIndex, e.rowIndex, e.columnIndex].every((t) => Number.isInteger(t) && t >= 0);
|
|
984
|
+
}
|
|
985
|
+
function wt(e, t, r) {
|
|
986
|
+
const o = e.grid;
|
|
987
|
+
if (!o) return null;
|
|
988
|
+
const n = o.cells[t];
|
|
989
|
+
if (!n) return null;
|
|
990
|
+
const s = oe(o, e.widthMm, e.heightMm).cells.filter((c) => c.ri === t).findIndex((c) => c.ci === r), i = n[s];
|
|
991
|
+
return i ? { cell: i, sourceColumnIndex: s } : null;
|
|
992
|
+
}
|
|
993
|
+
function lo(e) {
|
|
994
|
+
return e.value !== void 0 ? e.value : e.rawText ?? e.text ?? null;
|
|
995
|
+
}
|
|
996
|
+
function uo(e, t) {
|
|
997
|
+
return e.valueType ? e.valueType : typeof t == "number" ? "number" : typeof t == "boolean" ? "boolean" : t === null && e.numberFormat && /[0#?]/.test(e.numberFormat) ? "number" : "text";
|
|
998
|
+
}
|
|
999
|
+
function fo(e, t) {
|
|
1000
|
+
if (e.derived) return "derived";
|
|
1001
|
+
if (e.editable === !1) return "cell";
|
|
1002
|
+
if (e.formula !== void 0) return "formula";
|
|
1003
|
+
if (e.children?.length || e.richParagraphs?.length) return "complex";
|
|
1004
|
+
if (t.table && t.table.role !== "body" && e.editable !== !0) return "structure";
|
|
1005
|
+
}
|
|
1006
|
+
function mo(e, t) {
|
|
1007
|
+
const r = e.table;
|
|
1008
|
+
if (r)
|
|
1009
|
+
return {
|
|
1010
|
+
id: r.id,
|
|
1011
|
+
rowIndex: r.rowIndex + t.rowIndex,
|
|
1012
|
+
role: r.role,
|
|
1013
|
+
columnKey: r.columnKeys[t.columnIndex]
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function ho(e, t, r) {
|
|
1017
|
+
if (e.derived) return;
|
|
1018
|
+
if (e.source) return { ...e.source };
|
|
1019
|
+
const o = t.table?.source, n = t.table?.columnKeys[r.columnIndex];
|
|
1020
|
+
if (!(!o || o.rowKey === void 0 || n === void 0))
|
|
1021
|
+
return { ...o, rowKey: o.rowKey, field: n };
|
|
1022
|
+
}
|
|
1023
|
+
function yt(e, t, r) {
|
|
1024
|
+
const o = lo(r), n = fo(r, e);
|
|
1025
|
+
return {
|
|
1026
|
+
address: { ...t },
|
|
1027
|
+
cell: r,
|
|
1028
|
+
component: e,
|
|
1029
|
+
value: o,
|
|
1030
|
+
valueType: uo(r, o),
|
|
1031
|
+
table: mo(e, t),
|
|
1032
|
+
source: ho(r, e, t),
|
|
1033
|
+
editable: n === void 0,
|
|
1034
|
+
readOnlyReason: n
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
function $e(e, t) {
|
|
1038
|
+
if (!pt(t)) return null;
|
|
1039
|
+
const r = e.pages[t.pageIndex]?.components[t.componentIndex];
|
|
1040
|
+
if (!r) return null;
|
|
1041
|
+
const o = wt(r, t.rowIndex, t.columnIndex);
|
|
1042
|
+
return o ? yt(r, t, o.cell) : null;
|
|
1043
|
+
}
|
|
1044
|
+
function H(e) {
|
|
1045
|
+
const t = /* @__PURE__ */ new Map();
|
|
1046
|
+
return (r) => {
|
|
1047
|
+
if (!pt(r)) return null;
|
|
1048
|
+
const o = e.pages[r.pageIndex]?.components[r.componentIndex];
|
|
1049
|
+
if (!o?.grid) return null;
|
|
1050
|
+
let n = t.get(o);
|
|
1051
|
+
if (!n) {
|
|
1052
|
+
const s = /* @__PURE__ */ new Map();
|
|
1053
|
+
n = /* @__PURE__ */ new Map();
|
|
1054
|
+
for (const i of oe(o.grid, o.widthMm, o.heightMm).cells) {
|
|
1055
|
+
const c = s.get(i.ri) ?? 0;
|
|
1056
|
+
s.set(i.ri, c + 1);
|
|
1057
|
+
const l = o.grid.cells[i.ri]?.[c];
|
|
1058
|
+
l && n.set(`${i.ri}:${i.ci}`, l);
|
|
1059
|
+
}
|
|
1060
|
+
t.set(o, n);
|
|
1061
|
+
}
|
|
1062
|
+
const a = n.get(`${r.rowIndex}:${r.columnIndex}`);
|
|
1063
|
+
return a ? yt(o, r, a) : null;
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
class M extends Error {
|
|
1067
|
+
constructor(t) {
|
|
1068
|
+
super(`Invalid report cell edit: ${t}`), this.code = t, this.name = "ReportCellEditError";
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
function go(e, t) {
|
|
1072
|
+
let r = e.trim();
|
|
1073
|
+
const o = t && r.endsWith("%");
|
|
1074
|
+
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");
|
|
1075
|
+
return Number(r) / (o ? 100 : 1);
|
|
1076
|
+
}
|
|
1077
|
+
function po(e, t) {
|
|
1078
|
+
if (e === null || typeof e == "string" && e.trim() === "") return null;
|
|
1079
|
+
if (typeof e != "string" && typeof e != "number") throw new M("number");
|
|
1080
|
+
const r = typeof e == "number" ? e : go(e, dr(t.cell.numberFormat));
|
|
1081
|
+
if (!Number.isFinite(r) || Number.isInteger(r) && !Number.isSafeInteger(r)) throw new M("number");
|
|
1082
|
+
return r;
|
|
1083
|
+
}
|
|
1084
|
+
function wo(e) {
|
|
1085
|
+
if (e === null || typeof e == "string" && e.trim() === "") return null;
|
|
1086
|
+
if (typeof e == "boolean") return e;
|
|
1087
|
+
const t = String(e).trim().toLowerCase();
|
|
1088
|
+
if (["true", "yes", "是", "1"].includes(t)) return !0;
|
|
1089
|
+
if (["false", "no", "否", "0"].includes(t)) return !1;
|
|
1090
|
+
throw new M("boolean");
|
|
1091
|
+
}
|
|
1092
|
+
function bt(e, t) {
|
|
1093
|
+
return e.valueType === "number" ? po(t, e) : e.valueType === "boolean" ? wo(t) : t === null ? null : String(t);
|
|
1094
|
+
}
|
|
1095
|
+
function yo(e, t) {
|
|
1096
|
+
const r = t.cell.text, n = [["是", "否"], ["TRUE", "FALSE"], ["True", "False"], ["true", "false"], ["1", "0"]].find((a) => a.includes(r ?? ""));
|
|
1097
|
+
return n ? n[e ? 0 : 1] : String(e);
|
|
1098
|
+
}
|
|
1099
|
+
function _(e, t) {
|
|
1100
|
+
return t === null ? "" : typeof t == "boolean" ? yo(t, e) : typeof t == "number" ? lr(t, e.cell.numberFormat) : String(t);
|
|
1101
|
+
}
|
|
1102
|
+
function hn(e, t, r) {
|
|
1103
|
+
const o = $e(e, t);
|
|
1104
|
+
if (!o) throw new M("missing");
|
|
1105
|
+
return q(o, r);
|
|
1106
|
+
}
|
|
1107
|
+
function q(e, t) {
|
|
1108
|
+
if (!e.editable) throw new M("readonly");
|
|
1109
|
+
const r = bt(e, t);
|
|
1110
|
+
return {
|
|
1111
|
+
address: { ...e.address },
|
|
1112
|
+
table: e.table,
|
|
1113
|
+
source: e.source,
|
|
1114
|
+
previousValue: e.value,
|
|
1115
|
+
previousText: e.cell.text ?? "",
|
|
1116
|
+
value: r,
|
|
1117
|
+
text: _(e, r)
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
function bo(e, t) {
|
|
1121
|
+
const r = e.table, o = t.table;
|
|
1122
|
+
return !r || !o || r.columnKey === void 0 ? !1 : r.id === o.id && r.rowIndex === o.rowIndex && r.role === o.role && r.columnKey === o.columnKey;
|
|
1123
|
+
}
|
|
1124
|
+
function vt(e, t, r) {
|
|
1125
|
+
const o = e.grid, { rowIndex: n, columnIndex: a } = t.address, s = wt(e, n, a), i = [...o.cells], c = [...i[n]], l = _(t, r.value), d = { ...s.cell, value: r.value, text: l, rawText: l };
|
|
1126
|
+
return c[s.sourceColumnIndex] = d, i[n] = c, { ...e, grid: { ...o, cells: i } };
|
|
1127
|
+
}
|
|
1128
|
+
function vo(e, t) {
|
|
1129
|
+
const r = e.table?.columnKeys, o = t.table?.columnKey;
|
|
1130
|
+
return r && o !== void 0 ? r.flatMap((n, a) => n === o ? [a] : []) : [];
|
|
1131
|
+
}
|
|
1132
|
+
function Mo(e, t, r, o, n, a) {
|
|
1133
|
+
const s = t.table, i = n.table;
|
|
1134
|
+
if (!s || !i || s.id !== i.id || s.role !== i.role || !t.grid) return t;
|
|
1135
|
+
const c = i.rowIndex - s.rowIndex;
|
|
1136
|
+
if (c < 0 || c >= t.grid.cells.length) return t;
|
|
1137
|
+
let l = t;
|
|
1138
|
+
for (const d of vo(t, n)) {
|
|
1139
|
+
const f = $e(e, { pageIndex: r, componentIndex: o, rowIndex: c, columnIndex: d });
|
|
1140
|
+
f?.editable && bo(n, f) && (l = vt(l, f, a));
|
|
1141
|
+
}
|
|
1142
|
+
return l;
|
|
1143
|
+
}
|
|
1144
|
+
function So(e, t, r, o, n, a) {
|
|
1145
|
+
const s = n.address;
|
|
1146
|
+
return n.table?.columnKey !== void 0 ? Mo(e, t, r, o, n, a) : s.pageIndex === r && s.componentIndex === o ? vt(t, n, a) : t;
|
|
1147
|
+
}
|
|
1148
|
+
function Ie(e, t) {
|
|
1149
|
+
const r = t.source;
|
|
1150
|
+
if (!r) return !1;
|
|
1151
|
+
const o = e.source;
|
|
1152
|
+
return !o || ["sourceScope", "datasetId", "rowKey", "field", "revision", "sourceToken"].some((n) => !Object.is(o[n], r[n]));
|
|
1153
|
+
}
|
|
1154
|
+
function gn(e, t) {
|
|
1155
|
+
const r = $e(e, t.address);
|
|
1156
|
+
if (!r) throw new M("missing");
|
|
1157
|
+
if (!r.editable) throw new M("readonly");
|
|
1158
|
+
if (Ie(r, t)) throw new M("conflict");
|
|
1159
|
+
if (!Object.is(r.value, t.previousValue) || (r.cell.text ?? "") !== t.previousText) throw new M("conflict");
|
|
1160
|
+
const o = bt(r, t.value), n = { ...t, value: o, text: _(r, o) };
|
|
1161
|
+
if (Object.is(o, r.value) && n.text === r.cell.text) return e;
|
|
1162
|
+
const a = e.pages.map((s, i) => {
|
|
1163
|
+
const c = s.components.map((l, d) => So(e, l, i, d, r, n));
|
|
1164
|
+
return c.every((l, d) => l === s.components[d]) ? s : { ...s, components: c };
|
|
1165
|
+
});
|
|
1166
|
+
return { ...e, pages: a };
|
|
1167
|
+
}
|
|
1168
|
+
function Mt(e) {
|
|
1169
|
+
const t = [];
|
|
1170
|
+
for (const r of e.template.pages) for (const o of r.components)
|
|
1171
|
+
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] ?? [] } }));
|
|
1172
|
+
return t;
|
|
1173
|
+
}
|
|
1174
|
+
function D(e) {
|
|
1175
|
+
return JSON.stringify([e.sourceScope, e.datasetId]);
|
|
1176
|
+
}
|
|
1177
|
+
function De(e) {
|
|
1178
|
+
return JSON.stringify([e.sourceScope, e.datasetId, e.rowKey]);
|
|
1179
|
+
}
|
|
1180
|
+
function St(e) {
|
|
1181
|
+
const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
|
|
1182
|
+
return e.forEach((o, n) => {
|
|
1183
|
+
for (const a of Mt(o)) {
|
|
1184
|
+
if (!a.rowKey) continue;
|
|
1185
|
+
const s = a.relation, i = s ? new Set(s.parentRows.map((c) => JSON.stringify(c[s.detail.parentKey]))) : void 0;
|
|
1186
|
+
(o.datasets[a.dataset] ?? []).forEach((c, l) => {
|
|
1187
|
+
if (s && !i.has(JSON.stringify(c[s.detail.foreignKey]))) return;
|
|
1188
|
+
const d = c[a.rowKey];
|
|
1189
|
+
if (typeof d != "string" && typeof d != "number") return;
|
|
1190
|
+
const f = `${n}:${a.dataset}:${l}:${a.rowKey}`;
|
|
1191
|
+
if (r.has(f)) return;
|
|
1192
|
+
r.add(f);
|
|
1193
|
+
const u = De({ sourceScope: o.sourceScope, datasetId: a.dataset, rowKey: d }), h = t.get(u) ?? [];
|
|
1194
|
+
h.push({ partIndex: n, dataset: a.dataset, rowIndex: l, row: c, binding: a }), t.set(u, h);
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
}), (o) => {
|
|
1198
|
+
const n = t.get(De(o));
|
|
1199
|
+
if (!n?.length) throw new M("missing");
|
|
1200
|
+
if (new Set(n.map((a) => `${a.partIndex}:${a.dataset}`)).size !== n.length) throw new M("conflict");
|
|
1201
|
+
return n;
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
function xt(e, t) {
|
|
1205
|
+
const r = e.map((n) => ({ ...n, datasets: { ...n.datasets } })), o = /* @__PURE__ */ new Set();
|
|
1206
|
+
for (const { row: n, field: a, value: s } of t) {
|
|
1207
|
+
const i = r[n.partIndex], c = JSON.stringify([n.partIndex, n.dataset]);
|
|
1208
|
+
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 };
|
|
1209
|
+
}
|
|
1210
|
+
for (const n of o) {
|
|
1211
|
+
const [a, s] = JSON.parse(n);
|
|
1212
|
+
Wt(e[a].datasets[s], r[a].datasets[s]);
|
|
1213
|
+
}
|
|
1214
|
+
return r;
|
|
1215
|
+
}
|
|
1216
|
+
function xo(e, t, r) {
|
|
1217
|
+
const o = [], n = /* @__PURE__ */ new Set();
|
|
1218
|
+
return e.forEach((a, s) => {
|
|
1219
|
+
for (const i of Mt(a))
|
|
1220
|
+
t.has(D({ sourceScope: a.sourceScope, datasetId: i.dataset })) && (a.datasets[i.dataset] ?? []).forEach((c, l) => {
|
|
1221
|
+
const d = { partIndex: s, dataset: i.dataset, rowIndex: l, row: c, binding: i };
|
|
1222
|
+
for (const [f, u] of [[i.revisionField, r.revision], [i.sourceTokenField, r.sourceToken]]) {
|
|
1223
|
+
if (!f || u === void 0) continue;
|
|
1224
|
+
const h = `${s}:${i.dataset}:${l}:${f}`;
|
|
1225
|
+
n.has(h) || (n.add(h), o.push({ row: d, field: f, value: u }));
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
}), o;
|
|
1229
|
+
}
|
|
1230
|
+
function Co(e, t, r) {
|
|
1231
|
+
if (!r || r.revision === void 0 && r.sourceToken === void 0) return e;
|
|
1232
|
+
const o = new Set(t.edits.flatMap((n) => n.source ? [D(n.source)] : []));
|
|
1233
|
+
return Ct(e, new Map([...o].map((n) => [n, r])));
|
|
1234
|
+
}
|
|
1235
|
+
function Ct(e, t) {
|
|
1236
|
+
if (!t.size) return e;
|
|
1237
|
+
function r(a) {
|
|
1238
|
+
const s = a.datasetId && t.get(D({ ...a, datasetId: a.datasetId }));
|
|
1239
|
+
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 } : {} };
|
|
1240
|
+
}
|
|
1241
|
+
function o(a) {
|
|
1242
|
+
const s = a.map((i) => {
|
|
1243
|
+
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) => {
|
|
1244
|
+
const h = u.map((m) => {
|
|
1245
|
+
if (!m) return m;
|
|
1246
|
+
const v = m.source ? r(m.source) : void 0, y = m.children ? o(m.children) : void 0;
|
|
1247
|
+
return v === m.source && y === m.children ? m : { ...m, source: v, children: y };
|
|
1248
|
+
});
|
|
1249
|
+
return h.some((m, v) => m !== u[v]) ? h : u;
|
|
1250
|
+
}), f = i.grid && d?.some((u, h) => u !== i.grid.cells[h]) ? { ...i.grid, cells: d } : i.grid;
|
|
1251
|
+
return l !== i.table || f !== i.grid ? { ...i, table: l, grid: f } : i;
|
|
1252
|
+
});
|
|
1253
|
+
return s.some((i, c) => i !== a[c]) ? s : a;
|
|
1254
|
+
}
|
|
1255
|
+
const n = e.pages.map((a) => {
|
|
1256
|
+
const s = o(a.components);
|
|
1257
|
+
return s !== a.components ? { ...a, components: s } : a;
|
|
1258
|
+
});
|
|
1259
|
+
return n.some((a, s) => a !== e.pages[s]) ? { ...e, pages: n } : e;
|
|
1260
|
+
}
|
|
1261
|
+
function ko(e) {
|
|
1262
|
+
return JSON.stringify([e.pageIndex, e.componentIndex, e.rowIndex, e.columnIndex]);
|
|
1263
|
+
}
|
|
1264
|
+
function Be(e) {
|
|
1265
|
+
const t = e.table;
|
|
1266
|
+
return t?.columnKey !== void 0 ? JSON.stringify([t.id, t.role, t.rowIndex, t.columnKey]) : ko(e.address);
|
|
1267
|
+
}
|
|
1268
|
+
function Eo(e, t) {
|
|
1269
|
+
if (!t.length) return e;
|
|
1270
|
+
const r = new Map(t.map((c) => [Be(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 = H(e);
|
|
1271
|
+
function s(c, l, d) {
|
|
1272
|
+
const f = c.grid;
|
|
1273
|
+
if (!f || !n.has(`${l}:${d}`) && !o.has(c.table?.id ?? "")) return c;
|
|
1274
|
+
const u = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
|
|
1275
|
+
for (const m of oe(f, c.widthMm, c.heightMm).cells) {
|
|
1276
|
+
const v = h.get(m.ri) ?? 0;
|
|
1277
|
+
h.set(m.ri, v + 1);
|
|
1278
|
+
const y = a({ pageIndex: l, componentIndex: d, rowIndex: m.ri, columnIndex: m.ci }), g = y && r.get(Be(y));
|
|
1279
|
+
if (!g || !y.editable) continue;
|
|
1280
|
+
const w = u.get(m.ri) ?? [...f.cells[m.ri]], x = _(y, g.value);
|
|
1281
|
+
Object.is(y.value, g.value) && x === y.cell.text || (w[v] = { ...m.cell, value: g.value, text: x, rawText: x }, u.set(m.ri, w));
|
|
1282
|
+
}
|
|
1283
|
+
return u.size ? { ...c, grid: { ...f, cells: f.cells.map((m, v) => u.get(v) ?? m) } } : c;
|
|
1284
|
+
}
|
|
1285
|
+
const i = e.pages.map((c, l) => {
|
|
1286
|
+
const d = c.components.map((f, u) => s(f, l, u));
|
|
1287
|
+
return d.every((f, u) => f === c.components[u]) ? c : { ...c, components: d };
|
|
1288
|
+
});
|
|
1289
|
+
return i.every((c, l) => c === e.pages[l]) ? e : { ...e, pages: i };
|
|
1290
|
+
}
|
|
1291
|
+
function F(e) {
|
|
1292
|
+
const t = e.source;
|
|
1293
|
+
if (t) return JSON.stringify([t.sourceScope, t.datasetId, t.rowKey, t.field]);
|
|
1294
|
+
const r = e.table;
|
|
1295
|
+
if (r?.columnKey !== void 0) return JSON.stringify([r.id, r.role, r.rowIndex, r.columnKey]);
|
|
1296
|
+
const o = e.address;
|
|
1297
|
+
return JSON.stringify([o.pageIndex, o.componentIndex, o.rowIndex, o.columnIndex]);
|
|
1298
|
+
}
|
|
1299
|
+
function pn(e, t, r) {
|
|
1300
|
+
if (typeof r != "string" || !r.trim() || !Array.isArray(t)) throw new M("missing");
|
|
1301
|
+
if (t.length > 1e4) throw new M("limit");
|
|
1302
|
+
const o = /* @__PURE__ */ new Set(), n = H(e), a = t.map(({ address: s, value: i }) => {
|
|
1303
|
+
const c = n(s);
|
|
1304
|
+
if (!c) throw new M("missing");
|
|
1305
|
+
const l = q(c, i), d = F(l);
|
|
1306
|
+
if (o.has(d)) throw new M("duplicate");
|
|
1307
|
+
return o.add(d), l;
|
|
1308
|
+
});
|
|
1309
|
+
return { requestId: r, edits: a };
|
|
1310
|
+
}
|
|
1311
|
+
function wn(e, t) {
|
|
1312
|
+
if (t.edits.length > 1e4) throw new M("limit");
|
|
1313
|
+
const r = H(e), o = /* @__PURE__ */ new Set(), n = t.edits.map((a) => {
|
|
1314
|
+
const s = r(a.address);
|
|
1315
|
+
if (!s) throw new M("missing");
|
|
1316
|
+
const i = F(a);
|
|
1317
|
+
if (o.has(i)) throw new M("duplicate");
|
|
1318
|
+
if (o.add(i), Ie(s, a) || !Object.is(s.value, a.previousValue) || (s.cell.text ?? "") !== a.previousText) throw new M("conflict");
|
|
1319
|
+
return q(s, a.value);
|
|
1320
|
+
});
|
|
1321
|
+
return Eo(e, n);
|
|
1322
|
+
}
|
|
1323
|
+
function yn(e) {
|
|
1324
|
+
const t = /* @__PURE__ */ new Map();
|
|
1325
|
+
for (const r of e) {
|
|
1326
|
+
const o = F(r), n = t.get(o), a = n ? { ...r, previousValue: n.previousValue, previousText: n.previousText } : { ...r };
|
|
1327
|
+
Object.is(a.previousValue, a.value) ? t.delete(o) : t.set(o, a);
|
|
1328
|
+
}
|
|
1329
|
+
return [...t.values()];
|
|
1330
|
+
}
|
|
1331
|
+
function kt(e) {
|
|
1332
|
+
const t = /* @__PURE__ */ new Map(), r = H(e);
|
|
1333
|
+
return e.pages.forEach((o, n) => o.components.forEach((a, s) => {
|
|
1334
|
+
if (!(!a.grid || a.table?.role !== "body"))
|
|
1335
|
+
for (let i = 0; i < a.grid.cells.length; i++) for (let c = 0; c < a.table.columnKeys.length; c++) {
|
|
1336
|
+
const l = r({ pageIndex: n, componentIndex: s, rowIndex: i, columnIndex: c });
|
|
1337
|
+
l?.source && l.editable && t.set(F(l), l);
|
|
1338
|
+
}
|
|
1339
|
+
})), t;
|
|
1340
|
+
}
|
|
1341
|
+
function bn(e, t, r) {
|
|
1342
|
+
const o = kt(e), n = H(e);
|
|
1343
|
+
return t.map((a) => {
|
|
1344
|
+
const s = a.source ? o.get(F(a)) : n(a.address);
|
|
1345
|
+
if (!s || F(s) !== F(a)) throw new M("missing");
|
|
1346
|
+
return { address: { ...s.address }, value: a[r] };
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
function Et(e, t) {
|
|
1350
|
+
if (++e.nodes > 1e6 || t > 128) throw new M("limit");
|
|
1351
|
+
}
|
|
1352
|
+
function ee(e, t) {
|
|
1353
|
+
const r = Object.getOwnPropertyDescriptor(e, t);
|
|
1354
|
+
if (!r || r.get || r.set) throw new M("conflict");
|
|
1355
|
+
return r.value;
|
|
1356
|
+
}
|
|
1357
|
+
function Tt(e) {
|
|
1358
|
+
if (Object.getOwnPropertyDescriptor(e, "toJSON")) throw new M("conflict");
|
|
1359
|
+
const t = Object.getPrototypeOf(e);
|
|
1360
|
+
if (Array.isArray(e) && (t !== Array.prototype || Object.keys(e).length !== e.length)) throw new M("conflict");
|
|
1361
|
+
if (!(e instanceof Date) && !Array.isArray(e) && t !== Object.prototype && t !== null) throw new M("conflict");
|
|
1362
|
+
for (const r of Reflect.ownKeys(e))
|
|
1363
|
+
if (!(Array.isArray(e) && r === "length")) {
|
|
1364
|
+
if (typeof r == "symbol" || !Object.getOwnPropertyDescriptor(e, r)?.enumerable) throw new M("conflict");
|
|
1365
|
+
if (e instanceof Date || Array.isArray(e) && !/^(0|[1-9]\d*)$/.test(r)) throw new M("conflict");
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
function Pt(e, t, r, o, n) {
|
|
1369
|
+
if (Et(o, n), typeof e == "function" || typeof e == "symbol") throw new M("conflict");
|
|
1370
|
+
if (e === null || typeof e != "object") return;
|
|
1371
|
+
if (Tt(e), r.has(e)) throw new M("conflict");
|
|
1372
|
+
r.add(e);
|
|
1373
|
+
const a = Object.keys(e), s = a.map((i) => ee(e, i));
|
|
1374
|
+
t.push({
|
|
1375
|
+
object: e,
|
|
1376
|
+
prototype: Object.getPrototypeOf(e),
|
|
1377
|
+
keys: a,
|
|
1378
|
+
values: s,
|
|
1379
|
+
...e instanceof Date ? { date: Date.prototype.getTime.call(e) } : {},
|
|
1380
|
+
...Array.isArray(e) ? { length: e.length } : {}
|
|
1381
|
+
});
|
|
1382
|
+
for (const i of s) Pt(i, t, r, o, n + 1);
|
|
1383
|
+
r.delete(e);
|
|
1384
|
+
}
|
|
1385
|
+
function To(e) {
|
|
1386
|
+
const { object: t, keys: r, values: o } = e;
|
|
1387
|
+
if (Tt(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;
|
|
1388
|
+
const n = Object.keys(t);
|
|
1389
|
+
return n.length === r.length && r.every((a, s) => n[s] === a && Object.is(ee(t, a), o[s]));
|
|
1390
|
+
}
|
|
1391
|
+
function Po(e) {
|
|
1392
|
+
const t = [];
|
|
1393
|
+
return Pt(e, t, /* @__PURE__ */ new Set(), { nodes: 0 }, 0), () => {
|
|
1394
|
+
try {
|
|
1395
|
+
return t.every(To);
|
|
1396
|
+
} catch {
|
|
1397
|
+
return !1;
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
function ge(e, t, r) {
|
|
1402
|
+
if (Et(t, r), e === null || typeof e != "object") return e;
|
|
1403
|
+
if (e instanceof Date) return new Date(Date.prototype.getTime.call(e));
|
|
1404
|
+
if (Array.isArray(e)) {
|
|
1405
|
+
const o = [];
|
|
1406
|
+
for (let n = 0; n < e.length; n++) o[n] = ge(ee(e, String(n)), t, r + 1);
|
|
1407
|
+
return o;
|
|
1408
|
+
}
|
|
1409
|
+
return Object.fromEntries(Object.keys(e).map((o) => [o, ge(ee(e, o), t, r + 1)]));
|
|
1410
|
+
}
|
|
1411
|
+
function Ro(e) {
|
|
1412
|
+
const t = ge(e, { nodes: 0 }, 0);
|
|
1413
|
+
for (const r of t) for (const o of Object.values(r.datasets)) Jt(o);
|
|
1414
|
+
return t;
|
|
1415
|
+
}
|
|
1416
|
+
async function $o(e, t, r = {}) {
|
|
1417
|
+
return (await Rt(e, t, r)).plan;
|
|
1418
|
+
}
|
|
1419
|
+
async function Rt(e, t, r = {}) {
|
|
1420
|
+
const o = [], n = { chartComponents: 0 }, a = { ...r, knownTotalPages: void 0 };
|
|
1421
|
+
for (const s of ft(e, t, a, n))
|
|
1422
|
+
o.push(s), o.length % 8 === 0 && await new Promise((i) => setTimeout(i, 0));
|
|
1423
|
+
if (r.signal?.aborted) {
|
|
1424
|
+
const s = new Error("报表重算已取消");
|
|
1425
|
+
throw s.name = "AbortError", s;
|
|
1426
|
+
}
|
|
1427
|
+
return { plan: { schemaVersion: te, ...ae(e) ? { requiresRecalculation: !0 } : {}, pages: o }, ...n };
|
|
1428
|
+
}
|
|
1429
|
+
const pe = /* @__PURE__ */ new WeakMap();
|
|
1430
|
+
function vn(e) {
|
|
1431
|
+
return pe.get(e);
|
|
1432
|
+
}
|
|
1433
|
+
function U(e) {
|
|
1434
|
+
if (e?.aborted) {
|
|
1435
|
+
const t = new Error("报表重算已取消");
|
|
1436
|
+
throw t.name = "AbortError", t;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
function $t(e, t) {
|
|
1440
|
+
return e[t] === void 0 ? "" : e[t];
|
|
1441
|
+
}
|
|
1442
|
+
function Io(e, t) {
|
|
1443
|
+
if (t.edits.length > 1e4) throw new M("limit");
|
|
1444
|
+
const r = H(e), o = /* @__PURE__ */ new Set(), n = [], a = t.edits.map((s) => {
|
|
1445
|
+
const i = r(s.address);
|
|
1446
|
+
if (!i?.source) throw new M("missing");
|
|
1447
|
+
const c = F(s);
|
|
1448
|
+
if (o.has(c)) throw new M("duplicate");
|
|
1449
|
+
if (o.add(c), Ie(i, s) || !Object.is(i.value, s.previousValue) || (i.cell.text ?? "") !== s.previousText) throw new M("conflict");
|
|
1450
|
+
return n.push(i), q(i, s.value);
|
|
1451
|
+
});
|
|
1452
|
+
return { batch: { requestId: t.requestId, edits: a }, contexts: n };
|
|
1453
|
+
}
|
|
1454
|
+
function Fo(e, t) {
|
|
1455
|
+
const r = St(e);
|
|
1456
|
+
return t.flatMap((o) => {
|
|
1457
|
+
if (!o.source) throw new M("missing");
|
|
1458
|
+
return r(o.source).map((n) => {
|
|
1459
|
+
if (!Object.is($t(n.row, o.source.field), o.previousValue)) throw new M("conflict");
|
|
1460
|
+
if (n.binding.rowKey === o.source.field) throw new M("readonly");
|
|
1461
|
+
return { row: n, field: o.source.field, value: o.value };
|
|
1462
|
+
});
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
function fe(e, t, r) {
|
|
1466
|
+
const o = { ...e, value: t, source: { ...e.source, ...r?.revision === void 0 ? {} : { revision: r.revision }, ...r?.sourceToken === void 0 ? {} : { sourceToken: r.sourceToken } } };
|
|
1467
|
+
return o.cell = { ...e.cell, value: o.value, text: _(o, o.value) }, o;
|
|
1468
|
+
}
|
|
1469
|
+
function Oo(e, t, r) {
|
|
1470
|
+
if (!r || r.revision === void 0 && r.sourceToken === void 0) return [...e];
|
|
1471
|
+
const o = new Set(t.edits.flatMap((n) => n.source ? [D(n.source)] : []));
|
|
1472
|
+
return xt(e, xo(e, o, r));
|
|
1473
|
+
}
|
|
1474
|
+
function Ao(e, t, r) {
|
|
1475
|
+
const o = new Set(t.edits.map((n) => D(n.source)));
|
|
1476
|
+
for (const n of o) e.set(n, {
|
|
1477
|
+
...e.get(n),
|
|
1478
|
+
...r.revision !== void 0 ? { revision: r.revision } : {},
|
|
1479
|
+
...r.sourceToken !== void 0 ? { sourceToken: r.sourceToken } : {}
|
|
1480
|
+
});
|
|
1481
|
+
return o;
|
|
1482
|
+
}
|
|
1483
|
+
function It(e, t) {
|
|
1484
|
+
let r = t.parts;
|
|
1485
|
+
const o = t.rebuild, n = [...t.validationFormulas ?? []];
|
|
1486
|
+
let a = Po(r), s = e, i;
|
|
1487
|
+
const c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
|
|
1488
|
+
function d(h) {
|
|
1489
|
+
if (h !== s) throw new M("conflict");
|
|
1490
|
+
if (i) return i;
|
|
1491
|
+
if (!a?.()) throw new M("conflict");
|
|
1492
|
+
return Ro(r);
|
|
1493
|
+
}
|
|
1494
|
+
async function f(h, m, v, y = {}) {
|
|
1495
|
+
U(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)), U(y.signal);
|
|
1496
|
+
const g = d(h), w = xt(g, Fo(g, m.edits)), x = Ct(await o(w, y.signal), l);
|
|
1497
|
+
U(y.signal);
|
|
1498
|
+
let P = !1, E = [], O = "allow", A = !1;
|
|
1499
|
+
function p(b) {
|
|
1500
|
+
return A = !0, E = Object.freeze(co(w, b, y.signal, n).map((S) => Object.freeze({ ...S }))), A = !1, O = b.warningPolicy ?? "allow", E;
|
|
1501
|
+
}
|
|
1502
|
+
return y.validation && p(y.validation), { plan: x, get validationIssues() {
|
|
1503
|
+
return E;
|
|
1504
|
+
}, validate: p, commit(b) {
|
|
1505
|
+
if (U(y.signal), P || s !== h) throw new M("conflict");
|
|
1506
|
+
if (b?.conflicts?.length) throw new M("conflict");
|
|
1507
|
+
if (A) throw new Error("候选规则校验未完成,不能提交");
|
|
1508
|
+
io(E, O);
|
|
1509
|
+
const S = Oo(w, m, b), T = Co(x, m, b);
|
|
1510
|
+
if (b) {
|
|
1511
|
+
const k = Ao(l, m, b);
|
|
1512
|
+
for (const [R, j] of c) k.has(D(j.source)) && c.set(R, fe(j, j.value, b));
|
|
1513
|
+
}
|
|
1514
|
+
return v.forEach((k, R) => c.set(F(k), fe(k, m.edits[R].value, b))), P = !0, i = S, r = void 0, a = void 0, s = T, pe.set(s, u), s;
|
|
1515
|
+
} };
|
|
1516
|
+
}
|
|
1517
|
+
const u = {
|
|
1518
|
+
get plan() {
|
|
1519
|
+
return s;
|
|
1520
|
+
},
|
|
1521
|
+
async prepare(h, m, v) {
|
|
1522
|
+
const y = Io(h, m);
|
|
1523
|
+
return f(h, y.batch, y.contexts, v);
|
|
1524
|
+
},
|
|
1525
|
+
async prepareHistory(h, m, v, y, g) {
|
|
1526
|
+
if (!y.trim() || m.length > 1e4) throw new M("limit");
|
|
1527
|
+
const w = d(h), x = St(w), P = kt(h), E = /* @__PURE__ */ new Set(), A = m.map((S) => {
|
|
1528
|
+
if (!S.source) throw new M("missing");
|
|
1529
|
+
const T = F(S);
|
|
1530
|
+
if (E.has(T)) throw new M("duplicate");
|
|
1531
|
+
E.add(T);
|
|
1532
|
+
const k = P.get(T) ?? c.get(T);
|
|
1533
|
+
if (!k?.source) throw new M("missing");
|
|
1534
|
+
const R = x(k.source)[0];
|
|
1535
|
+
return fe(k, $t(R.row, k.source.field));
|
|
1536
|
+
}).map((S, T) => ({ context: S, edit: q(S, m[T][v]) })).filter(({ edit: S }) => !Object.is(S.previousValue, S.value)), p = { requestId: y, edits: A.map(({ edit: S }) => S) }, b = A.map(({ context: S }) => S);
|
|
1537
|
+
return { batch: p, contexts: b, prepared: await f(h, p, b, g) };
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
return pe.set(e, u), u;
|
|
1541
|
+
}
|
|
1542
|
+
function Mn(e) {
|
|
1543
|
+
const t = mt(e.template, e.datasets, e.pagination).plan;
|
|
1544
|
+
return It(t, { validationFormulas: [e.pagination?.formula], parts: [{ template: e.template, datasets: e.datasets }], rebuild: (r, o) => $o(r[0].template, r[0].datasets, { ...e.pagination, signal: o }) });
|
|
1545
|
+
}
|
|
1546
|
+
let No = 0;
|
|
1547
|
+
function Ko() {
|
|
1548
|
+
return `report-${Date.now()}-${++No}`;
|
|
1549
|
+
}
|
|
1550
|
+
function Ge(e, t, r) {
|
|
1551
|
+
if (!r?.aborted)
|
|
1552
|
+
try {
|
|
1553
|
+
const o = e?.({ ...t });
|
|
1554
|
+
o && typeof o.then == "function" && Promise.resolve(o).catch(() => {
|
|
1555
|
+
});
|
|
1556
|
+
} catch {
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
function jo(e) {
|
|
1560
|
+
const t = e.taskId ?? Ko(), r = (o, n, a) => {
|
|
1561
|
+
Ge(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: o, status: n, ...a === void 0 ? {} : { reportId: a } }, e.signal);
|
|
1562
|
+
};
|
|
1563
|
+
return {
|
|
1564
|
+
taskId: t,
|
|
1565
|
+
progress(o, n, a) {
|
|
1566
|
+
Ge(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: o, status: "started", completed: n, total: a }, e.signal);
|
|
1567
|
+
},
|
|
1568
|
+
async run(o, n, a) {
|
|
1569
|
+
r(o, "started", a);
|
|
1570
|
+
try {
|
|
1571
|
+
const s = await n();
|
|
1572
|
+
return r(o, "completed", a), s;
|
|
1573
|
+
} catch (s) {
|
|
1574
|
+
throw r(o, "failed", a), s;
|
|
1575
|
+
}
|
|
1576
|
+
},
|
|
1577
|
+
runSync(o, n, a) {
|
|
1578
|
+
r(o, "started", a);
|
|
1579
|
+
try {
|
|
1580
|
+
const s = n();
|
|
1581
|
+
return r(o, "completed", a), s;
|
|
1582
|
+
} catch (s) {
|
|
1583
|
+
throw r(o, "failed", a), s;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
function Ft(e) {
|
|
1589
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
1590
|
+
const t = e, r = (o) => typeof o == "string" && o.trim().length > 0 && o.length <= 256;
|
|
1591
|
+
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);
|
|
1592
|
+
}
|
|
1593
|
+
function Lo(e) {
|
|
1594
|
+
return e === "missing-source" || e === "not-applicable" || e === "not-calculable";
|
|
1595
|
+
}
|
|
1596
|
+
function Ho(e) {
|
|
1597
|
+
return e.target !== void 0 && !Ft(e.target) ? !1 : e.valueState === void 0 || Lo(e.valueState) && e.target !== void 0;
|
|
1598
|
+
}
|
|
1599
|
+
function Sn(e, t) {
|
|
1600
|
+
if (Ze([], e), !Ft(t)) throw new Error("数据说明目标无效");
|
|
1601
|
+
const r = e.fields.find((n) => n.field === t.field);
|
|
1602
|
+
if (!r) throw new Error("数据说明字段未在契约中声明");
|
|
1603
|
+
const o = [];
|
|
1604
|
+
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;
|
|
1605
|
+
}
|
|
1606
|
+
function Ot(e, t, r = {}) {
|
|
1607
|
+
const o = /* @__PURE__ */ new Map();
|
|
1608
|
+
for (const a of e.pages) for (const s of a.components) {
|
|
1609
|
+
if (s.kind !== "list" || s.tree?.input !== "nested") continue;
|
|
1610
|
+
const i = o.get(s.dataset);
|
|
1611
|
+
if (i && (i.childrenField ?? "children") !== (s.tree.childrenField ?? "children")) throw new Error("同一数据集的嵌套树应使用相同 childrenField");
|
|
1612
|
+
o.set(s.dataset, s.tree);
|
|
1613
|
+
}
|
|
1614
|
+
if (!o.size) return t;
|
|
1615
|
+
const n = { ...t };
|
|
1616
|
+
for (const [a, s] of o) {
|
|
1617
|
+
const i = Math.min(s.maxRows ?? 1e5, r.maxRows ?? 1 / 0);
|
|
1618
|
+
n[a] = Xe(t[a] ?? [], { ...s, maxRows: i }, r.signal);
|
|
1619
|
+
}
|
|
1620
|
+
return n;
|
|
1621
|
+
}
|
|
1622
|
+
function xn(e, t, r = {}) {
|
|
1623
|
+
return Object.values(Ot(e, t, r)).reduce((o, n) => o + n.length, 0);
|
|
1624
|
+
}
|
|
1625
|
+
function Cn(e, t, r) {
|
|
1626
|
+
const o = ur(r), n = e?.pages.flatMap((i) => i.components).find((i) => i.kind === "list" && i.dataset === t && i.tree?.input === "nested");
|
|
1627
|
+
if (!n || n.kind !== "list" || !n.tree) return o;
|
|
1628
|
+
const a = o.items, s = n.tree.childrenField ?? "children";
|
|
1629
|
+
return { ...o, items: { $ref: "#/$defs/treeNode" }, $defs: { treeNode: { ...a, properties: { ...a.properties, [s]: { anyOf: [{ type: "null" }, { type: "array", items: { $ref: "#/$defs/treeNode" } }] } } } } };
|
|
1630
|
+
}
|
|
1631
|
+
function At(e, t) {
|
|
1632
|
+
return JSON.stringify([e, t]);
|
|
1633
|
+
}
|
|
1634
|
+
function Nt(e, t, r) {
|
|
1635
|
+
return r === void 0 ? At(e, t) : JSON.stringify(["shared", r]);
|
|
1636
|
+
}
|
|
1637
|
+
function Kt(e, t, r) {
|
|
1638
|
+
return e.map((o) => {
|
|
1639
|
+
const n = o.table ? {
|
|
1640
|
+
...o.table,
|
|
1641
|
+
id: r(o.table.id),
|
|
1642
|
+
...o.table.source ? { source: { ...o.table.source, sourceScope: t } } : {}
|
|
1643
|
+
} : void 0, a = o.grid?.cells.map((s) => s.map((i) => !i || !i.source && !i.children ? i : {
|
|
1644
|
+
...i,
|
|
1645
|
+
...i.source ? { source: { ...i.source, sourceScope: t } } : {},
|
|
1646
|
+
...i.children ? { children: Kt(i.children, t, r) } : {}
|
|
1647
|
+
}));
|
|
1648
|
+
return n || a ? {
|
|
1649
|
+
...o,
|
|
1650
|
+
...n ? { table: n } : {},
|
|
1651
|
+
...a ? { grid: { ...o.grid, cells: a } } : {}
|
|
1652
|
+
} : o;
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
function we(e) {
|
|
1656
|
+
return ne(e.maxChartComponents), { maxPages: e.maxPages, maxCells: e.maxCells, maxChartComponents: e.maxChartComponents ?? Ce, usedPages: 0, usedCells: 0, usedChartComponents: 0 };
|
|
1657
|
+
}
|
|
1658
|
+
function Do(e, t) {
|
|
1659
|
+
if (!e.repeat) return !1;
|
|
1660
|
+
const r = Object.prototype.hasOwnProperty.call(t, e.repeat.dataset) ? t[e.repeat.dataset] : void 0;
|
|
1661
|
+
return Array.isArray(r) && r.length === 0;
|
|
1662
|
+
}
|
|
1663
|
+
function Bo(e) {
|
|
1664
|
+
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;
|
|
1665
|
+
return e.pages.reduce((r, o) => r + o.components.reduce((n, a) => n + t(a), 0), 0);
|
|
1666
|
+
}
|
|
1667
|
+
function ye(e, t) {
|
|
1668
|
+
return e === void 0 ? void 0 : e - t;
|
|
1669
|
+
}
|
|
1670
|
+
function me(e, t) {
|
|
1671
|
+
return e === void 0 ? t : Math.max(1, Math.min(e, t ?? e));
|
|
1672
|
+
}
|
|
1673
|
+
function jt(e, t, r, o, n) {
|
|
1674
|
+
ne(e?.maxChartComponents);
|
|
1675
|
+
const a = ye(t.maxPages, t.usedPages), s = t.maxChartComponents - t.usedChartComponents;
|
|
1676
|
+
if (a !== void 0 && a < 1 && r.pages.length && !Do(r, o)) throw new G(0, 1);
|
|
1677
|
+
if (s < 1 && r.pages.some((i) => i.components.some((c) => c.kind !== "list" && c.chartBinding))) throw new Y(s, 1);
|
|
1678
|
+
return {
|
|
1679
|
+
...e,
|
|
1680
|
+
signal: n ?? e?.signal,
|
|
1681
|
+
maxPages: me(a, e?.maxPages),
|
|
1682
|
+
maxCells: me(ye(t.maxCells, t.usedCells), e?.maxCells),
|
|
1683
|
+
maxChartComponents: me(s, e?.maxChartComponents)
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
function Lt(e, t) {
|
|
1687
|
+
const r = Bo(t.plan), o = ye(e.maxCells, e.usedCells);
|
|
1688
|
+
if (o !== void 0 && r > o) throw new X(o, r);
|
|
1689
|
+
e.usedPages += t.plan.pages.length, e.usedCells += r, e.usedChartComponents += t.chartComponents;
|
|
1690
|
+
}
|
|
1691
|
+
function Ht(e, t) {
|
|
1692
|
+
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 X && t.maxCells !== void 0 ? new X(t.maxCells, t.usedCells + e.actual) : e instanceof Y && e.limit === t.maxChartComponents - t.usedChartComponents ? new Y(t.maxChartComponents, t.usedChartComponents + e.estimated) : e;
|
|
1693
|
+
}
|
|
1694
|
+
function kn(e) {
|
|
1695
|
+
if (!("mapData" in e)) return e;
|
|
1696
|
+
const { load: t, mapData: r, ...o } = e;
|
|
1697
|
+
return { ...o, load: async (n) => {
|
|
1698
|
+
const a = await t(n);
|
|
1699
|
+
$(n.signal);
|
|
1700
|
+
try {
|
|
1701
|
+
return r(a, n);
|
|
1702
|
+
} catch (s) {
|
|
1703
|
+
throw new C("validate", `报表 ${n.reportId} 数据映射失败`, s);
|
|
1704
|
+
}
|
|
1705
|
+
} };
|
|
1706
|
+
}
|
|
1707
|
+
class C extends Error {
|
|
1708
|
+
constructor(t, r, o) {
|
|
1709
|
+
super(r), this.name = "ReportSourceError", this.code = t, this.cause = o;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
function de(e) {
|
|
1713
|
+
const t = new Error("报表加载已取消");
|
|
1714
|
+
return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
|
|
1715
|
+
}
|
|
1716
|
+
function $(e) {
|
|
1717
|
+
if (e?.aborted) throw de(e);
|
|
1718
|
+
}
|
|
1719
|
+
function be(e, t) {
|
|
1720
|
+
return t ? new Promise((r, o) => {
|
|
1721
|
+
const n = () => t.removeEventListener("abort", a), a = () => {
|
|
1722
|
+
n(), o(de(t));
|
|
1723
|
+
};
|
|
1724
|
+
t.addEventListener("abort", a, { once: !0 }), t.aborted && a(), Promise.resolve(e).then(
|
|
1725
|
+
(s) => {
|
|
1726
|
+
n(), r(s);
|
|
1727
|
+
},
|
|
1728
|
+
(s) => {
|
|
1729
|
+
n(), o(s);
|
|
1730
|
+
}
|
|
1731
|
+
);
|
|
1732
|
+
}) : Promise.resolve(e);
|
|
1733
|
+
}
|
|
1734
|
+
function Go(e, t) {
|
|
1735
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
1736
|
+
throw new C("validate", `报表 ${t} 的数据集应为对象`);
|
|
1737
|
+
for (const [r, o] of Object.entries(e))
|
|
1738
|
+
if (!Array.isArray(o) || o.some((n) => !n || typeof n != "object" || Array.isArray(n)))
|
|
1739
|
+
throw new C("validate", `报表 ${t} 的数据集 ${r} 应为对象数组`);
|
|
1740
|
+
}
|
|
1741
|
+
async function Vo(e, t, r) {
|
|
1742
|
+
const { reportId: o, signal: n } = t;
|
|
1743
|
+
try {
|
|
1744
|
+
const a = await be(e(t), n);
|
|
1745
|
+
$(n);
|
|
1746
|
+
const s = sr(a);
|
|
1747
|
+
if (!s.ok)
|
|
1748
|
+
throw new C("validate", `报表 ${o} 模板校验失败:${s.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ")}`);
|
|
1749
|
+
return r.push(...s.warnings.map((i) => `${o}: ${i.path}: ${i.message}`)), a;
|
|
1750
|
+
} catch (a) {
|
|
1751
|
+
throw n?.aborted ? de(n) : a instanceof C ? a : a instanceof ir ? new C("validate", `报表 ${o} 模板校验失败:${a.message}`, a) : new C("fetch", `报表 ${o} 模板加载失败:${a instanceof Error ? a.message : String(a)}`, a);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
async function Wo(e, t, r, o) {
|
|
1755
|
+
const n = t.signal;
|
|
1756
|
+
let a;
|
|
1757
|
+
try {
|
|
1758
|
+
if (e.load) a = await be(e.load(t), n);
|
|
1759
|
+
else if (e.provider) {
|
|
1760
|
+
const s = await be(e.provider.query(t), n);
|
|
1761
|
+
$(n), Jo(s, r), a = s.datasets, o?.(r, s);
|
|
1762
|
+
} else a = e.datasets ?? {};
|
|
1763
|
+
} catch (s) {
|
|
1764
|
+
throw n?.aborted ? de(n) : s instanceof C ? s : new C("fetch", `报表 ${r} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
|
|
1765
|
+
}
|
|
1766
|
+
return $(n), a;
|
|
1767
|
+
}
|
|
1768
|
+
function Jo(e, t) {
|
|
1769
|
+
if (!e || typeof e != "object" || Array.isArray(e)) throw new C("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
|
|
1770
|
+
for (const r of ["revision", "sourceToken"])
|
|
1771
|
+
if (e[r] !== void 0 && typeof e[r] != "string") throw new C("validate", `报表 ${t} Provider ${r} 应为字符串`);
|
|
1772
|
+
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))))
|
|
1773
|
+
throw new C("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
|
|
1774
|
+
if (e.diagnostics?.some((r) => !Ho(r)))
|
|
1775
|
+
throw new C("validate", `报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`);
|
|
1776
|
+
}
|
|
1777
|
+
function zo(e, t, r, o, n) {
|
|
1778
|
+
try {
|
|
1779
|
+
t = Ot(o, t, { maxRows: e.dataValidation?.maxRows, signal: n });
|
|
1780
|
+
} catch (a) {
|
|
1781
|
+
throw new C("validate", `报表 ${r} 树形数据无效:${a instanceof Error ? a.message : String(a)}`, a);
|
|
1782
|
+
}
|
|
1783
|
+
for (const [a, s] of Object.entries(e.dataSchema ?? {})) {
|
|
1784
|
+
let i;
|
|
1785
|
+
try {
|
|
1786
|
+
i = Ze(Object.prototype.hasOwnProperty.call(t, a) ? t[a] : void 0, s, { ...e.dataValidation, path: `$.datasets.${a}` });
|
|
1787
|
+
} catch (c) {
|
|
1788
|
+
throw new C("config", `报表 ${r} 数据集 ${a} 字段契约配置无效`, c);
|
|
1789
|
+
}
|
|
1790
|
+
if (!i.ok) throw new C("validate", `报表 ${r} 数据集 ${a} 不符合字段契约:${i.issues[0]?.message}`, { issues: i.issues });
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
function _o(e, t, r, o, n, a) {
|
|
1794
|
+
try {
|
|
1795
|
+
const s = jt(r.pagination, n, e, t, a), i = mt(e, t, s);
|
|
1796
|
+
return Lt(n, i), i;
|
|
1797
|
+
} catch (s) {
|
|
1798
|
+
const i = Ht(s, n);
|
|
1799
|
+
throw new C("validate", `报表 ${o} 排版失败:${i instanceof Error ? i.message : String(i)}`, i);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
function Dt(e, t, r, o, n) {
|
|
1803
|
+
const a = /* @__PURE__ */ new Map(), s = (i) => {
|
|
1804
|
+
let c = a.get(i);
|
|
1805
|
+
return c === void 0 && (c = JSON.stringify([r, o, i]), a.set(i, c)), c;
|
|
1806
|
+
};
|
|
1807
|
+
for (const i of t.pages) e.push({
|
|
1808
|
+
...i,
|
|
1809
|
+
meta: { ...i.meta, reportScope: At(r, o) },
|
|
1810
|
+
components: Kt(i.components, n ?? Nt(r, o), s)
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
async function qo(e, t, r, o, n) {
|
|
1814
|
+
const a = [], s = we(o);
|
|
1815
|
+
for (const [l, d] of e.entries()) {
|
|
1816
|
+
$(n);
|
|
1817
|
+
try {
|
|
1818
|
+
const f = await Rt(d.template, d.datasets, jt(t[l]?.pagination, s, d.template, d.datasets, n));
|
|
1819
|
+
Lt(s, f), Dt(a, f.plan, l, r[l], d.sourceScope);
|
|
1820
|
+
} catch (f) {
|
|
1821
|
+
throw Ht(f, s);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
const i = { schemaVersion: te, ...e.some((l) => ae(l.template)) ? { requiresRecalculation: !0 } : {}, pages: a }, c = Qe(i);
|
|
1825
|
+
if (!c.ok) throw new C("validate", `重算渲染计划校验失败:${c.errors[0]?.message}`);
|
|
1826
|
+
return i;
|
|
1827
|
+
}
|
|
1828
|
+
function En(e, t = {}) {
|
|
1829
|
+
if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new C("config", "maxPages 应为正安全整数");
|
|
1830
|
+
if (t.maxCells !== void 0 && (!Number.isSafeInteger(t.maxCells) || t.maxCells < 1)) throw new C("config", "maxCells 应为正安全整数");
|
|
1831
|
+
try {
|
|
1832
|
+
we(t);
|
|
1833
|
+
} catch (n) {
|
|
1834
|
+
throw new C("config", "maxChartComponents 应为 1..1000000 的安全整数", n);
|
|
1835
|
+
}
|
|
1836
|
+
function r(n) {
|
|
1837
|
+
const a = Object.prototype.hasOwnProperty.call(e, n) ? e[n] : void 0;
|
|
1838
|
+
if (!a) throw new C("config", `未注册报表 ${n}`);
|
|
1839
|
+
if (a.sourceScope !== void 0 && (typeof a.sourceScope != "string" || !a.sourceScope.trim() || a.sourceScope.length > 512)) throw new C("config", "sourceScope 应为不超过 512 字符的非空字符串");
|
|
1840
|
+
return a;
|
|
1841
|
+
}
|
|
1842
|
+
return Object.assign(async ({ reportIds: n, params: a, signal: s, onWarning: i, onQueryResult: c, ...l }) => {
|
|
1843
|
+
$(s);
|
|
1844
|
+
const d = jo({ ...l, signal: s }), f = [...n], u = { ...a };
|
|
1845
|
+
if (f.length === 0) throw new C("config", "缺少报表 ID");
|
|
1846
|
+
const h = f.map(r), m = d.runSync("validate", () => h.map((p) => Oe(
|
|
1847
|
+
p.params ?? (typeof p.template == "function" ? [] : p.template.params) ?? [],
|
|
1848
|
+
u
|
|
1849
|
+
))), v = [], y = [], g = we(t), w = [];
|
|
1850
|
+
for (const [p, b] of h.entries()) {
|
|
1851
|
+
$(s);
|
|
1852
|
+
const S = f[p], T = { reportId: S, params: m[p], signal: s }, k = typeof b.template == "function" ? await d.run("query", () => Vo(b.template, T, w), S) : b.template;
|
|
1853
|
+
T.params = d.runSync("validate", () => Oe(b.params ?? k.params ?? [], T.params), S);
|
|
1854
|
+
const R = await d.run("query", () => Wo(b, T, S, (ue, Bt) => c?.(ue, Bt, p)), S);
|
|
1855
|
+
d.runSync("validate", () => {
|
|
1856
|
+
Go(R, S), t.onDatasets?.(S, R, k), zo(b, R, S, k, s);
|
|
1857
|
+
}, S), $(s);
|
|
1858
|
+
const j = d.runSync("layout", () => _o(k, R, b, S, g, s), S), Fe = Nt(p, S, b.sourceScope);
|
|
1859
|
+
y.push({ template: k, datasets: R, sourceScope: Fe }), Dt(v, j.plan, p, S, Fe), w.push(...j.warnings.map((ue) => `${S}: ${ue}`));
|
|
1860
|
+
}
|
|
1861
|
+
$(s);
|
|
1862
|
+
const x = { schemaVersion: te, ...y.some((p) => ae(p.template)) ? { requiresRecalculation: !0 } : {}, pages: v }, P = d.runSync("validate", () => {
|
|
1863
|
+
const p = Qe(x);
|
|
1864
|
+
if (!p.ok) throw new C("validate", `渲染计划校验失败:${p.errors.slice(0, 3).map((b) => `${b.path}: ${b.message}`).join("; ")}`);
|
|
1865
|
+
return p;
|
|
1866
|
+
});
|
|
1867
|
+
w.push(...P.warnings.map((p) => `${p.path}: ${p.message}`));
|
|
1868
|
+
const E = h.map((p) => ({ ...p, pagination: { ...p.pagination } })), O = { maxPages: t.maxPages, maxCells: t.maxCells, maxChartComponents: t.maxChartComponents };
|
|
1869
|
+
try {
|
|
1870
|
+
It(x, { parts: y, validationFormulas: E.map((p) => p.pagination?.formula), rebuild: (p, b) => qo(p, E, f, O, b) });
|
|
1871
|
+
} catch {
|
|
1872
|
+
w.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算");
|
|
1873
|
+
}
|
|
1874
|
+
const A = i ?? t.onWarning ?? ((p) => console.warn("[mach-report]", p));
|
|
1875
|
+
for (const p of w)
|
|
1876
|
+
$(s), A(p);
|
|
1877
|
+
return $(s), x;
|
|
1878
|
+
}, {
|
|
1879
|
+
getParamDefs: (n) => cr(e, n)
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
function Tn(e, t) {
|
|
1883
|
+
const r = t.maxNodes ?? 1e6;
|
|
1884
|
+
if (![t.maxBytes, r].every((d) => Number.isSafeInteger(d) && d > 0)) throw t.error("budget", "快照预算应为正安全整数");
|
|
1885
|
+
let o = 0, n = 0;
|
|
1886
|
+
const a = /* @__PURE__ */ new Set();
|
|
1887
|
+
function s(d) {
|
|
1888
|
+
if (n += d, n > t.maxBytes) throw t.error("budget", "快照超过字节预算");
|
|
1889
|
+
}
|
|
1890
|
+
function i(d, f) {
|
|
1891
|
+
if (++o > r || f > 64) throw t.error("budget", "快照节点或深度超过预算");
|
|
1892
|
+
if (o % 1024 === 0 && t.check?.(), typeof d == "string")
|
|
1893
|
+
return s(d.length + 2), d;
|
|
1894
|
+
if (d === null || typeof d == "boolean" || typeof d == "number" && Number.isFinite(d))
|
|
1895
|
+
return s(String(d).length), d;
|
|
1896
|
+
if (!d || typeof d != "object" || a.has(d)) throw t.error("input", "快照应为无循环的有限 JSON 值");
|
|
1897
|
+
return c(d, f);
|
|
1898
|
+
}
|
|
1899
|
+
function c(d, f) {
|
|
1900
|
+
const u = Array.isArray(d), h = Object.getPrototypeOf(d);
|
|
1901
|
+
if (h !== (u ? Array.prototype : Object.prototype) && !(h === null && !u) || Object.getOwnPropertySymbols(d).length) throw t.error("input", "快照应为普通 JSON 对象");
|
|
1902
|
+
const m = Object.getOwnPropertyNames(d).filter((g) => !(u && g === "length"));
|
|
1903
|
+
if (u && (m.length !== d.length || m.some((g, w) => g !== String(w)))) throw t.error("input", "快照数组应为连续数组");
|
|
1904
|
+
a.add(d), s(2);
|
|
1905
|
+
const v = /* @__PURE__ */ Object.create(null);
|
|
1906
|
+
let y = 0;
|
|
1907
|
+
for (const g of m) {
|
|
1908
|
+
const w = Object.getOwnPropertyDescriptor(d, g);
|
|
1909
|
+
if (w.get || w.set || !w.enumerable || ["__proto__", "constructor", "prototype"].includes(g)) throw t.error("input", "快照不允许访问器或危险键");
|
|
1910
|
+
w.value === void 0 && !u || (s((y++ ? 1 : 0) + (u ? 0 : g.length + 3)), v[g] = i(w.value === void 0 ? null : w.value, f + 1));
|
|
1911
|
+
}
|
|
1912
|
+
return a.delete(d), u ? m.map((g) => v[g]) : v;
|
|
1913
|
+
}
|
|
1914
|
+
t.check?.();
|
|
1915
|
+
const l = JSON.stringify(i(e, 0));
|
|
1916
|
+
if (new TextEncoder().encode(l).byteLength > t.maxBytes) throw t.error("budget", "快照超过字节预算");
|
|
1917
|
+
return JSON.parse(l);
|
|
1918
|
+
}
|
|
1919
|
+
export {
|
|
1920
|
+
mt as A,
|
|
1921
|
+
un as B,
|
|
1922
|
+
Mr as C,
|
|
1923
|
+
Er as D,
|
|
1924
|
+
It as E,
|
|
1925
|
+
bn as F,
|
|
1926
|
+
F as G,
|
|
1927
|
+
yn as H,
|
|
1928
|
+
mn as I,
|
|
1929
|
+
Ge as J,
|
|
1930
|
+
Ot as K,
|
|
1931
|
+
xn as L,
|
|
1932
|
+
Nt as M,
|
|
1933
|
+
Ie as N,
|
|
1934
|
+
q as O,
|
|
1935
|
+
X as P,
|
|
1936
|
+
jo as Q,
|
|
1937
|
+
C as R,
|
|
1938
|
+
Cn as S,
|
|
1939
|
+
Ko as T,
|
|
1940
|
+
At as U,
|
|
1941
|
+
M as a,
|
|
1942
|
+
Y as b,
|
|
1943
|
+
G as c,
|
|
1944
|
+
kn as d,
|
|
1945
|
+
ro as e,
|
|
1946
|
+
gn as f,
|
|
1947
|
+
wn as g,
|
|
1948
|
+
Co as h,
|
|
1949
|
+
Ct as i,
|
|
1950
|
+
io as j,
|
|
1951
|
+
dn as k,
|
|
1952
|
+
hn as l,
|
|
1953
|
+
pn as m,
|
|
1954
|
+
H as n,
|
|
1955
|
+
Mn as o,
|
|
1956
|
+
bt as p,
|
|
1957
|
+
En as q,
|
|
1958
|
+
fn as r,
|
|
1959
|
+
Tn as s,
|
|
1960
|
+
Sn as t,
|
|
1961
|
+
_ as u,
|
|
1962
|
+
$e as v,
|
|
1963
|
+
vn as w,
|
|
1964
|
+
Ho as x,
|
|
1965
|
+
Ft as y,
|
|
1966
|
+
Lo as z
|
|
1967
|
+
};
|