@agile-team/mach-report 2.13.0 → 2.15.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 (260) hide show
  1. package/README.md +20 -7
  2. package/THIRD_PARTY_NOTICES.md +3 -1
  3. package/dist/ExcelBindingWizard-BKH1nGNS.js +1485 -0
  4. package/dist/ExcelBindingWizard-Bs43BGNp.cjs +1 -0
  5. package/dist/ParamEditor-Da4akw6V.cjs +1 -0
  6. package/dist/ParamEditor-DoAhzJsm.js +594 -0
  7. package/dist/{ReportBatchPanel-CW2HV9I8.js → ReportBatchPanel-BMf6boMA.js} +39 -39
  8. package/dist/ReportBatchPanel-wP9m9Pj1.cjs +1 -0
  9. package/dist/ReportPreview-ChV19HBp.js +4619 -0
  10. package/dist/ReportPreview-DbLvvOUT.cjs +6 -0
  11. package/dist/{ReportTemplateLibrary-BZB-XWjj.js → ReportTemplateLibrary-C9wutIiT.js} +1 -1
  12. package/dist/ReportTemplateLibrary-Sxr3eD0J.cjs +1 -0
  13. package/dist/RuleEditor-C_Clasvd.js +2037 -0
  14. package/dist/RuleEditor-XhGHK8DE.cjs +1 -0
  15. package/dist/TemplateOutlinePanel-D6Bkny59.js +96 -0
  16. package/dist/TemplateOutlinePanel-JTSR53vJ.cjs +1 -0
  17. package/dist/TemplateReusePanel-Kx35S0Ql.cjs +1 -0
  18. package/dist/TemplateReusePanel-rVuK1kTz.js +388 -0
  19. package/dist/TemplateReviewPanel-B0ar9_zf.js +592 -0
  20. package/dist/TemplateReviewPanel-Dn6X9UmY.cjs +1 -0
  21. package/dist/analytics.cjs +1 -1
  22. package/dist/analytics.d.cts +3 -1
  23. package/dist/analytics.d.ts +3 -1
  24. package/dist/analytics.js +154 -60
  25. package/dist/artifact-integrity.json +135 -0
  26. package/dist/assets-B9ImAi6_.cjs +1 -0
  27. package/dist/assets-DEaz4qsp.js +124 -0
  28. package/dist/batch-BaP6pWDE.cjs +1 -0
  29. package/dist/batch-BfZHN1do.js +220 -0
  30. package/dist/batch-CGyt-b2W.js +273 -0
  31. package/dist/batch-CLpELXBl.cjs +1 -0
  32. package/dist/capabilities-CAh2Nrue.cjs +1 -0
  33. package/dist/capabilities-DskCHs3V.js +69 -0
  34. package/dist/codes.d.cts +2 -0
  35. package/dist/codes.d.ts +2 -0
  36. package/dist/{computed-Bvk0W15F.js → computed-C-4C2S5h.js} +3 -3
  37. package/dist/config-BVsJXSqS.js +842 -0
  38. package/dist/config-D10us76d.cjs +1 -0
  39. package/dist/data-explanation-B8MZRYVS.js +16 -0
  40. package/dist/data-explanation-DE55G30w.cjs +1 -0
  41. package/dist/designer-2bDlcNXQ.js +5136 -0
  42. package/dist/designer-BT7XCdbW.cjs +2 -0
  43. package/dist/designer.cjs +1 -2
  44. package/dist/designer.d.cts +432 -17
  45. package/dist/designer.d.ts +432 -17
  46. package/dist/designer.js +21 -4312
  47. package/dist/drill-ByJviLXS.js +145 -0
  48. package/dist/drill-DYTxuL3A.cjs +1 -0
  49. package/dist/font-loader-B_UkxpzC.cjs +1 -0
  50. package/dist/font-loader-Q3bQjmrI.js +297 -0
  51. package/dist/index.cjs +8 -8
  52. package/dist/index.d.cts +239 -5
  53. package/dist/index.d.ts +239 -5
  54. package/dist/index.js +939 -893
  55. package/dist/json-snapshot-DFb2eWkf.js +1416 -0
  56. package/dist/json-snapshot-WWSGlaHG.cjs +2 -0
  57. package/dist/licenses/_bwip-js_generic-4.11.4.txt +24 -0
  58. package/dist/licenses/_fast-csv_format-4.3.5.txt +22 -0
  59. package/dist/licenses/_fast-csv_parse-4.3.6.txt +22 -0
  60. package/dist/licenses/_pdf-lib_fontkit-1.1.1.txt +326 -0
  61. package/dist/licenses/_pdf-lib_standard-fonts-1.0.0.txt +22 -0
  62. package/dist/licenses/_pdf-lib_upng-1.0.1.txt +22 -0
  63. package/dist/licenses/_types_node-14.18.63.txt +22 -0
  64. package/dist/licenses/_types_pako-2.0.3.txt +22 -0
  65. package/dist/licenses/_types_pegjs-0.10.6.txt +22 -0
  66. package/dist/licenses/archiver-5.3.2.txt +23 -0
  67. package/dist/licenses/archiver-utils-2.1.0.txt +23 -0
  68. package/dist/licenses/archiver-utils-3.0.4.txt +23 -0
  69. package/dist/licenses/async-3.2.6.txt +20 -0
  70. package/dist/licenses/balanced-match-1.0.2.txt +22 -0
  71. package/dist/licenses/base64-js-1.5.1.txt +22 -0
  72. package/dist/licenses/big-integer-1.6.52.txt +25 -0
  73. package/dist/licenses/binary-0.3.0.txt +178 -0
  74. package/dist/licenses/bl-4.1.0.txt +14 -0
  75. package/dist/licenses/bluebird-3.4.7.txt +22 -0
  76. package/dist/licenses/brace-expansion-1.1.21.txt +22 -0
  77. package/dist/licenses/brace-expansion-2.1.7.txt +22 -0
  78. package/dist/licenses/buffer-5.7.1.txt +22 -0
  79. package/dist/licenses/buffer-crc32-0.2.13.txt +20 -0
  80. package/dist/licenses/buffer-indexof-polyfill-1.0.2.txt +23 -0
  81. package/dist/licenses/buffers-0.1.1.txt +140 -0
  82. package/dist/licenses/chainsaw-0.1.0.txt +184 -0
  83. package/dist/licenses/compress-commons-4.1.2.txt +23 -0
  84. package/dist/licenses/concat-map-0.0.1.txt +19 -0
  85. package/dist/licenses/core-util-is-1.0.3.txt +20 -0
  86. package/dist/licenses/crc-32-1.2.2.txt +202 -0
  87. package/dist/licenses/crc32-stream-4.0.3.txt +23 -0
  88. package/dist/licenses/dayjs-1.11.23.txt +22 -0
  89. package/dist/licenses/duplexer2-0.1.4.txt +27 -0
  90. package/dist/licenses/end-of-stream-1.4.5.txt +22 -0
  91. package/dist/licenses/exceljs-4.4.0.txt +23 -0
  92. package/dist/licenses/fast-csv-4.3.6.txt +22 -0
  93. package/dist/licenses/fast-png-6.4.0.txt +22 -0
  94. package/dist/licenses/fs-constants-1.0.0.txt +22 -0
  95. package/dist/licenses/fs.realpath-1.0.0.txt +44 -0
  96. package/dist/licenses/fstream-1.0.12.txt +16 -0
  97. package/dist/licenses/glob-7.2.3.txt +22 -0
  98. package/dist/licenses/graceful-fs-4.2.11.txt +16 -0
  99. package/dist/licenses/ieee754-1.2.1.txt +12 -0
  100. package/dist/licenses/immediate-3.0.6.txt +21 -0
  101. package/dist/licenses/inflight-1.0.6.txt +16 -0
  102. package/dist/licenses/inherits-2.0.4.txt +17 -0
  103. package/dist/licenses/iobuffer-5.4.0.txt +23 -0
  104. package/dist/licenses/isarray-1.0.0.txt +61 -0
  105. package/dist/licenses/jszip-3.10.2.txt +652 -0
  106. package/dist/licenses/lazystream-1.0.1.txt +24 -0
  107. package/dist/licenses/lie-3.3.0.txt +8 -0
  108. package/dist/licenses/listenercount-1.0.1.txt +6 -0
  109. package/dist/licenses/lodash.defaults-4.2.0.txt +48 -0
  110. package/dist/licenses/lodash.difference-4.5.0.txt +48 -0
  111. package/dist/licenses/lodash.escaperegexp-4.1.2.txt +48 -0
  112. package/dist/licenses/lodash.flatten-4.4.0.txt +48 -0
  113. package/dist/licenses/lodash.groupby-4.6.0.txt +48 -0
  114. package/dist/licenses/lodash.isboolean-3.0.3.txt +23 -0
  115. package/dist/licenses/lodash.isequal-4.5.0.txt +48 -0
  116. package/dist/licenses/lodash.isfunction-3.0.9.txt +48 -0
  117. package/dist/licenses/lodash.isnil-4.0.0.txt +23 -0
  118. package/dist/licenses/lodash.isplainobject-4.0.6.txt +48 -0
  119. package/dist/licenses/lodash.isundefined-3.0.1.txt +23 -0
  120. package/dist/licenses/lodash.union-4.6.0.txt +48 -0
  121. package/dist/licenses/lodash.uniq-4.5.0.txt +48 -0
  122. package/dist/licenses/minimatch-3.1.5.txt +16 -0
  123. package/dist/licenses/minimatch-5.1.9.txt +16 -0
  124. package/dist/licenses/minimist-1.2.8.txt +19 -0
  125. package/dist/licenses/mkdirp-0.5.6.txt +22 -0
  126. package/dist/licenses/node-sql-parser-5.4.0.txt +202 -0
  127. package/dist/licenses/normalize-path-3.0.0.txt +22 -0
  128. package/dist/licenses/once-1.4.0.txt +16 -0
  129. package/dist/licenses/pako-1.0.11.txt +22 -0
  130. package/dist/licenses/pako-2.2.0.txt +22 -0
  131. package/dist/licenses/path-is-absolute-1.0.1.txt +22 -0
  132. package/dist/licenses/pdf-lib-1.17.1.txt +22 -0
  133. package/dist/licenses/process-nextick-args-2.0.1.txt +20 -0
  134. package/dist/licenses/readable-stream-2.3.8.txt +48 -0
  135. package/dist/licenses/readable-stream-3.6.2.txt +48 -0
  136. package/dist/licenses/readdir-glob-1.1.3.txt +202 -0
  137. package/dist/licenses/rimraf-2.7.1.txt +16 -0
  138. package/dist/licenses/safe-buffer-5.1.2.txt +22 -0
  139. package/dist/licenses/safe-buffer-5.2.1.txt +22 -0
  140. package/dist/licenses/saxes-5.0.1.txt +397 -0
  141. package/dist/licenses/setimmediate-1.0.5.txt +21 -0
  142. package/dist/licenses/string_decoder-1.1.1.txt +49 -0
  143. package/dist/licenses/string_decoder-1.3.0.txt +49 -0
  144. package/dist/licenses/tar-stream-2.2.0.txt +22 -0
  145. package/dist/licenses/tmp-0.2.7.txt +22 -0
  146. package/dist/licenses/traverse-0.3.9.txt +25 -0
  147. package/dist/licenses/tslib-1.14.1.txt +13 -0
  148. package/dist/licenses/unzipper-0.10.14.txt +26 -0
  149. package/dist/licenses/util-deprecate-1.0.2.txt +25 -0
  150. package/dist/licenses/uuid-11.1.1.txt +10 -0
  151. package/dist/licenses/wrappy-1.0.2.txt +16 -0
  152. package/dist/licenses/xmlchars-2.2.0.txt +19 -0
  153. package/dist/licenses/zip-stream-4.1.1.txt +23 -0
  154. package/dist/matrix-CGRGkn5s.js +112 -0
  155. package/dist/matrix-gEO7ZM_u.cjs +1 -0
  156. package/dist/media-B7vnpD8k.cjs +1 -0
  157. package/dist/media-Y90dHK9z.js +70 -0
  158. package/dist/param-validation-C3HlcLLO.cjs +1 -0
  159. package/dist/param-validation-Do7Eg8Zv.js +181 -0
  160. package/dist/pdf-BwNyeGpt.js +36352 -0
  161. package/dist/pdf-CvvrjPQg.cjs +103 -0
  162. package/dist/pdf.cjs +1 -101
  163. package/dist/pdf.d.cts +18 -3
  164. package/dist/pdf.d.ts +18 -3
  165. package/dist/pdf.js +9 -36579
  166. package/dist/plugin-Ca_XZG3l.js +22 -0
  167. package/dist/{plugin-DzS6pxTA.cjs → plugin-DHO7X8z2.cjs} +1 -1
  168. package/dist/prepared-CFy9B75C.cjs +1 -0
  169. package/dist/prepared-ajM-H-9B.js +69 -0
  170. package/dist/progress-B0ctFpKf.cjs +1 -0
  171. package/dist/progress-D-OTpEav.js +52 -0
  172. package/dist/{record-bindings-D-5jQlTj.js → record-bindings-Do_b3h4V.js} +1 -1
  173. package/dist/{region-binding-workflow-CcUq8W2Q.js → region-binding-workflow-BMhK_TjP.js} +1 -1
  174. package/dist/{region-binding-workflow-BzfbxRiR.cjs → region-binding-workflow-DIYJdCUr.cjs} +1 -1
  175. package/dist/{report-params-B44imUd4.js → report-params-B1RzkhJj.js} +1 -1
  176. package/dist/{report-params-SJfhKgaX.cjs → report-params-WDGrA4oP.cjs} +1 -1
  177. package/dist/sbom.cdx.json +3982 -0
  178. package/dist/server/node.d.cts +66 -12
  179. package/dist/server/node.d.ts +66 -12
  180. package/dist/server-node.cjs +1 -1
  181. package/dist/server-node.js +405 -381
  182. package/dist/server.cjs +1 -1
  183. package/dist/server.d.cts +878 -15
  184. package/dist/server.d.ts +878 -15
  185. package/dist/server.js +1034 -534
  186. package/dist/sha256-ArEYjaTI.cjs +1 -0
  187. package/dist/sha256-DPEuJ3nh.js +155 -0
  188. package/dist/style.css +1 -1
  189. package/dist/template-bindings-C2SpvsMU.js +58 -0
  190. package/dist/template-bindings-CEtWyiLX.cjs +1 -0
  191. package/dist/template-catalog-FJE_c9Qe.cjs +1 -0
  192. package/dist/template-catalog-j2B1MJlL.js +414 -0
  193. package/dist/template-fragments-BGbQLGlV.js +187 -0
  194. package/dist/template-fragments-DcKeiylI.cjs +1 -0
  195. package/dist/template-outline-BwRV_eRo.cjs +1 -0
  196. package/dist/template-outline-cnWfT_LK.js +88 -0
  197. package/dist/{template-registry-BjE1VS6g.js → template-registry-BtaKPELV.js} +364 -201
  198. package/dist/template-registry-Co1zPq5e.cjs +1 -0
  199. package/dist/textwrap-CWHyzkBH.cjs +4 -0
  200. package/dist/textwrap-DE1kgcJB.js +110 -0
  201. package/dist/{tree-CqcQ99NM.js → tree-CjVZLRw7.js} +1 -1
  202. package/dist/{useLocalDraft-C07SYRnC.js → useLocalDraft-BnhcxXk_.js} +1 -1
  203. package/dist/{useLocalDraft-Yiw1wFgI.cjs → useLocalDraft-CioIfDb6.cjs} +1 -1
  204. package/dist/vue/async.d.cts +190 -15
  205. package/dist/vue/async.d.ts +190 -15
  206. package/dist/vue/index.d.cts +274 -24
  207. package/dist/vue/index.d.ts +274 -24
  208. package/dist/vue-async.cjs +1 -1
  209. package/dist/vue-async.js +5 -5
  210. package/dist/vue.cjs +1 -1
  211. package/dist/vue.js +90 -81
  212. package/dist/{workbook-session-DNa2RHNG.cjs → workbook-session-Bjv1YCRK.cjs} +18 -18
  213. package/dist/{workbook-session-BPb3TMnT.js → workbook-session-BvToI-Fd.js} +5440 -5288
  214. package/dist/worker.cjs +1 -1
  215. package/dist/worker.d.cts +66 -12
  216. package/dist/worker.d.ts +66 -12
  217. package/dist/worker.js +61 -56
  218. package/dist/xlsx-node.cjs +34 -34
  219. package/dist/xlsx-node.js +878 -870
  220. package/dist/xlsx.cjs +3 -4
  221. package/dist/xlsx.d.cts +22 -10
  222. package/dist/xlsx.d.ts +22 -10
  223. package/dist/xlsx.js +261 -253
  224. package/package.json +2 -2
  225. package/dist/ExcelBindingWizard-CeAf4QSE.js +0 -1465
  226. package/dist/ExcelBindingWizard-y0mT-AHR.cjs +0 -1
  227. package/dist/ParamEditor-BLaE5q5W.js +0 -522
  228. package/dist/ParamEditor-MBBC7lUE.cjs +0 -1
  229. package/dist/ReportBatchPanel-Fp1ePFag.cjs +0 -1
  230. package/dist/ReportPreview-BN6fk7Wz.cjs +0 -6
  231. package/dist/ReportPreview-D2Jkyh1U.js +0 -4243
  232. package/dist/ReportTemplateLibrary-5fk5CQBO.cjs +0 -1
  233. package/dist/RuleEditor-ChRzNQuF.cjs +0 -1
  234. package/dist/RuleEditor-DzAmW5YH.js +0 -2024
  235. package/dist/TemplateReviewPanel-BKofGrV9.js +0 -222
  236. package/dist/TemplateReviewPanel-DwtOcLue.cjs +0 -1
  237. package/dist/assets-C2U-e-Sz.cjs +0 -4
  238. package/dist/assets-Q0wUwNrV.js +0 -217
  239. package/dist/batch-Bt3Fd27Z.cjs +0 -1
  240. package/dist/batch-mRqhhhjt.js +0 -364
  241. package/dist/capabilities-CK_7hizc.js +0 -63
  242. package/dist/capabilities-CsZ-pNHR.cjs +0 -1
  243. package/dist/config-Bb7RiIO5.cjs +0 -1
  244. package/dist/config-XVwG87IA.js +0 -529
  245. package/dist/matrix-DVyWiYsd.cjs +0 -1
  246. package/dist/matrix-yZsGnldA.js +0 -227
  247. package/dist/page-window-index-CIuT4BAv.js +0 -43
  248. package/dist/page-window-index-DEjnM6IB.cjs +0 -1
  249. package/dist/param-validation-BlHHXs6u.js +0 -153
  250. package/dist/param-validation-DCK039V1.cjs +0 -1
  251. package/dist/plugin-D4wizDXB.js +0 -22
  252. package/dist/progress-7OSZbFok.js +0 -39
  253. package/dist/progress-BnLiS5eH.cjs +0 -1
  254. package/dist/task-events-DQ276fn2.cjs +0 -1
  255. package/dist/task-events-Dpsvf_t2.js +0 -47
  256. package/dist/template-registry-D3SjENi6.cjs +0 -1
  257. package/dist/template-review-DGwWOoCv.cjs +0 -2
  258. package/dist/template-review-PgEe_Wr9.js +0 -1742
  259. package/dist/validate-BJ5HIWY8.cjs +0 -1
  260. package/dist/validate-DbgEM1Hh.js +0 -163
