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