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