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