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