@@ -0,0 +1,1416 @@
1
+ import { R as z } from "./render-plan-Ck6koX9L.js";
2
+ import { c as mt, D as Pe, L as Te } from "./defaults-DXhiM1ZD.js";
3
+ import { w as q, h as ke } from "./textwrap-DE1kgcJB.js";
4
+ import { R as C, g as $e, b as gt, i as ht, e as L, l as ce, c as pt, t as Re, h as Ee, f as xe, j as wt, k as yt } from "./record-bindings-Do_b3h4V.js";
5
+ import { e as Ce, b as bt } from "./computed-C-4C2S5h.js";
6
+ import { e as Mt, c as vt } from "./matrix-CGRGkn5s.js";
7
+ import { f as Oe, a as St, c as Pt } from "./tree-CjVZLRw7.js";
8
+ import { i as Tt, r as kt, j as $t, a as Fe, v as Rt, R as Et } from "./template-registry-BtaKPELV.js";
9
+ import { r as de, b as xt, e as I } from "./style-CQ1PK8ZB.js";
10
+ import { g as Ct } from "./report-params-B1RzkhJj.js";
11
+ import { a as ye } from "./param-validation-Do7Eg8Zv.js";
12
+ import { R as P, r as j, e as le, h as Ae, f as Ot, i as Ft } from "./batch-CGyt-b2W.js";
13
+ import { h as At } from "./data-explanation-B8MZRYVS.js";
14
+ import { d as It, v as jt } from "./dataset-H5pFuQGU.js";
15
+ function Nt(e, t, r) {
16
+ const o = /* @__PURE__ */ new Set(), a = e.cells.map((n, s) => {
17
+ const i = [];
18
+ let c = 0;
19
+ for (const d of n) {
20
+ for (; o.has(`${s}:${c}`); ) c++;
21
+ const l = d?.colSpan ?? 1, f = d?.rowSpan ?? 1;
22
+ let u = 0;
23
+ for (let g = c; g < c + l; g++) {
24
+ t.has(g) && u++;
25
+ for (let h = s + 1; h < s + f; h++)
26
+ o.add(`${h}:${g}`);
27
+ }
28
+ u && i.push(d ? { ...d, colSpan: u } : null), c += l;
29
+ }
30
+ return i;
31
+ });
32
+ return { ...e, cells: a, colWidthsMm: r };
33
+ }
34
+ function Ht(e) {
35
+ if (!e.columns.some((o) => o.hidden)) return e;
36
+ const t = /* @__PURE__ */ new Set(), r = e.columns.filter((o, a) => o.hidden ? !1 : (t.add(a), !0));
37
+ if (!r.length) throw new Error("列表至少需要一列可见列");
38
+ return {
39
+ ...e,
40
+ columns: r,
41
+ ...e.headerGrid ? {
42
+ headerGrid: Nt(
43
+ e.headerGrid,
44
+ t,
45
+ r.map((o) => o.widthMm)
46
+ )
47
+ } : {}
48
+ };
49
+ }
50
+ function* Lt(e) {
51
+ const { page: t } = e;
52
+ Tt(t.components, t.flow);
53
+ let r = 0, o = 0;
54
+ for (const a of kt(t.components, t.flow)) {
55
+ e.active();
56
+ const n = a.band, s = a.components.some((l) => l.kind === "list" && l.cardinality !== "record"), i = s ? 0 : a.components.reduce((l, f) => Math.max(l, f.topMm - n.topMm + (f.kind === "list" ? e.height(f) : f.heightMm)), n.heightMm);
57
+ let c = Math.max(e.top(), o + n.topMm - r);
58
+ if (!s && i > e.bottom() - e.top() + 1e-3) throw new Error(`静态区域 ${n.componentIds.join(",")} 高度超出单页可用范围`);
59
+ !s && c + i > e.bottom() + 1e-3 && (e.nextPage(), yield* e.takePages(), e.active(), c = e.top());
60
+ let d = c + i;
61
+ for (const l of a.components) {
62
+ const f = c + l.topMm - n.topMm;
63
+ l.kind === "list" ? (yield* e.list(l, f, (u) => {
64
+ d = s ? u : Math.max(d, u);
65
+ }), e.active()) : e.append({ ...l, topMm: f });
66
+ }
67
+ o = d, r = n.topMm + n.heightMm;
68
+ }
69
+ }
70
+ function Dt(e) {
71
+ 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));
72
+ }
73
+ function U(e) {
74
+ return e.pages.some((t) => t.components.some((r) => r.kind === "list" && Dt(r)));
75
+ }
76
+ const Kt = 512, be = 256 * 1024;
77
+ function Bt() {
78
+ const e = /* @__PURE__ */ new Map();
79
+ let t = 0, r;
80
+ return (o, a, n, s) => {
81
+ s !== r && (e.clear(), t = 0, r = s);
82
+ const i = JSON.stringify([o, a, n.fontSizePt, n.fontFamily, n.bold, n.italic, n.letterSpacingPt]), c = e.get(i);
83
+ if (c)
84
+ return e.delete(i), e.set(i, c), c.lines.slice();
85
+ const d = q(o, a, n, s), l = i.length + d.reduce((f, u) => f + u.length, 0);
86
+ if (l <= be) {
87
+ for (; e.size >= Kt || t + l > be; ) {
88
+ const f = e.keys().next().value;
89
+ t -= e.get(f).units, e.delete(f);
90
+ }
91
+ e.set(i, { lines: d.slice(), units: l }), t += l;
92
+ }
93
+ return d;
94
+ };
95
+ }
96
+ class N extends Error {
97
+ constructor(t, r) {
98
+ super(`报表页数超出上限 ${t}(至少 ${r} 页)`), this.limit = t, this.actual = r, this.code = "page-limit", this.name = "PaginatePageLimitError";
99
+ }
100
+ }
101
+ class D extends Error {
102
+ constructor(t, r) {
103
+ super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`), this.limit = t, this.actual = r, this.code = "cell-limit", this.name = "PaginateCellLimitError";
104
+ }
105
+ }
106
+ const Wt = 1e4, Me = 25e4;
107
+ function ue(e) {
108
+ if (e?.aborted) throw e.reason ?? new DOMException("标签生成已取消", "AbortError");
109
+ }
110
+ function Ie(e, t, r) {
111
+ const o = typeof e.copies == "object" ? $e(t, e.copies.field, r) : e.copies ?? 1;
112
+ if (typeof o != "number" || !Number.isSafeInteger(o) || o < 1 || o > 1e3) throw new C(`$.datasets.${r.dataset}[${r.rowIndex}]`, "每条记录复制数必须是 1..1000 的数值型整数", r.rowIndex, typeof e.copies == "object" ? e.copies.field : void 0);
113
+ return o;
114
+ }
115
+ function je(e, t, r) {
116
+ if (e.rowKey === void 0) return;
117
+ const o = $e(t, e.rowKey, r);
118
+ if (typeof o == "string" && o.trim() || typeof o == "number" && Number.isFinite(o)) return o;
119
+ throw new C(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`, "业务主键必须是非空字符串或有限数字", r.rowIndex, e.rowKey);
120
+ }
121
+ function Gt(e) {
122
+ const t = (r) => 1 + (r.grid?.cells.reduce((o, a) => o + 1 + a.length + a.reduce((n, s) => n + (s?.children?.reduce((i, c) => i + t(c), 0) ?? 0), 0), 0) ?? 0);
123
+ return e.pages.reduce((r, o) => r + o.components.reduce((a, n) => a + t(n), 0), 0);
124
+ }
125
+ function Vt(e, t, r) {
126
+ const o = e.repeat, a = Object.prototype.hasOwnProperty.call(t, o.dataset) ? t[o.dataset] : void 0;
127
+ if (!Array.isArray(a)) throw new C(`$.datasets.${o.dataset}`, "逐记录标签数据集缺失,应提供对象数组(允许空数组)");
128
+ const n = /* @__PURE__ */ new Set(), s = r.maxPages ?? Wt, i = Gt(e);
129
+ let c = 0, d = 0;
130
+ for (const [l, f] of a.entries()) {
131
+ if (ue(r.signal), !f || typeof f != "object" || Array.isArray(f)) throw new C(`$.datasets.${o.dataset}[${l}]`, "标签记录应为对象", l);
132
+ const u = { rowIndex: l, dataset: o.dataset }, g = je(o, f, u);
133
+ if (g !== void 0) {
134
+ const m = JSON.stringify([typeof g, g]);
135
+ if (n.has(m)) throw new C(`$.datasets.${o.dataset}[${l}].${o.rowKey}`, "业务主键重复;请先确认记录来源,避免重复打印标签", l, o.rowKey);
136
+ n.add(m);
137
+ }
138
+ const h = Ie(o, f, u);
139
+ if (c += h * e.pages.length, d += h * i, c > s) throw new N(s, c);
140
+ if (d > Me) throw new C("$.repeat", `标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Me},请分批生成`, l);
141
+ }
142
+ return a;
143
+ }
144
+ function _t(e, t, r) {
145
+ if (!e.binding) return e;
146
+ const { binding: o, ...a } = e, n = gt(o, t.row, t);
147
+ if (e.kind === "image") {
148
+ if (!n) return;
149
+ if (!ht(n)) throw new C(`${r}.binding`, "图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换", t.rowIndex, o.field);
150
+ return { ...a, imageData: n };
151
+ }
152
+ return e.kind === "barcode" || e.kind === "qrcode" ? (delete a.imageData, { ...a, code: { ...a.code, value: n }, fallbackText: n }) : (delete a.lines, delete a.richParagraphs, { ...a, text: n });
153
+ }
154
+ function Jt(e, t, r) {
155
+ if (e.kind !== "text" || e.grid || e.richParagraphs?.length) return e;
156
+ const o = e.style ?? {}, a = de(o).fontSizePt, n = e.text ?? e.lines?.join(`
157
+ `) ?? "";
158
+ if (n.length > 16384) throw new C(r, "标签文本超过 16384 字符预算,请缩小字段内容", t.rowIndex);
159
+ const s = t.wrapText(n, e.widthMm, { fontSizePt: a, bold: o.bold, italic: o.italic, fontFamily: o.fontFamily, letterSpacingPt: o.letterSpacing }, t.options.measurer ?? ke), i = s.length * a * xt(o) * 25.4 / 72;
160
+ if (i > e.heightMm + 0.05) throw new C(r, `标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`, t.rowIndex, e.binding?.field);
161
+ return { ...e, lines: s };
162
+ }
163
+ function Ne(e, t, r) {
164
+ ue(t.options.signal);
165
+ const o = _t(e, t, r);
166
+ if (!o) return;
167
+ let a = o.grid;
168
+ return a && (a = { ...a, cells: a.cells.map((n, s) => n.map((i, c) => i?.children?.length ? { ...i, children: i.children.flatMap((d, l) => {
169
+ const f = Ne(d, t, `${r}.grid.cells.${s}.${c}.children.${l}`);
170
+ return f ? [f] : [];
171
+ }) } : i)) }), Jt(a === o.grid ? o : { ...o, grid: a }, t, r);
172
+ }
173
+ function zt(e, t, r, o, a, n) {
174
+ return {
175
+ ...e,
176
+ components: e.components.flatMap((s, i) => {
177
+ const c = Ne(s, r, `$.pages.${t}.components.${i}`);
178
+ return c ? [{ ...c, meta: { ...c.meta, labelSource: { pageIndex: t, componentIndex: i } } }] : [];
179
+ }),
180
+ meta: { ...e.meta, record: { dataset: r.dataset, rowIndex: r.rowIndex, ...n === void 0 ? {} : { rowKey: n }, copyIndex: o, copyCount: a, templatePageIndex: t } }
181
+ };
182
+ }
183
+ function* qt(e, t, r) {
184
+ const o = [];
185
+ if ($t(e, o), o.length) throw new C(o[0].path, o[0].message);
186
+ if (!e.repeat) {
187
+ for (const [i, c] of e.pages.entries()) yield { page: c, pageIndex: i };
188
+ return;
189
+ }
190
+ const a = e.repeat, n = Vt(e, t, r), s = Bt();
191
+ for (const [i, c] of n.entries()) {
192
+ const d = { row: c, rowIndex: i, dataset: a.dataset, options: r, wrapText: s }, l = Ie(a, c, d), f = je(a, c, d);
193
+ for (let u = 0; u < l; u++) for (const [g, h] of e.pages.entries())
194
+ ue(r.signal), yield { page: zt(h, g, d, u, l, f), pageIndex: g };
195
+ }
196
+ }
197
+ function Ut(e) {
198
+ return {
199
+ widthMm: e.widthMm,
200
+ heightMm: e.heightMm,
201
+ marginTopMm: e.marginTopMm ?? 0,
202
+ marginBottomMm: e.marginBottomMm ?? 0,
203
+ marginLeftMm: e.marginLeftMm ?? 0,
204
+ marginRightMm: e.marginRightMm ?? 0,
205
+ components: []
206
+ };
207
+ }
208
+ function _(e, t) {
209
+ const r = t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
210
+ return e.components.reduce((o, a) => a.kind !== "list" && a.pageAnchor === "footer" ? Math.min(o, a.topMm) : o, r);
211
+ }
212
+ function B(e) {
213
+ return e.components.reduce((t, r) => r.kind !== "list" && r.pageAnchor === "header" ? Math.max(t, r.topMm + r.heightMm) : t, 0);
214
+ }
215
+ function He(e, t) {
216
+ let r = e.textMetrics.get(t);
217
+ if (!r) {
218
+ const o = de(t).fontSizePt;
219
+ r = {
220
+ measureOptions: {
221
+ fontSizePt: o,
222
+ fontFamily: t.fontFamily ?? Pe,
223
+ italic: t.italic,
224
+ bold: t.bold,
225
+ letterSpacingPt: t.letterSpacing
226
+ },
227
+ lineMm: o * (t.lineHeight ?? Te) * 25.4 / 72
228
+ }, e.textMetrics.set(t, r);
229
+ }
230
+ return r;
231
+ }
232
+ function Xt(e) {
233
+ if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
234
+ }
235
+ function fe(e, t) {
236
+ const r = e.fontSizePt ?? mt, o = e.paddingMm ?? 1, a = e.columns.map((m) => m.align ?? m.style?.align ?? e.align ?? "left"), n = e.columns.map((m, w) => ({
237
+ ...I({
238
+ fontSize: r,
239
+ verticalAlign: "middle"
240
+ }, m.style),
241
+ align: a[w] === "auto" ? "left" : a[w]
242
+ })), s = n.map((m, w) => a[w] === "auto" ? { left: m, center: { ...m, align: "center" }, right: { ...m, align: "right" } } : void 0), i = e.columns.map((m, w) => m.rules?.map((v) => {
243
+ const S = s[w];
244
+ if (S) return {
245
+ left: I(S.left, v.style),
246
+ center: I(S.center, v.style),
247
+ right: I(S.right, v.style)
248
+ };
249
+ const k = I(n[w], v.style);
250
+ return { left: k, center: k, right: k };
251
+ })), c = e.columns.map((m) => pt(e, m)), d = e.columns.map((m) => m.header);
252
+ let l = e.rowHeightMm ?? 0;
253
+ for (let m = 0; m < d.length; m++) {
254
+ const w = c[m], v = de(w).fontSizePt, S = q(
255
+ d[m],
256
+ e.columns[m].widthMm - o * 2,
257
+ { fontSizePt: v, fontFamily: w.fontFamily ?? Pe, italic: w.italic, bold: w.bold, letterSpacingPt: w.letterSpacing },
258
+ t
259
+ ), k = v * (w.lineHeight ?? Te) * 25.4 / 72;
260
+ l = Math.max(l, Math.max(S.length, 1) * k + o * 2);
261
+ }
262
+ const f = d.map((m, w) => ({
263
+ text: m,
264
+ style: c[w]
265
+ })), u = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, g = e.columns.map((m) => m.widthMm), h = Yt(e.headerGrid, g, {
266
+ cells: [f],
267
+ colWidthsMm: g,
268
+ rowHeightsMm: [l],
269
+ paddingMm: o
270
+ });
271
+ return {
272
+ fontSizePt: r,
273
+ paddingMm: o,
274
+ cellStyles: n,
275
+ autoStyles: s,
276
+ ruleStyles: i,
277
+ textMetrics: /* @__PURE__ */ new WeakMap(),
278
+ numberFormats: e.columns.map((m) => Re(m.format)),
279
+ derivedFields: new Set(e.computed?.map((m) => m.field)),
280
+ borderStyle: u,
281
+ headerHeightMm: h.rowHeightsMm.reduce((m, w) => m + w, 0),
282
+ headerGrid: h,
283
+ colWidthsMm: g,
284
+ columns: e.columns
285
+ };
286
+ }
287
+ function Yt(e, t, r) {
288
+ if (!e) return r;
289
+ if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
290
+ const o = e.rowHeightsMm ?? e.cells.map(() => r.rowHeightsMm[0]);
291
+ if (o.length !== e.cells.length || o.some((a) => !Number.isFinite(a) || a <= 0)) throw new Error("自定义列表表头行高无效");
292
+ return { ...e, colWidthsMm: t, rowHeightsMm: o };
293
+ }
294
+ function Qt(e, t, r) {
295
+ const o = t.format?.kind === "number" || t.format?.kind === "percent";
296
+ 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);
297
+ }
298
+ function W(e, t, r) {
299
+ const o = e.columns, a = e.tree?.rows.get(t);
300
+ let n = e.rowHeightFloorMm;
301
+ const s = new Array(o.length);
302
+ for (let i = 0; i < o.length; i++) {
303
+ const c = o[i], d = c.visibleWhen && !L(t, c.visibleWhen) ? null : t[c.field], l = e.autoStyles[i] ? Ee(d, c.format, c.semanticRole) : "left";
304
+ let f = e.autoStyles[i]?.[l] ?? e.cellStyles[i];
305
+ if (c.rules)
306
+ for (let S = 0; S < c.rules.length; S++) {
307
+ const k = c.rules[S];
308
+ if (L(t, k.when)) {
309
+ f = e.ruleStyles[i][S][l];
310
+ break;
311
+ }
312
+ }
313
+ const u = c.format ? xe(d, c.format) : ce(d), g = Zt(e, c, a);
314
+ f = er(e, c, f, a);
315
+ const h = He(e, f), m = q(u, Math.max(1, c.widthMm - e.paddingMm * 2 - g), h.measureOptions, r);
316
+ n = Math.max(n, m.length * h.lineMm + e.paddingMm * 2);
317
+ const w = Xt(d), v = { text: u, style: f };
318
+ w !== void 0 && (v.value = w), Qt(v, c, e.numberFormats[i]), tr(v, c, e, a, g), e.derivedFields.has(c.field) && (v.derived = !0, v.editable = !1), c.visibleWhen && d === null && !L(t, c.visibleWhen) && (v.editable = !1), s[i] = v;
319
+ }
320
+ return {
321
+ grid: { cells: [s], colWidthsMm: e.colWidthsMm, rowHeightsMm: [n], paddingMm: e.paddingMm },
322
+ heightMm: n
323
+ };
324
+ }
325
+ function Zt(e, t, r) {
326
+ return !r || t.field !== e.tree.list.tree.labelField ? 0 : wt(e.tree.list, t, r, e.paddingMm);
327
+ }
328
+ function er(e, t, r, o) {
329
+ return !o || t.field !== e.tree.list.tree.labelField || r.align === "left" ? r : { ...r, align: "left" };
330
+ }
331
+ function tr(e, t, r, o, a = 0) {
332
+ o && (a && (e.indentMm = a), yt(e, t, o, r.tree.list));
333
+ }
334
+ function Le(e) {
335
+ if (e != null && typeof e != "string" && typeof e != "boolean" && !(typeof e == "number" && Number.isFinite(e))) throw new Error("分组字段应为有限 JSON 标量");
336
+ return JSON.stringify([typeof e, e ?? null]);
337
+ }
338
+ function* De(e, t, r = 0) {
339
+ const o = t[r];
340
+ if (!o) {
341
+ for (const n of e) yield { kind: "row", row: n };
342
+ return;
343
+ }
344
+ const a = /* @__PURE__ */ new Map();
345
+ for (const n of e) {
346
+ const s = Le(n[o.field]), i = a.get(s);
347
+ i ? i.push(n) : a.set(s, [n]);
348
+ }
349
+ for (const n of a.values())
350
+ yield { kind: "groupHeader", label: (o.headerTemplate ?? "{value}").replace(/\{value\}/g, ce(n[0][o.field])), firstRow: n[0], group: o, depth: r, rows: n }, yield* De(n, t, r + 1), (o.subtotal?.length || o.aggregates?.length) && (yield { kind: "subtotal", label: o.subtotalLabel ?? "小计", rows: n, group: o, depth: r }), yield { kind: "groupEnd", depth: r };
351
+ }
352
+ function Ke(e, t, r, o = []) {
353
+ const a = [...r.filter((n) => !o.some((s) => s.field === n)).map((n) => ({ field: n, op: "sum" })), ...o];
354
+ return new Map(a.map((n) => {
355
+ const s = e.find((c) => c.field === n.field)?.format ?? { kind: "number", thousands: !0 }, i = bt(t, { ...n, field: n.valueField ?? n.field });
356
+ return [n.field, { text: xe(i, s), ...i === null ? {} : { value: i }, ...typeof i == "number" ? { numberFormat: Re(s) } : {} }];
357
+ }));
358
+ }
359
+ function Be(e, t) {
360
+ const r = e.findIndex((o) => t.includes(o.field));
361
+ return r < 0 ? 1 : r;
362
+ }
363
+ function K(e, t, r, o, a, n) {
364
+ const s = [], i = Math.max(0, Math.min(n, e.columns.length)), c = I({ fontSize: e.fontSizePt }, a);
365
+ i && s.push({ text: r, colSpan: i, style: { bold: !0, ...c } });
366
+ for (let u = i; u < e.columns.length; u++) {
367
+ const g = e.columns[u], h = o.get(g.field), m = e.autoStyles[u]?.[Ee(h?.value, g.format)] ?? e.cellStyles[u];
368
+ s.push({ ...h, text: h?.text ?? "", style: I(m, a) });
369
+ }
370
+ const d = { text: r, colSpan: e.columns.length, style: { bold: !0, ...c } }, l = i ? [s] : [[d], s], f = l.map((u) => rr(e, u, t));
371
+ return {
372
+ grid: { cells: l, colWidthsMm: e.colWidthsMm, rowHeightsMm: f, paddingMm: e.paddingMm },
373
+ heightMm: f.reduce((u, g) => u + g, 0)
374
+ };
375
+ }
376
+ function rr(e, t, r) {
377
+ let o = e.rowHeightFloorMm, a = 0;
378
+ for (const n of t) {
379
+ let s = 0;
380
+ const i = a + (n.colSpan ?? 1);
381
+ for (; a < i; a++) s += e.colWidthsMm[a] ?? 0;
382
+ const c = He(e, n.style), d = q(n.text ?? "", s - e.paddingMm * 2, c.measureOptions, r);
383
+ o = Math.max(o, d.length * c.lineMm + e.paddingMm * 2);
384
+ }
385
+ return o;
386
+ }
387
+ function or(e, t, r) {
388
+ const { templatePage: o, current: a, warnings: n, nextId: s, pushCurrent: i } = r, c = () => _(o, a), d = Math.max(a.marginTopMm, B(o)), l = o.layout === "wide" ? B(o) : d, f = {
389
+ id: r.tableId,
390
+ columnKeys: e.columns.map((p) => p.field),
391
+ ...e.layout === void 0 ? {} : { layout: e.layout },
392
+ ...e.title === void 0 ? {} : { title: e.title }
393
+ }, u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), h = {
394
+ kind: "rect",
395
+ leftMm: e.leftMm,
396
+ topMm: 0,
397
+ widthMm: e.widthMm,
398
+ heightMm: t.headerHeightMm,
399
+ grid: t.headerGrid,
400
+ nid: s("listh"),
401
+ table: { ...f, role: "header", rowIndex: -1 },
402
+ style: t.borderStyle,
403
+ ...e.meta ? { meta: e.meta } : {}
404
+ }, m = (p) => a.components.push({ ...h, topMm: p });
405
+ if (r.flow && e.header !== !1 && t.headerHeightMm > c() - d + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的表头高度超出单页可用范围`);
406
+ let w = Math.max(r.startTop ?? e.topMm, d);
407
+ e.header !== !1 && (m(w), w += t.headerHeightMm + r.mmPerRow);
408
+ function v() {
409
+ const p = Math.max(r.flow || o.layout === "wide" ? 0 : e.topMm, l);
410
+ return (e.header !== !1 && e.headerEveryPage !== !1 ? p + t.headerHeightMm : l) + [...g.values()].reduce((M, $) => M + $.heightMm, 0);
411
+ }
412
+ function S() {
413
+ const p = o.layout === "wide" ? 0 : a.marginBottomMm;
414
+ return Math.min(o.heightMm - p, _(o, a)) - v();
415
+ }
416
+ function k(p) {
417
+ if (w + p <= c()) return;
418
+ i(), a.components = [], a.heightMm = o.heightMm, o.layout === "wide" && (a.marginTopMm = 0, a.marginBottomMm = 0);
419
+ const y = Math.max(r.flow || o.layout === "wide" ? 0 : e.topMm, l);
420
+ e.header !== !1 && e.headerEveryPage !== !1 ? (m(y), w = y + t.headerHeightMm) : w = l;
421
+ for (const M of g.values()) A(M, "listgr", "group-header");
422
+ }
423
+ function b(p, y, M, $) {
424
+ const R = S();
425
+ if (r.flow && p.heightMm > R + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的单行高度超出单页可用范围`);
426
+ p.heightMm > R && n.push(`列表 ${e.id ?? e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${R.toFixed(2)}mm,预览与打印可能截断内容`), k(p.heightMm), A(p, y, M, $);
427
+ }
428
+ function A(p, y, M, $) {
429
+ const R = p.table?.id ?? f.id, F = M === "header" ? -1 : u.get(R) ?? 0;
430
+ M !== "header" && u.set(R, F + p.grid.cells.length), a.components.push({
431
+ kind: "rect",
432
+ leftMm: e.leftMm,
433
+ topMm: w,
434
+ widthMm: e.widthMm,
435
+ heightMm: p.heightMm,
436
+ grid: p.grid,
437
+ nid: s(y),
438
+ table: { ...f, ...p.table, role: M, rowIndex: F, ...$ ? { source: $ } : {} },
439
+ style: t.borderStyle,
440
+ ...e.meta ? { meta: e.meta } : {}
441
+ }), w += p.heightMm;
442
+ }
443
+ function O(p) {
444
+ p <= S() && k(p);
445
+ }
446
+ return { keepTogether: O, placeGridRow: b, setGroupHeader: (p, y) => {
447
+ y ? g.set(p, y) : g.delete(p);
448
+ }, bottom: () => w };
449
+ }
450
+ function nr(e, t) {
451
+ if (!e.rowKey) return;
452
+ const r = t[e.rowKey];
453
+ if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r)))
454
+ throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);
455
+ const o = e.revisionField ? t[e.revisionField] : void 0, a = e.sourceTokenField ? t[e.sourceTokenField] : void 0;
456
+ if (o !== void 0 && typeof o != "string" && !(typeof o == "number" && Number.isFinite(o))) throw new Error("业务修订号应为字符串或有限数字");
457
+ if (a !== void 0 && typeof a != "string") throw new Error("来源令牌应为字符串");
458
+ return { datasetId: e.dataset, rowKey: r, ...o === void 0 ? {} : { revision: o }, ...a === void 0 ? {} : { sourceToken: a } };
459
+ }
460
+ function X(e, t) {
461
+ const r = /* @__PURE__ */ new Map();
462
+ if (!e.rowKey) return r;
463
+ const o = /* @__PURE__ */ new Set();
464
+ for (const a of t) {
465
+ const n = nr(e, a), s = JSON.stringify(n.rowKey);
466
+ if (o.has(s)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(n.rowKey)}`);
467
+ o.add(s), r.set(a, n);
468
+ }
469
+ return r;
470
+ }
471
+ function ar(e, t, r, o, a) {
472
+ if (!e.grandTotal) return;
473
+ const n = typeof e.grandTotal == "object" ? e.grandTotal : void 0, s = Y(e)[0], i = n?.fields ?? s?.subtotal ?? [], c = n?.aggregates ?? s?.aggregates ?? [];
474
+ if (i.length === 0 && c.length === 0) {
475
+ o.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
476
+ return;
477
+ }
478
+ const d = K(r, o.measurer, n?.label ?? "合计", Ke(e.columns, t, i, c), n?.style ?? {}, Be(e.columns, [...i, ...c.map((l) => l.field)]));
479
+ a.placeGridRow(d, "listgt", "grand-total");
480
+ }
481
+ function G(e) {
482
+ if (e?.aborted) {
483
+ const t = new Error("报表排版已取消");
484
+ throw t.name = "AbortError", t;
485
+ }
486
+ }
487
+ function Y(e) {
488
+ const t = e.groups ?? (e.groupBy ? [e.groupBy] : []);
489
+ if (t.length > 16) throw new Error("列表最多支持 16 级分组");
490
+ return t;
491
+ }
492
+ function me(e) {
493
+ const t = Ht(e), r = t.columns.reduce((a, n) => a + n.widthMm, 0), o = r > t.widthMm ? t.widthMm / r : 1;
494
+ return o === 1 ? t : { ...t, columns: t.columns.map((a) => ({ ...a, widthMm: a.widthMm * o })) };
495
+ }
496
+ function sr(e, t, r) {
497
+ const o = e.detail;
498
+ if (!o) return;
499
+ const a = /* @__PURE__ */ new Set();
500
+ for (const d of t) {
501
+ const l = ne(d[o.parentKey]);
502
+ if (a.has(l)) throw new Error("主从明细的主表关联键重复");
503
+ a.add(l);
504
+ }
505
+ const n = r.datasets[o.dataset] ?? [], s = /* @__PURE__ */ new Map(), i = [];
506
+ for (const d of n) {
507
+ const l = d[o.foreignKey];
508
+ if (!We(l) && o.unmatched === "ignore") continue;
509
+ const f = ne(l);
510
+ if (!a.has(f)) {
511
+ if (o.unmatched !== "ignore") throw new Error(`明细数据集 ${o.dataset} 存在未关联的业务键`);
512
+ continue;
513
+ }
514
+ const u = s.get(f);
515
+ u ? u.push(d) : s.set(f, [d]), i.push(d);
516
+ }
517
+ const c = me({ ...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 });
518
+ return { list: c, inter: { ...fe(c, r.measurer), rowHeightFloorMm: c.rowHeightMm ?? 0 }, rows: s, sources: X(c, i) };
519
+ }
520
+ function We(e) {
521
+ return typeof e == "string" && !!e.trim() || typeof e == "number" && Number.isFinite(e);
522
+ }
523
+ function ne(e) {
524
+ if (!We(e)) throw new Error("主从关联键必须是非空字符串或有限数字");
525
+ return Le(e);
526
+ }
527
+ function* ir(e, t, r, o, a) {
528
+ if (!r) return;
529
+ const n = r.rows.get(ne(t[e.detail.parentKey])) ?? [];
530
+ if (!n.length) return;
531
+ const s = { id: `${o.tableId}:detail`, columnKeys: r.list.columns.map((i) => i.field), title: e.detail.label };
532
+ e.detail.label && a.placeGridRow({ ...K(r.inter, o.measurer, e.detail.label, /* @__PURE__ */ new Map(), {}, r.list.columns.length), table: s }, "listdl", "group-header"), e.detail.header !== !1 && a.placeGridRow({ grid: r.inter.headerGrid, heightMm: r.inter.headerHeightMm, table: s }, "listdh", "header"), yield* o.takePages();
533
+ for (const i of n)
534
+ G(o.signal), a.placeGridRow({ ...W(r.inter, i, o.measurer), table: s }, "listdr", "body", r.sources.get(i)), yield* o.takePages();
535
+ }
536
+ function cr(e, t) {
537
+ if (!e.matrix) return { list: e, rows: t };
538
+ if (e.detail || e.groupBy || e.groups?.length || e.grandTotal) throw new Error("矩阵不能同时配置普通分组、总计或主从明细");
539
+ const r = vt(t, e.matrix), o = r.columns.map((n, s) => ({ ...n, widthMm: s === 0 ? e.matrix.rowWidthMm ?? 40 : e.matrix.columnWidthMm ?? 28, editable: !1, align: s === 0 ? "center" : "right" })), a = { ...e, columns: o, headerGrid: void 0, rowKey: void 0, revisionField: void 0, sourceTokenField: void 0 };
540
+ return e.layout === "wide" && (a.widthMm = o.reduce((n, s) => n + s.widthMm, 0)), { list: a, rows: r.rows };
541
+ }
542
+ function Ge(e) {
543
+ if (e.matrix || e.detail || e.groups?.length || e.groupBy || e.rowVisibleWhen) throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");
544
+ if (e.rowKey && e.rowKey !== e.tree.idField) throw new Error("树形布局的 rowKey 应与 idField 一致");
545
+ if (!e.columns.some((t) => t.field === e.tree.labelField && !t.hidden)) throw new Error("树形布局需要可见的标签列");
546
+ St(e.tree, e.computed);
547
+ }
548
+ function dr(e, t, r) {
549
+ Ge(e);
550
+ const o = Pt(t, e.tree, { signal: r.signal, computed: e.computed?.length ? { fields: e.computed, formula: r.formula } : void 0 }), a = { ...e, rowKey: e.tree.idField }, n = X(a, o.entries.map((c) => c.original)), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap();
551
+ for (const c of o.entries)
552
+ s.set(c.row, n.get(c.original)), i.set(c.row, c);
553
+ return { list: a, rows: o.rows, sources: s, treeRows: i, totalRows: o.leaves };
554
+ }
555
+ function lr(e, t) {
556
+ if (e.cardinality === "record") {
557
+ if (t.length > 1) throw new Error(`单记录区域 ${e.id ?? e.dataset} 仅允许 0 或 1 行数据`);
558
+ if (e.tree || e.matrix || e.detail || e.groups?.length || e.groupBy || e.grandTotal || e.rowVisibleWhen) throw new Error("单记录区域不能配置树、矩阵、主从、分组、总计或行过滤");
559
+ if (!t.length) return { list: { ...e, columns: e.columns.map((r) => ({ ...r, editable: !1 })) }, rows: [{}], sources: /* @__PURE__ */ new Map() };
560
+ }
561
+ }
562
+ function Ve(e, t, r) {
563
+ const o = r.prepared.get(e);
564
+ if (o) return o;
565
+ const a = lr(e, t);
566
+ if (a)
567
+ return r.prepared.set(e, a), a;
568
+ if (e.tree) {
569
+ const c = dr(e, t, r);
570
+ return r.prepared.set(e, c), c;
571
+ }
572
+ let n = e.computed?.length ? Ce(t, { fields: e.computed, signal: r.signal, formula: r.formula }).rows : t;
573
+ const s = n === t ? void 0 : new Map(n.map((c, d) => [c, t[d]]));
574
+ e.rowVisibleWhen && (n = n.filter((c) => L(c, e.rowVisibleWhen)));
575
+ const i = cr(e, n);
576
+ if (!e.matrix) {
577
+ const c = X(e, s ? n.map((d) => s.get(d)) : n);
578
+ i.sources = s ? new Map(n.map((d) => [d, c.get(s.get(d))])) : c;
579
+ }
580
+ return r.prepared.set(e, i), i;
581
+ }
582
+ function ur(e, t, r, o) {
583
+ if (!o.flow) return;
584
+ const { current: a, templatePage: n } = o, s = Math.max(a.marginTopMm, B(n)), 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);
585
+ i + c <= _(n, a) + 1e-3 || i <= s + 1e-3 || (o.pushCurrent(), a.components = [], a.heightMm = n.heightMm, n.layout === "wide" && (a.marginTopMm = 0, a.marginBottomMm = 0), o.startTop = Math.max(a.marginTopMm, B(n)));
586
+ }
587
+ function* fr(e, t, r) {
588
+ const o = Ve(e, t, r), a = o.rows;
589
+ e = o.list, e.layout === "wide" && (r.current.widthMm = Math.max(r.current.widthMm, e.leftMm + e.widthMm + r.current.marginRightMm));
590
+ const n = o.sources ?? X(e, a), s = me(e), i = Y(s), c = { ...fe(s, r.measurer), rowHeightFloorMm: s.rowHeightMm ?? 0, ...o.treeRows ? { tree: { list: s, rows: o.treeRows } } : {} };
591
+ ur(s, c, a, r);
592
+ const d = or(s, c, r), l = sr(s, a, r);
593
+ let f;
594
+ for (const u of De(a, i)) {
595
+ if (G(r.signal), u.kind === "row")
596
+ d.placeGridRow(f ?? W(c, u.row, r.measurer), "listr", "body", n.get(u.row)), f = void 0, yield* r.takePages(), yield* ir(s, u.row, l, r, d);
597
+ else if (u.kind === "groupHeader") {
598
+ const g = K(c, r.measurer, u.label, /* @__PURE__ */ new Map(), u.group.headerStyle ?? {}, s.columns.length);
599
+ f ??= W(c, u.firstRow, r.measurer);
600
+ const h = i.slice(u.depth + 1).reduce((m, w) => m + K(c, r.measurer, (w.headerTemplate ?? "{value}").replace(/\{value\}/g, ce(u.firstRow[w.field])), /* @__PURE__ */ new Map(), w.headerStyle ?? {}, s.columns.length).heightMm, 0);
601
+ u.group.keepWithNext !== !1 && d.keepTogether(g.heightMm + h + f.heightMm), d.placeGridRow(g, "listg", "group-header"), u.group.repeatHeader && d.setGroupHeader(u.depth, g);
602
+ } else if (u.kind === "subtotal") {
603
+ const g = u.group.subtotal ?? [], h = u.group.aggregates ?? [], m = K(c, r.measurer, u.label, Ke(s.columns, u.rows, g, h), u.group.subtotalStyle ?? {}, Be(s.columns, [...g, ...h.map((w) => w.field)]));
604
+ d.placeGridRow(m, "listst", "subtotal");
605
+ } else d.setGroupHeader(u.depth);
606
+ yield* r.takePages();
607
+ }
608
+ ar(s, o.totalRows ?? a, c, r, d), r.finished?.(d.bottom()), yield* r.takePages();
609
+ }
610
+ function Q(e) {
611
+ return e.kind !== "list" && (e.pageAnchor !== void 0 || e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}")));
612
+ }
613
+ function Z(e, t) {
614
+ return {
615
+ ...e,
616
+ ...e.text === void 0 ? {} : { text: t(e.text) },
617
+ ...e.lines ? { lines: e.lines.map(t) } : {},
618
+ ...e.richParagraphs ? { richParagraphs: e.richParagraphs.map((r) => ({ ...r, segments: r.segments.map((o) => ({ ...o, ...o.text === void 0 ? {} : { text: t(o.text) } })) })) } : {},
619
+ ...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((a) => Z(a, t)) } : {} } : null)) } } : {}
620
+ };
621
+ }
622
+ function mr(e) {
623
+ let t = !1;
624
+ for (const r of e.pages) for (const o of r.components) Q(o) && Z(o, (a) => (a.includes("{totalPages}") && (t = !0), a));
625
+ return t;
626
+ }
627
+ function gr(e, t, r, o, a, n) {
628
+ const s = {
629
+ pageWidthMm: t.widthMm,
630
+ pageHeightMm: t.heightMm,
631
+ ...e.layout === void 0 ? {} : { layout: e.layout },
632
+ marginTopMm: t.marginTopMm,
633
+ marginBottomMm: t.marginBottomMm,
634
+ marginLeftMm: t.marginLeftMm,
635
+ marginRightMm: t.marginRightMm,
636
+ components: t.components,
637
+ ...e.meta ? { meta: e.meta } : {}
638
+ }, i = (c) => {
639
+ const d = c.replace(/\{page\}/g, String(o));
640
+ return n === void 0 ? d : d.replace(/\{totalPages\}/g, String(n));
641
+ };
642
+ for (const c of r) s.components.push(Z(c, i));
643
+ if (e.layout === "wide") {
644
+ const c = s.components.reduce((d, l) => Math.max(d, l.topMm + l.heightMm), 0);
645
+ s.marginBottomMm = a ? e.marginBottomMm ?? 0 : 0, s.pageHeightMm = Math.max(1, c + s.marginBottomMm);
646
+ }
647
+ return s;
648
+ }
649
+ function ge(e) {
650
+ return e.cells.reduce((t, r) => t + r.reduce((o, a) => o + (a ? 1 + (a.children?.reduce((n, s) => n + _e(s), 0) ?? 0) : 0), 0), 0);
651
+ }
652
+ function _e(e) {
653
+ return e.grid ? ge(e.grid) : 0;
654
+ }
655
+ function he(e) {
656
+ for (const t of ["maxPages", "maxCells", "knownTotalPages"]) if (e[t] !== void 0 && (!Number.isSafeInteger(e[t]) || e[t] < 1)) throw new RangeError(`${t} 应为正安全整数`);
657
+ }
658
+ function hr(e, t) {
659
+ const r = Ve(e, t.datasets[e.dataset] ?? [], t), o = me(r.list), a = { ...fe(o, t.measurer), rowHeightFloorMm: o.rowHeightMm ?? 0 };
660
+ return (o.header === !1 ? 0 : a.headerHeightMm) + r.rows.reduce((n, s) => n + W(a, s, t.measurer).heightMm, 0);
661
+ }
662
+ function* pr(e) {
663
+ const { templatePage: t, current: r } = e, o = new Map(t.components.map((n, s) => [n, s])), a = (n, s, i) => {
664
+ const c = e.datasets[n.dataset];
665
+ return Array.isArray(c) || e.warnings.push(`数据集 ${n.dataset} 未提供数据,列表 ${n.id ?? ""} 输出为空`), fr(n, Array.isArray(c) ? c : [], { ...e, tableId: `${e.tableId}:${o.get(n)}`, startTop: s, finished: i, flow: !!t.flow });
666
+ };
667
+ if (t.flow) {
668
+ yield* Lt({
669
+ page: t,
670
+ active: () => G(e.signal),
671
+ top: () => Math.max(r.marginTopMm, B(t)),
672
+ bottom: () => _(t, r),
673
+ append: (n) => {
674
+ r.components.push(n);
675
+ },
676
+ nextPage: () => {
677
+ e.pushCurrent(), r.components = [], r.heightMm = t.heightMm, t.layout === "wide" && (r.marginTopMm = 0, r.marginBottomMm = 0);
678
+ },
679
+ takePages: e.takePages,
680
+ height: (n) => hr(n, e),
681
+ list: a
682
+ });
683
+ return;
684
+ }
685
+ for (const n of t.components)
686
+ Q(n) || (n.kind === "list" ? yield* a(n) : r.components.push(n));
687
+ }
688
+ function* J(e, t, r, o, a, n = /* @__PURE__ */ new WeakMap()) {
689
+ let s = 0, i = 0, c = 0;
690
+ const d = (l) => `${l}_${(++s).toString(36)}`;
691
+ for (const { pageIndex: l, page: f } of qt(e, t, r)) {
692
+ G(r.signal);
693
+ const u = Ut(f), g = f.components.filter(Q);
694
+ let h = [];
695
+ const m = (v = !1) => {
696
+ if (G(r.signal), r.maxPages !== void 0 && i >= r.maxPages) throw new N(r.maxPages, i + 1);
697
+ if (r.maxCells !== void 0 && (c += [...u.components, ...g].reduce((S, k) => S + _e(k), 0), c > r.maxCells))
698
+ throw new D(r.maxCells, c);
699
+ h.push(gr(f, u, g, ++i, v, a));
700
+ }, w = () => {
701
+ const v = h;
702
+ return h = [], v;
703
+ };
704
+ yield* pr({
705
+ templatePage: f,
706
+ current: u,
707
+ warnings: o,
708
+ nextId: d,
709
+ pushCurrent: m,
710
+ takePages: w,
711
+ datasets: t,
712
+ signal: r.signal,
713
+ formula: r.formula,
714
+ prepared: n,
715
+ measurer: r.measurer ?? ke,
716
+ mmPerRow: r.mmPerRow ?? 0,
717
+ tableId: `table:${l}`
718
+ }), m(!0), yield* w();
719
+ }
720
+ }
721
+ function Zr(e, t, r = {}) {
722
+ he(r);
723
+ let o = 0;
724
+ for (const a of J(e, t, { ...r, onWarning: void 0 }, [])) o++;
725
+ return o;
726
+ }
727
+ function* wr(e, t, r = {}) {
728
+ he(r);
729
+ const o = mr(e), a = /* @__PURE__ */ new WeakMap();
730
+ let n = r.knownTotalPages;
731
+ if (o && n === void 0) {
732
+ n = 0;
733
+ for (const c of J(e, t, r, [], void 0, a)) n++;
734
+ }
735
+ const s = [];
736
+ let i = 0;
737
+ for (const c of J(e, t, r, s, n, a)) {
738
+ for (; i < s.length; i++) r.onWarning?.(s[i]);
739
+ yield c;
740
+ }
741
+ }
742
+ function Je(e, t, r = {}) {
743
+ const o = typeof r == "number" ? { mmPerRow: r } : r;
744
+ he(o);
745
+ const a = [], n = [...J(e, t, o, a, o.knownTotalPages)];
746
+ for (const s of n) s.components = s.components.map((i) => Q(i) ? Z(i, (c) => c.replace(/\{totalPages\}/g, String(n.length))) : i);
747
+ return a.forEach((s) => o.onWarning?.(s)), { plan: { schemaVersion: z, ...U(e) ? { requiresRecalculation: !0 } : {}, pages: n }, warnings: a };
748
+ }
749
+ function yr(e) {
750
+ const t = e.columns.find((n) => !n.hidden)?.field;
751
+ if (!t) return { groups: 0, total: 0 };
752
+ const r = Y(e), o = (n = [], s = []) => n.includes(t) || s.some((i) => i.field === t), a = typeof e.grandTotal == "object" ? e.grandTotal : void 0;
753
+ return { groups: r.filter((n) => o(n.subtotal, n.aggregates)).length, total: Number(o(a?.fields ?? r[0]?.subtotal, a?.aggregates ?? r[0]?.aggregates)) };
754
+ }
755
+ function br(e, t, r) {
756
+ Ge(e);
757
+ const o = Oe(t[e.dataset] ?? [], e.tree, r), a = e.columns.filter((s) => !s.hidden).length, n = e.header === !1 ? 0 : e.headerGrid ? ge(e.headerGrid) : a;
758
+ return o.length * a + n + +!!e.grandTotal * 2 * a;
759
+ }
760
+ function eo(e, t, r = {}) {
761
+ if (e.tree) return br(e, t, r.signal);
762
+ if (e.matrix) {
763
+ let c = t[e.dataset] ?? [];
764
+ e.computed?.length && (c = Ce(c, { fields: e.computed, ...r }).rows), e.rowVisibleWhen && (c = c.filter((l) => L(l, e.rowVisibleWhen)));
765
+ const d = Mt(c, e.matrix);
766
+ return d.cells + d.columnCount;
767
+ }
768
+ const o = t[e.dataset]?.length ?? 0, a = e.columns.filter((c) => !c.hidden).length, n = Y(e).length, s = yr(e);
769
+ let i = (o * (1 + 2 * n + s.groups) + +!!e.grandTotal * (1 + s.total)) * a;
770
+ if (i += e.header === !1 ? 0 : e.headerGrid ? ge(e.headerGrid) : a, e.cardinality === "record" && o === 0 && (i += a), e.detail) {
771
+ const c = t[e.detail.dataset]?.length ?? 0, d = e.detail.columns.filter((l) => !l.hidden).length;
772
+ i += (c + o * (+(e.detail.header !== !1) + +!!e.detail.label)) * d;
773
+ }
774
+ if (!Number.isSafeInteger(i)) throw new RangeError("报表单元格估算超出安全整数预算");
775
+ return i;
776
+ }
777
+ function ze(e) {
778
+ const t = [];
779
+ for (const r of e.template.pages) for (const o of r.components)
780
+ 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] ?? [] } }));
781
+ return t;
782
+ }
783
+ function H(e) {
784
+ return JSON.stringify([e.sourceScope, e.datasetId]);
785
+ }
786
+ function ve(e) {
787
+ return JSON.stringify([e.sourceScope, e.datasetId, e.rowKey]);
788
+ }
789
+ function qe(e) {
790
+ const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
791
+ return e.forEach((o, a) => {
792
+ for (const n of ze(o)) {
793
+ if (!n.rowKey) continue;
794
+ const s = n.relation, i = s ? new Set(s.parentRows.map((c) => JSON.stringify(c[s.detail.parentKey]))) : void 0;
795
+ (o.datasets[n.dataset] ?? []).forEach((c, d) => {
796
+ if (s && !i.has(JSON.stringify(c[s.detail.foreignKey]))) return;
797
+ const l = c[n.rowKey];
798
+ if (typeof l != "string" && typeof l != "number") return;
799
+ const f = `${a}:${n.dataset}:${d}:${n.rowKey}`;
800
+ if (r.has(f)) return;
801
+ r.add(f);
802
+ const u = ve({ sourceScope: o.sourceScope, datasetId: n.dataset, rowKey: l }), g = t.get(u) ?? [];
803
+ g.push({ partIndex: a, dataset: n.dataset, rowIndex: d, row: c, binding: n }), t.set(u, g);
804
+ });
805
+ }
806
+ }), (o) => {
807
+ const a = t.get(ve(o));
808
+ if (!a?.length) throw new P("missing");
809
+ if (new Set(a.map((n) => `${n.partIndex}:${n.dataset}`)).size !== a.length) throw new P("conflict");
810
+ return a;
811
+ };
812
+ }
813
+ function Ue(e, t) {
814
+ const r = e.map((a) => ({ ...a, datasets: { ...a.datasets } })), o = /* @__PURE__ */ new Set();
815
+ for (const { row: a, field: n, value: s } of t) {
816
+ const i = r[a.partIndex], c = `${a.partIndex}:${a.dataset}`;
817
+ o.has(c) || (i.datasets[a.dataset] = [...i.datasets[a.dataset]], o.add(c)), i.datasets[a.dataset][a.rowIndex] = { ...i.datasets[a.dataset][a.rowIndex], [n]: s };
818
+ }
819
+ return r;
820
+ }
821
+ function Mr(e, t, r) {
822
+ const o = [], a = /* @__PURE__ */ new Set();
823
+ return e.forEach((n, s) => {
824
+ for (const i of ze(n))
825
+ t.has(H({ sourceScope: n.sourceScope, datasetId: i.dataset })) && (n.datasets[i.dataset] ?? []).forEach((c, d) => {
826
+ const l = { partIndex: s, dataset: i.dataset, rowIndex: d, row: c, binding: i };
827
+ for (const [f, u] of [[i.revisionField, r.revision], [i.sourceTokenField, r.sourceToken]]) {
828
+ if (!f || u === void 0) continue;
829
+ const g = `${s}:${i.dataset}:${d}:${f}`;
830
+ a.has(g) || (a.add(g), o.push({ row: l, field: f, value: u }));
831
+ }
832
+ });
833
+ }), o;
834
+ }
835
+ function vr(e, t, r) {
836
+ if (!r || r.revision === void 0 && r.sourceToken === void 0) return e;
837
+ const o = new Set(t.edits.flatMap((a) => a.source ? [H(a.source)] : []));
838
+ return Xe(e, new Map([...o].map((a) => [a, r])));
839
+ }
840
+ function Xe(e, t) {
841
+ if (!t.size) return e;
842
+ function r(n) {
843
+ const s = n.datasetId && t.get(H({ ...n, datasetId: n.datasetId }));
844
+ return !s || (s.revision === void 0 || Object.is(s.revision, n.revision)) && (s.sourceToken === void 0 || s.sourceToken === n.sourceToken) ? n : { ...n, ...s.revision !== void 0 ? { revision: s.revision } : {}, ...s.sourceToken !== void 0 ? { sourceToken: s.sourceToken } : {} };
845
+ }
846
+ function o(n) {
847
+ const s = n.map((i) => {
848
+ const c = i.table?.source ? r(i.table.source) : void 0, d = i.table && c !== i.table.source ? { ...i.table, source: c } : i.table, l = i.grid?.cells.map((u) => {
849
+ const g = u.map((h) => {
850
+ if (!h) return h;
851
+ const m = h.source ? r(h.source) : void 0, w = h.children ? o(h.children) : void 0;
852
+ return m === h.source && w === h.children ? h : { ...h, source: m, children: w };
853
+ });
854
+ return g.some((h, m) => h !== u[m]) ? g : u;
855
+ }), f = i.grid && l?.some((u, g) => u !== i.grid.cells[g]) ? { ...i.grid, cells: l } : i.grid;
856
+ return d !== i.table || f !== i.grid ? { ...i, table: d, grid: f } : i;
857
+ });
858
+ return s.some((i, c) => i !== n[c]) ? s : n;
859
+ }
860
+ const a = e.pages.map((n) => {
861
+ const s = o(n.components);
862
+ return s !== n.components ? { ...n, components: s } : n;
863
+ });
864
+ return a.some((n, s) => n !== e.pages[s]) ? { ...e, pages: a } : e;
865
+ }
866
+ function Ye(e) {
867
+ const t = /* @__PURE__ */ new Map(), r = le(e);
868
+ return e.pages.forEach((o, a) => o.components.forEach((n, s) => {
869
+ if (!(!n.grid || n.table?.role !== "body"))
870
+ for (let i = 0; i < n.grid.cells.length; i++) for (let c = 0; c < n.table.columnKeys.length; c++) {
871
+ const d = r({ pageIndex: a, componentIndex: s, rowIndex: i, columnIndex: c });
872
+ d?.source && d.editable && t.set(j(d), d);
873
+ }
874
+ })), t;
875
+ }
876
+ function to(e, t, r) {
877
+ const o = Ye(e), a = le(e);
878
+ return t.map((n) => {
879
+ const s = n.source ? o.get(j(n)) : a(n.address);
880
+ if (!s || j(s) !== j(n)) throw new P("missing");
881
+ return { address: { ...s.address }, value: n[r] };
882
+ });
883
+ }
884
+ function Qe(e, t) {
885
+ if (++e.nodes > 1e6 || t > 128) throw new P("limit");
886
+ }
887
+ function pe(e, t) {
888
+ const r = Object.getOwnPropertyDescriptor(e, t);
889
+ if (!r || r.get || r.set) throw new P("conflict");
890
+ return r.value;
891
+ }
892
+ function Ze(e) {
893
+ if (Object.getOwnPropertyDescriptor(e, "toJSON")) throw new P("conflict");
894
+ const t = Object.getPrototypeOf(e);
895
+ if (!(e instanceof Date) && !Array.isArray(e) && t !== Object.prototype && t !== null) throw new P("conflict");
896
+ for (const r of Reflect.ownKeys(e))
897
+ if (!(Array.isArray(e) && r === "length")) {
898
+ if (typeof r == "symbol" || !Object.getOwnPropertyDescriptor(e, r)?.enumerable) throw new P("conflict");
899
+ if (e instanceof Date || Array.isArray(e) && !/^(0|[1-9]\d*)$/.test(r)) throw new P("conflict");
900
+ }
901
+ }
902
+ function et(e, t, r, o, a) {
903
+ if (Qe(o, a), typeof e == "function" || typeof e == "symbol") throw new P("conflict");
904
+ if (e === null || typeof e != "object") return;
905
+ if (Ze(e), r.has(e)) throw new P("conflict");
906
+ r.add(e);
907
+ const n = Object.keys(e), s = n.map((i) => pe(e, i));
908
+ t.push({
909
+ object: e,
910
+ prototype: Object.getPrototypeOf(e),
911
+ keys: n,
912
+ values: s,
913
+ ...e instanceof Date ? { date: Date.prototype.getTime.call(e) } : {},
914
+ ...Array.isArray(e) ? { length: e.length } : {}
915
+ });
916
+ for (const i of s) et(i, t, r, o, a + 1);
917
+ r.delete(e);
918
+ }
919
+ function Sr(e) {
920
+ const { object: t, keys: r, values: o } = e;
921
+ if (Ze(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;
922
+ const a = Object.keys(t);
923
+ return a.length === r.length && r.every((n, s) => a[s] === n && Object.is(pe(t, n), o[s]));
924
+ }
925
+ function Pr(e) {
926
+ const t = [];
927
+ return et(e, t, /* @__PURE__ */ new Set(), { nodes: 0 }, 0), () => {
928
+ try {
929
+ return t.every(Sr);
930
+ } catch {
931
+ return !1;
932
+ }
933
+ };
934
+ }
935
+ function ae(e, t, r) {
936
+ return Qe(t, r), e === null || typeof e != "object" ? e : e instanceof Date ? new Date(Date.prototype.getTime.call(e)) : Array.isArray(e) ? e.map((o) => ae(o, t, r + 1)) : Object.fromEntries(Object.keys(e).map((o) => [o, ae(pe(e, o), t, r + 1)]));
937
+ }
938
+ function Tr(e) {
939
+ return ae(e, { nodes: 0 }, 0);
940
+ }
941
+ async function tt(e, t, r = {}) {
942
+ const o = [], a = { ...r, knownTotalPages: void 0 };
943
+ for (const n of wr(e, t, a))
944
+ o.push(n), o.length % 8 === 0 && await new Promise((s) => setTimeout(s, 0));
945
+ if (r.signal?.aborted) {
946
+ const n = new Error("报表重算已取消");
947
+ throw n.name = "AbortError", n;
948
+ }
949
+ return { schemaVersion: z, ...U(e) ? { requiresRecalculation: !0 } : {}, pages: o };
950
+ }
951
+ const se = /* @__PURE__ */ new WeakMap();
952
+ function ro(e) {
953
+ return se.get(e);
954
+ }
955
+ function V(e) {
956
+ if (e?.aborted) {
957
+ const t = new Error("报表重算已取消");
958
+ throw t.name = "AbortError", t;
959
+ }
960
+ }
961
+ function rt(e, t) {
962
+ return e[t] === void 0 ? "" : e[t];
963
+ }
964
+ function kr(e, t) {
965
+ if (t.edits.length > 1e4) throw new P("limit");
966
+ const r = le(e), o = /* @__PURE__ */ new Set(), a = [], n = t.edits.map((s) => {
967
+ const i = r(s.address);
968
+ if (!i?.source) throw new P("missing");
969
+ const c = j(s);
970
+ if (o.has(c)) throw new P("duplicate");
971
+ if (o.add(c), Ft(i, s) || !Object.is(i.value, s.previousValue) || (i.cell.text ?? "") !== s.previousText) throw new P("conflict");
972
+ return a.push(i), Ae(i, s.value);
973
+ });
974
+ return { batch: { requestId: t.requestId, edits: n }, contexts: a };
975
+ }
976
+ function $r(e, t) {
977
+ const r = qe(e);
978
+ return t.flatMap((o) => {
979
+ if (!o.source) throw new P("missing");
980
+ return r(o.source).map((a) => {
981
+ if (!Object.is(rt(a.row, o.source.field), o.previousValue)) throw new P("conflict");
982
+ if (a.binding.rowKey === o.source.field) throw new P("readonly");
983
+ return { row: a, field: o.source.field, value: o.value };
984
+ });
985
+ });
986
+ }
987
+ function oe(e, t, r) {
988
+ const o = { ...e, value: t, source: { ...e.source, ...r?.revision === void 0 ? {} : { revision: r.revision }, ...r?.sourceToken === void 0 ? {} : { sourceToken: r.sourceToken } } };
989
+ return o.cell = { ...e.cell, value: o.value, text: Ot(o, o.value) }, o;
990
+ }
991
+ function Rr(e, t, r) {
992
+ if (!r || r.revision === void 0 && r.sourceToken === void 0) return [...e];
993
+ const o = new Set(t.edits.flatMap((a) => a.source ? [H(a.source)] : []));
994
+ return Ue(e, Mr(e, o, r));
995
+ }
996
+ function Er(e, t, r) {
997
+ const o = new Set(t.edits.map((a) => H(a.source)));
998
+ for (const a of o) e.set(a, {
999
+ ...e.get(a),
1000
+ ...r.revision !== void 0 ? { revision: r.revision } : {},
1001
+ ...r.sourceToken !== void 0 ? { sourceToken: r.sourceToken } : {}
1002
+ });
1003
+ return o;
1004
+ }
1005
+ function ot(e, t) {
1006
+ let r = t.parts;
1007
+ const o = t.rebuild;
1008
+ let a = Pr(r), n = e, s;
1009
+ const i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
1010
+ function d(u) {
1011
+ if (u !== n) throw new P("conflict");
1012
+ if (s) return s;
1013
+ if (!a?.()) throw new P("conflict");
1014
+ return Tr(r);
1015
+ }
1016
+ async function l(u, g, h, m = {}) {
1017
+ V(m.signal), g = { requestId: g.requestId, edits: g.edits.map((b) => ({ ...b, address: { ...b.address }, source: b.source ? { ...b.source } : void 0, table: b.table ? { ...b.table } : void 0 })) }, h = h.map((b) => ({ ...b, address: { ...b.address }, source: b.source ? { ...b.source } : void 0, table: b.table ? { ...b.table } : void 0, cell: { ...b.cell } })), await new Promise((b) => setTimeout(b, 0)), V(m.signal);
1018
+ const w = d(u), v = Ue(w, $r(w, g.edits)), S = Xe(await o(v, m.signal), c);
1019
+ V(m.signal);
1020
+ let k = !1;
1021
+ return { plan: S, commit(b) {
1022
+ if (V(m.signal), k || n !== u) throw new P("conflict");
1023
+ if (b?.conflicts?.length) throw new P("conflict");
1024
+ const A = Rr(v, g, b), O = vr(S, g, b);
1025
+ if (b) {
1026
+ const x = Er(c, g, b);
1027
+ for (const [p, y] of i) x.has(H(y.source)) && i.set(p, oe(y, y.value, b));
1028
+ }
1029
+ return h.forEach((x, p) => i.set(j(x), oe(x, g.edits[p].value, b))), k = !0, s = A, r = void 0, a = void 0, n = O, se.set(n, f), n;
1030
+ } };
1031
+ }
1032
+ const f = {
1033
+ get plan() {
1034
+ return n;
1035
+ },
1036
+ async prepare(u, g, h) {
1037
+ const m = kr(u, g);
1038
+ return l(u, m.batch, m.contexts, h);
1039
+ },
1040
+ async prepareHistory(u, g, h, m, w) {
1041
+ if (!m.trim() || g.length > 1e4) throw new P("limit");
1042
+ const v = d(u), S = qe(v), k = Ye(u), b = /* @__PURE__ */ new Set(), O = g.map((y) => {
1043
+ if (!y.source) throw new P("missing");
1044
+ const M = j(y);
1045
+ if (b.has(M)) throw new P("duplicate");
1046
+ b.add(M);
1047
+ const $ = k.get(M) ?? i.get(M);
1048
+ if (!$?.source) throw new P("missing");
1049
+ const R = S($.source)[0];
1050
+ return oe($, rt(R.row, $.source.field));
1051
+ }).map((y, M) => ({ context: y, edit: Ae(y, g[M][h]) })).filter(({ edit: y }) => !Object.is(y.previousValue, y.value)), x = { requestId: m, edits: O.map(({ edit: y }) => y) }, p = O.map(({ context: y }) => y);
1052
+ return { batch: x, contexts: p, prepared: await l(u, x, p, w) };
1053
+ }
1054
+ };
1055
+ return se.set(e, f), f;
1056
+ }
1057
+ function oo(e) {
1058
+ const t = Je(e.template, e.datasets, e.pagination).plan;
1059
+ return ot(t, { parts: [{ template: e.template, datasets: e.datasets }], rebuild: (r, o) => tt(r[0].template, r[0].datasets, { ...e.pagination, signal: o }) });
1060
+ }
1061
+ let xr = 0;
1062
+ function Cr() {
1063
+ return `report-${Date.now()}-${++xr}`;
1064
+ }
1065
+ function Se(e, t, r) {
1066
+ if (!r?.aborted)
1067
+ try {
1068
+ const o = e?.({ ...t });
1069
+ o && typeof o.then == "function" && Promise.resolve(o).catch(() => {
1070
+ });
1071
+ } catch {
1072
+ }
1073
+ }
1074
+ function Or(e) {
1075
+ const t = e.taskId ?? Cr(), r = (o, a, n) => {
1076
+ Se(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: o, status: a, ...n === void 0 ? {} : { reportId: n } }, e.signal);
1077
+ };
1078
+ return {
1079
+ taskId: t,
1080
+ progress(o, a, n) {
1081
+ Se(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: o, status: "started", completed: a, total: n }, e.signal);
1082
+ },
1083
+ async run(o, a, n) {
1084
+ r(o, "started", n);
1085
+ try {
1086
+ const s = await a();
1087
+ return r(o, "completed", n), s;
1088
+ } catch (s) {
1089
+ throw r(o, "failed", n), s;
1090
+ }
1091
+ },
1092
+ runSync(o, a, n) {
1093
+ r(o, "started", n);
1094
+ try {
1095
+ const s = a();
1096
+ return r(o, "completed", n), s;
1097
+ } catch (s) {
1098
+ throw r(o, "failed", n), s;
1099
+ }
1100
+ }
1101
+ };
1102
+ }
1103
+ function nt(e, t, r = {}) {
1104
+ const o = /* @__PURE__ */ new Map();
1105
+ for (const n of e.pages) for (const s of n.components) {
1106
+ if (s.kind !== "list" || s.tree?.input !== "nested") continue;
1107
+ const i = o.get(s.dataset);
1108
+ if (i && (i.childrenField ?? "children") !== (s.tree.childrenField ?? "children")) throw new Error("同一数据集的嵌套树应使用相同 childrenField");
1109
+ o.set(s.dataset, s.tree);
1110
+ }
1111
+ if (!o.size) return t;
1112
+ const a = { ...t };
1113
+ for (const [n, s] of o) {
1114
+ const i = Math.min(s.maxRows ?? 1e5, r.maxRows ?? 1 / 0);
1115
+ a[n] = Oe(t[n] ?? [], { ...s, maxRows: i }, r.signal);
1116
+ }
1117
+ return a;
1118
+ }
1119
+ function no(e, t, r = {}) {
1120
+ return Object.values(nt(e, t, r)).reduce((o, a) => o + a.length, 0);
1121
+ }
1122
+ function ao(e, t, r) {
1123
+ const o = It(r), a = e?.pages.flatMap((i) => i.components).find((i) => i.kind === "list" && i.dataset === t && i.tree?.input === "nested");
1124
+ if (!a || a.kind !== "list" || !a.tree) return o;
1125
+ const n = o.items, s = a.tree.childrenField ?? "children";
1126
+ return { ...o, items: { $ref: "#/$defs/treeNode" }, $defs: { treeNode: { ...n, properties: { ...n.properties, [s]: { anyOf: [{ type: "null" }, { type: "array", items: { $ref: "#/$defs/treeNode" } }] } } } } };
1127
+ }
1128
+ function at(e, t) {
1129
+ return JSON.stringify([e, t]);
1130
+ }
1131
+ function st(e, t, r) {
1132
+ return r === void 0 ? at(e, t) : JSON.stringify(["shared", r]);
1133
+ }
1134
+ function it(e, t, r) {
1135
+ return e.map((o) => {
1136
+ const a = o.table ? {
1137
+ ...o.table,
1138
+ id: r(o.table.id),
1139
+ ...o.table.source ? { source: { ...o.table.source, sourceScope: t } } : {}
1140
+ } : void 0, n = o.grid?.cells.map((s) => s.map((i) => !i || !i.source && !i.children ? i : {
1141
+ ...i,
1142
+ ...i.source ? { source: { ...i.source, sourceScope: t } } : {},
1143
+ ...i.children ? { children: it(i.children, t, r) } : {}
1144
+ }));
1145
+ return a || n ? {
1146
+ ...o,
1147
+ ...a ? { table: a } : {},
1148
+ ...n ? { grid: { ...o.grid, cells: n } } : {}
1149
+ } : o;
1150
+ });
1151
+ }
1152
+ function so(e) {
1153
+ if (!("mapData" in e)) return e;
1154
+ const { load: t, mapData: r, ...o } = e;
1155
+ return { ...o, load: async (a) => {
1156
+ const n = await t(a);
1157
+ E(a.signal);
1158
+ try {
1159
+ return r(n, a);
1160
+ } catch (s) {
1161
+ throw new T("validate", `报表 ${a.reportId} 数据映射失败`, s);
1162
+ }
1163
+ } };
1164
+ }
1165
+ class T extends Error {
1166
+ constructor(t, r, o) {
1167
+ super(r), this.name = "ReportSourceError", this.code = t, this.cause = o;
1168
+ }
1169
+ }
1170
+ function ee(e) {
1171
+ const t = new Error("报表加载已取消");
1172
+ return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
1173
+ }
1174
+ function E(e) {
1175
+ if (e?.aborted) throw ee(e);
1176
+ }
1177
+ function ie(e, t) {
1178
+ return t ? new Promise((r, o) => {
1179
+ const a = () => t.removeEventListener("abort", n), n = () => {
1180
+ a(), o(ee(t));
1181
+ };
1182
+ t.addEventListener("abort", n, { once: !0 }), t.aborted && n(), Promise.resolve(e).then(
1183
+ (s) => {
1184
+ a(), r(s);
1185
+ },
1186
+ (s) => {
1187
+ a(), o(s);
1188
+ }
1189
+ );
1190
+ }) : Promise.resolve(e);
1191
+ }
1192
+ function Fr(e, t) {
1193
+ if (!e || typeof e != "object" || Array.isArray(e))
1194
+ throw new T("validate", `报表 ${t} 的数据集应为对象`);
1195
+ for (const [r, o] of Object.entries(e))
1196
+ if (!Array.isArray(o) || o.some((a) => !a || typeof a != "object" || Array.isArray(a)))
1197
+ throw new T("validate", `报表 ${t} 的数据集 ${r} 应为对象数组`);
1198
+ }
1199
+ async function Ar(e, t, r) {
1200
+ const { reportId: o, signal: a } = t;
1201
+ try {
1202
+ const n = await ie(e(t), a);
1203
+ E(a);
1204
+ const s = Rt(n);
1205
+ if (!s.ok)
1206
+ throw new T("validate", `报表 ${o} 模板校验失败:${s.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ")}`);
1207
+ return r.push(...s.warnings.map((i) => `${o}: ${i.path}: ${i.message}`)), n;
1208
+ } catch (n) {
1209
+ throw a?.aborted ? ee(a) : n instanceof T ? n : n instanceof Et ? new T("validate", `报表 ${o} 模板校验失败:${n.message}`, n) : new T("fetch", `报表 ${o} 模板加载失败:${n instanceof Error ? n.message : String(n)}`, n);
1210
+ }
1211
+ }
1212
+ async function Ir(e, t, r, o) {
1213
+ const a = t.signal;
1214
+ let n;
1215
+ try {
1216
+ if (e.load) n = await ie(e.load(t), a);
1217
+ else if (e.provider) {
1218
+ const s = await ie(e.provider.query(t), a);
1219
+ E(a), jr(s, r), n = s.datasets, o?.(r, s);
1220
+ } else n = e.datasets ?? {};
1221
+ } catch (s) {
1222
+ throw a?.aborted ? ee(a) : s instanceof T ? s : new T("fetch", `报表 ${r} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
1223
+ }
1224
+ return E(a), n;
1225
+ }
1226
+ function jr(e, t) {
1227
+ if (!e || typeof e != "object" || Array.isArray(e)) throw new T("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
1228
+ for (const r of ["revision", "sourceToken"])
1229
+ if (e[r] !== void 0 && typeof e[r] != "string") throw new T("validate", `报表 ${t} Provider ${r} 应为字符串`);
1230
+ 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))))
1231
+ throw new T("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
1232
+ if (e.diagnostics?.some((r) => !At(r)))
1233
+ throw new T("validate", `报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`);
1234
+ }
1235
+ function Nr(e, t, r, o, a) {
1236
+ try {
1237
+ t = nt(o, t, { maxRows: e.dataValidation?.maxRows, signal: a });
1238
+ } catch (n) {
1239
+ throw new T("validate", `报表 ${r} 树形数据无效:${n instanceof Error ? n.message : String(n)}`, n);
1240
+ }
1241
+ for (const [n, s] of Object.entries(e.dataSchema ?? {})) {
1242
+ let i;
1243
+ try {
1244
+ i = jt(Object.prototype.hasOwnProperty.call(t, n) ? t[n] : void 0, s, { ...e.dataValidation, path: `$.datasets.${n}` });
1245
+ } catch (c) {
1246
+ throw new T("config", `报表 ${r} 数据集 ${n} 字段契约配置无效`, c);
1247
+ }
1248
+ if (!i.ok) throw new T("validate", `报表 ${r} 数据集 ${n} 不符合字段契约:${i.issues[0]?.message}`, { issues: i.issues });
1249
+ }
1250
+ }
1251
+ function ct(e, t) {
1252
+ if (!e.repeat) return !1;
1253
+ const r = Object.prototype.hasOwnProperty.call(t, e.repeat.dataset) ? t[e.repeat.dataset] : void 0;
1254
+ return Array.isArray(r) && r.length === 0;
1255
+ }
1256
+ function dt(e) {
1257
+ const t = (r) => r.grid?.cells.reduce((o, a) => o + a.reduce((n, s) => n + (s ? 1 + (s.children?.reduce((i, c) => i + t(c), 0) ?? 0) : 0), 0), 0) ?? 0;
1258
+ return e.pages.reduce((r, o) => r + o.components.reduce((a, n) => a + t(n), 0), 0);
1259
+ }
1260
+ function lt(e, t, r, o) {
1261
+ return {
1262
+ ...e,
1263
+ signal: o ?? e?.signal,
1264
+ ...t === void 0 ? {} : { maxPages: Math.max(1, Math.min(t, e?.maxPages ?? t)) },
1265
+ ...r === void 0 ? {} : { maxCells: Math.max(1, Math.min(r, e?.maxCells ?? r)) }
1266
+ };
1267
+ }
1268
+ function Hr(e, t, r, o, a, n) {
1269
+ const s = a.maxPages === void 0 ? void 0 : a.maxPages - a.usedPages, i = a.maxCells === void 0 ? void 0 : a.maxCells - a.usedCells;
1270
+ try {
1271
+ if (s !== void 0 && s < 1 && e.pages.length && !ct(e, t)) throw new N(0, 1);
1272
+ const c = lt(r.pagination, s, i, n), d = Je(e, t, c), l = dt(d.plan);
1273
+ if (i !== void 0 && l > i) throw new D(i, l);
1274
+ return { ...d, cells: l };
1275
+ } catch (c) {
1276
+ let d = c;
1277
+ throw c instanceof N && a.maxPages !== void 0 && c.limit === s && (d = new N(a.maxPages, a.usedPages + c.actual)), c instanceof D && a.maxCells !== void 0 && (d = new D(a.maxCells, a.usedCells + c.actual)), new T("validate", `报表 ${o} 排版失败:${d instanceof Error ? d.message : String(d)}`, d);
1278
+ }
1279
+ }
1280
+ function ut(e, t, r, o, a) {
1281
+ const n = /* @__PURE__ */ new Map(), s = (i) => {
1282
+ let c = n.get(i);
1283
+ return c === void 0 && (c = JSON.stringify([r, o, i]), n.set(i, c)), c;
1284
+ };
1285
+ for (const i of t.pages) e.push({
1286
+ ...i,
1287
+ meta: { ...i.meta, reportScope: at(r, o) },
1288
+ components: it(i.components, a ?? st(r, o), s)
1289
+ });
1290
+ }
1291
+ async function Lr(e, t, r, o, a) {
1292
+ const n = [];
1293
+ let s = 0;
1294
+ for (const [d, l] of e.entries()) {
1295
+ E(a);
1296
+ const f = o.maxPages === void 0 ? void 0 : o.maxPages - n.length, u = o.maxCells === void 0 ? void 0 : o.maxCells - s;
1297
+ if (f !== void 0 && f < 1 && l.template.pages.length && !ct(l.template, l.datasets)) throw new N(o.maxPages, n.length + 1);
1298
+ const g = await tt(l.template, l.datasets, lt(t[d]?.pagination, f, u, a));
1299
+ if (s += dt(g), o.maxCells !== void 0 && s > o.maxCells) throw new D(o.maxCells, s);
1300
+ ut(n, g, d, r[d], l.sourceScope);
1301
+ }
1302
+ const i = { schemaVersion: z, ...e.some((d) => U(d.template)) ? { requiresRecalculation: !0 } : {}, pages: n }, c = Fe(i);
1303
+ if (!c.ok) throw new T("validate", `重算渲染计划校验失败:${c.errors[0]?.message}`);
1304
+ return i;
1305
+ }
1306
+ function io(e, t = {}) {
1307
+ if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new T("config", "maxPages 应为正安全整数");
1308
+ if (t.maxCells !== void 0 && (!Number.isSafeInteger(t.maxCells) || t.maxCells < 1)) throw new T("config", "maxCells 应为正安全整数");
1309
+ function r(a) {
1310
+ const n = Object.prototype.hasOwnProperty.call(e, a) ? e[a] : void 0;
1311
+ if (!n) throw new T("config", `未注册报表 ${a}`);
1312
+ if (n.sourceScope !== void 0 && (typeof n.sourceScope != "string" || !n.sourceScope.trim() || n.sourceScope.length > 512)) throw new T("config", "sourceScope 应为不超过 512 字符的非空字符串");
1313
+ return n;
1314
+ }
1315
+ return Object.assign(async ({ reportIds: a, params: n, signal: s, onWarning: i, onQueryResult: c, ...d }) => {
1316
+ E(s);
1317
+ const l = Or({ ...d, signal: s }), f = [...a], u = { ...n };
1318
+ if (f.length === 0) throw new T("config", "缺少报表 ID");
1319
+ const g = f.map(r), h = l.runSync("validate", () => g.map((p) => ye(
1320
+ p.params ?? (typeof p.template == "function" ? [] : p.template.params) ?? [],
1321
+ u
1322
+ ))), m = [], w = [];
1323
+ let v = 0;
1324
+ const S = [];
1325
+ for (const [p, y] of g.entries()) {
1326
+ E(s);
1327
+ const M = f[p], $ = { reportId: M, params: h[p], signal: s }, R = typeof y.template == "function" ? await l.run("query", () => Ar(y.template, $, S), M) : y.template;
1328
+ $.params = l.runSync("validate", () => ye(y.params ?? R.params ?? [], $.params), M);
1329
+ const F = await l.run("query", () => Ir(y, $, M, (re, ft) => c?.(re, ft, p)), M);
1330
+ l.runSync("validate", () => {
1331
+ Fr(F, M), t.onDatasets?.(M, F, R), Nr(y, F, M, R, s);
1332
+ }, M), E(s);
1333
+ const te = l.runSync("layout", () => Hr(R, F, y, M, { maxPages: t.maxPages, usedPages: m.length, maxCells: t.maxCells, usedCells: v }, s), M);
1334
+ v += te.cells;
1335
+ const we = st(p, M, y.sourceScope);
1336
+ w.push({ template: R, datasets: F, sourceScope: we }), ut(m, te.plan, p, M, we), S.push(...te.warnings.map((re) => `${M}: ${re}`));
1337
+ }
1338
+ E(s);
1339
+ const k = { schemaVersion: z, ...w.some((p) => U(p.template)) ? { requiresRecalculation: !0 } : {}, pages: m }, b = l.runSync("validate", () => {
1340
+ const p = Fe(k);
1341
+ if (!p.ok) throw new T("validate", `渲染计划校验失败:${p.errors.slice(0, 3).map((y) => `${y.path}: ${y.message}`).join("; ")}`);
1342
+ return p;
1343
+ });
1344
+ S.push(...b.warnings.map((p) => `${p.path}: ${p.message}`));
1345
+ const A = g.map((p) => ({ ...p, pagination: { ...p.pagination } })), O = { maxPages: t.maxPages, maxCells: t.maxCells };
1346
+ try {
1347
+ ot(k, { parts: w, rebuild: (p, y) => Lr(p, A, f, O, y) });
1348
+ } catch {
1349
+ S.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算");
1350
+ }
1351
+ const x = i ?? t.onWarning ?? ((p) => console.warn("[mach-report]", p));
1352
+ for (const p of S)
1353
+ E(s), x(p);
1354
+ return E(s), k;
1355
+ }, {
1356
+ getParamDefs: (a) => Ct(e, a)
1357
+ });
1358
+ }
1359
+ function co(e, t) {
1360
+ let r = 0, o = 0;
1361
+ const a = /* @__PURE__ */ new Set();
1362
+ function n(c, d) {
1363
+ if (++r > 1e6 || d > 64) throw t.error("budget", "快照节点或深度超过预算");
1364
+ if (r % 1024 === 0 && t.check?.(), typeof c == "string" && (o += c.length, o > t.maxBytes))
1365
+ throw t.error("budget", "快照文本超过预算");
1366
+ if (c === null || ["string", "boolean"].includes(typeof c) || typeof c == "number" && Number.isFinite(c)) return c;
1367
+ if (!c || typeof c != "object" || a.has(c)) throw t.error("input", "快照应为无循环的有限 JSON 值");
1368
+ return s(c, d);
1369
+ }
1370
+ function s(c, d) {
1371
+ const l = Array.isArray(c), f = Object.getPrototypeOf(c);
1372
+ if (f !== (l ? Array.prototype : Object.prototype) && !(f === null && !l) || Object.getOwnPropertySymbols(c).length) throw t.error("input", "快照应为普通 JSON 对象");
1373
+ const u = Object.getOwnPropertyNames(c).filter((h) => !(l && h === "length"));
1374
+ if (l && (u.length !== c.length || u.some((h, m) => h !== String(m)))) throw t.error("input", "快照数组应为连续数组");
1375
+ a.add(c);
1376
+ const g = /* @__PURE__ */ Object.create(null);
1377
+ for (const h of u) {
1378
+ if (o += h.length, o > t.maxBytes) throw t.error("budget", "快照文本超过预算");
1379
+ const m = Object.getOwnPropertyDescriptor(c, h);
1380
+ if (m.get || m.set || !m.enumerable || ["__proto__", "constructor", "prototype"].includes(h)) throw t.error("input", "快照不允许访问器或危险键");
1381
+ m.value !== void 0 && (g[h] = n(m.value, d + 1));
1382
+ }
1383
+ return a.delete(c), l ? u.map((h) => g[h]) : g;
1384
+ }
1385
+ t.check?.();
1386
+ const i = JSON.stringify(n(e, 0));
1387
+ if (new TextEncoder().encode(i).byteLength > t.maxBytes) throw t.error("budget", "快照超过字节预算");
1388
+ return JSON.parse(i);
1389
+ }
1390
+ export {
1391
+ Wt as D,
1392
+ D as P,
1393
+ T as R,
1394
+ N as a,
1395
+ vr as b,
1396
+ Xe as c,
1397
+ so as d,
1398
+ Zr as e,
1399
+ oo as f,
1400
+ io as g,
1401
+ eo as h,
1402
+ ro as i,
1403
+ wr as j,
1404
+ Ht as k,
1405
+ to as l,
1406
+ Or as m,
1407
+ Cr as n,
1408
+ Se as o,
1409
+ Je as p,
1410
+ no as q,
1411
+ ot as r,
1412
+ co as s,
1413
+ ao as t,
1414
+ at as u,
1415
+ nt as v
1416
+ };