@agile-team/mach-report 2.25.2 → 2.26.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 (140) hide show
  1. package/README.md +12 -8
  2. package/dist/ExcelBindingWizard-B418l44t.js +1578 -0
  3. package/dist/ExcelBindingWizard-C4FGVsY_.cjs +1 -0
  4. package/dist/{ParamEditor-CGfaweYX.cjs → ParamEditor-BemJE8n8.cjs} +1 -1
  5. package/dist/{ParamEditor-B7YVD28E.js → ParamEditor-XvMtf_XQ.js} +2 -2
  6. package/dist/{ReportBatchPanel-BRJt0TXp.cjs → ReportBatchPanel-CbY4fvXD.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-BTKHtLTW.js → ReportBatchPanel-Ds0R_uXn.js} +37 -37
  8. package/dist/{ReportLabelStudio-BvK_WBke.cjs → ReportLabelStudio-DuTwN5er.cjs} +1 -1
  9. package/dist/{ReportLabelStudio-CZwqyO3t.js → ReportLabelStudio-ZFy79eRv.js} +26 -26
  10. package/dist/ReportParamPanel-Chxu4MTx.cjs +1 -0
  11. package/dist/{ReportParamPanel-DGXzBzl2.js → ReportParamPanel-Czm3OPo_.js} +216 -205
  12. package/dist/{ReportPreview-D1ZC5kzz.js → ReportPreview-C9c0Rp7Y.js} +2938 -2875
  13. package/dist/ReportPreview-CIMR4ERo.cjs +6 -0
  14. package/dist/{ReportTemplateLibrary-ClwxhnC0.cjs → ReportTemplateLibrary-C6lByc69.cjs} +1 -1
  15. package/dist/{ReportTemplateLibrary-C7sB0Jay.js → ReportTemplateLibrary-XJVoTDIz.js} +1 -1
  16. package/dist/{RuleEditor-CsDGFaWz.js → RuleEditor-CeNFPeOc.js} +5 -5
  17. package/dist/{RuleEditor-D-OdaGdR.cjs → RuleEditor-gggUkEwB.cjs} +1 -1
  18. package/dist/{TemplateOutlinePanel-DAqR9zQi.cjs → TemplateOutlinePanel-B0e-umq2.cjs} +1 -1
  19. package/dist/{TemplateOutlinePanel-CXOT7d1r.js → TemplateOutlinePanel-BWN4Y9iz.js} +2 -2
  20. package/dist/{TemplateReusePanel-Dcfx3Hba.js → TemplateReusePanel-CR-4OHoU.js} +2 -2
  21. package/dist/{TemplateReusePanel-ygIi-Ajz.cjs → TemplateReusePanel-Cthig1S1.cjs} +1 -1
  22. package/dist/{TemplateReviewPanel-COU8FqPq.js → TemplateReviewPanel-BkWzyNL4.js} +2 -2
  23. package/dist/{TemplateReviewPanel-DyGULVxr.cjs → TemplateReviewPanel-D8o2gDaK.cjs} +1 -1
  24. package/dist/analytics.cjs +1 -1
  25. package/dist/analytics.js +5 -5
  26. package/dist/artifact-integrity.json +106 -102
  27. package/dist/{assets-C4MIvzQ4.js → assets-BFTP-0WR.js} +2 -2
  28. package/dist/{assets-BYdpkTIt.cjs → assets-CZiZhTf2.cjs} +1 -1
  29. package/dist/{auto-j7mr8Kvc.js → auto-C7udkeAa.js} +20 -19
  30. package/dist/auto-CXd2E2aZ.cjs +1 -0
  31. package/dist/capabilities-D8UU2clQ.cjs +1 -0
  32. package/dist/{capabilities-CN_kSVjO.js → capabilities-g0a2j9Yy.js} +50 -46
  33. package/dist/{charts-Cjw5AYkg.cjs → charts-D-Vg-ak9.cjs} +1 -1
  34. package/dist/{charts-CxJZ0XaY.js → charts-D48XCefN.js} +1 -1
  35. package/dist/computed-BQgBrma-.cjs +1 -0
  36. package/dist/{computed-f3pOqWLX.js → computed-CH3NYPOW.js} +198 -188
  37. package/dist/{data-bar-Bfh54sT4.js → data-bar-DjOgTLqu.js} +1 -1
  38. package/dist/{dataset-DL83majE.js → dataset-B8oTsC6o.js} +69 -66
  39. package/dist/dataset-D3OsyzG1.cjs +1 -0
  40. package/dist/designer-COuSUxZ1.cjs +2 -0
  41. package/dist/designer-CT4mlrr0.js +7997 -0
  42. package/dist/designer.cjs +1 -1
  43. package/dist/designer.d.cts +83 -4
  44. package/dist/designer.d.ts +83 -4
  45. package/dist/designer.js +4 -4
  46. package/dist/{diagnostic-collector-gB07PHy2.js → diagnostic-collector-C-JBA016.js} +2 -2
  47. package/dist/dom-DgWc-DY1.js +452 -0
  48. package/dist/dom-Fk4NF-gN.cjs +1 -0
  49. package/dist/{encoding-BWEMdzFG.js → encoding-D480EM2r.js} +2 -2
  50. package/dist/{encoding-DVea2qIR.cjs → encoding-tWc2Wn89.cjs} +1 -1
  51. package/dist/execution-result-7sG_mdcD.cjs +1 -0
  52. package/dist/execution-result-Ba65gieT.js +39 -0
  53. package/dist/{font-loader-p_SyTvqt.cjs → font-loader-BIxme_9g.cjs} +1 -1
  54. package/dist/{font-loader-D4NLIKJL.js → font-loader-CHmEwkHl.js} +1 -1
  55. package/dist/{grid-strokes-DkZEZvcI.js → grid-strokes-DsoICRjZ.js} +1 -1
  56. package/dist/import-range-BwT86Z3j.cjs +1 -0
  57. package/dist/import-range-D9p_blcb.js +98 -0
  58. package/dist/index.cjs +1 -1
  59. package/dist/index.js +25 -25
  60. package/dist/{json-snapshot-DdzALe8q.js → json-snapshot-BZ0CIQln.js} +1041 -887
  61. package/dist/json-snapshot-DGFeI30h.cjs +2 -0
  62. package/dist/{matrix-b6T291xo.js → matrix-CB9TqTEy.js} +1 -1
  63. package/dist/{matrix-DUYPRL7t.cjs → matrix-CcqYOuq_.cjs} +1 -1
  64. package/dist/{pdf-DU8HelKd.js → pdf-DTR7fAIr.js} +3596 -3517
  65. package/dist/{pdf-C060D5UY.cjs → pdf-d9oJ6V0P.cjs} +49 -49
  66. package/dist/pdf.cjs +1 -1
  67. package/dist/pdf.js +2 -2
  68. package/dist/{plugin-D5BRHlne.cjs → plugin-B7Bi-1te.cjs} +1 -1
  69. package/dist/{plugin-FWhTnjr0.js → plugin-OKDFQFS4.js} +1 -1
  70. package/dist/{prefill-m01IM1hl.js → prefill-C8fF91JB.js} +3 -3
  71. package/dist/{prefill-DZymomY6.cjs → prefill-C_Bf_AMo.cjs} +1 -1
  72. package/dist/{prepared-BHu8bIdj.cjs → prepared-BLhV7vdE.cjs} +1 -1
  73. package/dist/{prepared-DO5pe6Ed.js → prepared-DhgQ0d-h.js} +7 -7
  74. package/dist/protocol-CZ-BILne.cjs +1 -0
  75. package/dist/{protocol-CZddmu2n.js → protocol-DHO91-Jt.js} +3 -3
  76. package/dist/{record-bindings-Cv7lFiof.js → record-bindings-DBrCu6zO.js} +3 -3
  77. package/dist/{record-bindings-B7djSjNs.cjs → record-bindings-KEs-DKCS.cjs} +1 -1
  78. package/dist/region-binding-workflow-FSyIZge8.js +882 -0
  79. package/dist/region-binding-workflow-ikpY1Kbw.cjs +3 -0
  80. package/dist/report-encoding-worker.cjs +1 -1
  81. package/dist/report-encoding-worker.js +1 -1
  82. package/dist/rich-text-layout-BYbIc3eJ.cjs +3 -0
  83. package/dist/rich-text-layout-BtygMWZC.js +96 -0
  84. package/dist/runtime-B5HG8poy.cjs +1 -0
  85. package/dist/runtime-BsvAqz4a.js +204 -0
  86. package/dist/sbom.cdx.json +1 -1
  87. package/dist/server-node.cjs +5 -5
  88. package/dist/server-node.js +2049 -1889
  89. package/dist/server.cjs +1 -1
  90. package/dist/server.d.cts +35 -0
  91. package/dist/server.d.ts +35 -0
  92. package/dist/server.js +340 -328
  93. package/dist/style.css +1 -1
  94. package/dist/{template-catalog-DLu814zA.js → template-catalog-BbrN9dgu.js} +5 -5
  95. package/dist/{template-catalog-Lil5Ryt-.cjs → template-catalog-DDH-5J57.cjs} +1 -1
  96. package/dist/{template-fragments-BDxdCuMD.js → template-fragments-CUTE8-_I.js} +3 -3
  97. package/dist/{template-fragments-DbKdxI1z.cjs → template-fragments-cyAQu7aw.cjs} +1 -1
  98. package/dist/{template-registry-B-AK1oam.cjs → template-registry-D24Z8aQf.cjs} +1 -1
  99. package/dist/{template-registry-DeVgwEZj.js → template-registry-PSuLsnyq.js} +4 -4
  100. package/dist/{template-serialization-CqQY4zDg.cjs → template-serialization-BOUidUlh.cjs} +1 -1
  101. package/dist/{template-serialization-CWmHq7lX.js → template-serialization-BgGWYV_1.js} +1 -1
  102. package/dist/{textwrap-BywMBMXM.js → textwrap-Bt_tnI6V.js} +1 -1
  103. package/dist/vue/async.d.cts +46 -3
  104. package/dist/vue/async.d.ts +46 -3
  105. package/dist/vue/index.d.cts +215 -24
  106. package/dist/vue/index.d.ts +215 -24
  107. package/dist/vue-async.cjs +1 -1
  108. package/dist/vue-async.js +3 -3
  109. package/dist/vue.cjs +1 -1
  110. package/dist/vue.js +433 -202
  111. package/dist/workbook-session-BJfZVp4q.cjs +29 -0
  112. package/dist/{workbook-session-B6hRjTyX.js → workbook-session-DRnMjIFK.js} +2377 -2350
  113. package/dist/worker.cjs +1 -1
  114. package/dist/worker.js +4 -4
  115. package/dist/xlsx.cjs +1 -1
  116. package/dist/xlsx.d.cts +27 -2
  117. package/dist/xlsx.d.ts +27 -2
  118. package/dist/xlsx.js +15 -15
  119. package/package.json +1 -1
  120. package/dist/ExcelBindingWizard-bs3F4dD8.js +0 -1486
  121. package/dist/ExcelBindingWizard-jSdjBtWw.cjs +0 -1
  122. package/dist/ReportParamPanel-B27IGJjk.cjs +0 -1
  123. package/dist/ReportPreview-DAU-V3Ov.cjs +0 -6
  124. package/dist/auto-DjmvmcX-.cjs +0 -1
  125. package/dist/capabilities-D4nfhcvB.cjs +0 -1
  126. package/dist/computed-DK6BruFz.cjs +0 -1
  127. package/dist/dataset-IrlXbUvh.cjs +0 -1
  128. package/dist/designer-B597ZdC0.js +0 -7595
  129. package/dist/designer-DFIdv_n7.cjs +0 -2
  130. package/dist/dom-CXWMmwh-.cjs +0 -1
  131. package/dist/dom-DxdCMLzs.js +0 -452
  132. package/dist/json-snapshot-L_gJ7KRS.cjs +0 -2
  133. package/dist/protocol-CymmHWmL.cjs +0 -1
  134. package/dist/region-binding-workflow-EYxvUYJ-.js +0 -977
  135. package/dist/region-binding-workflow-NdkMSFCh.cjs +0 -3
  136. package/dist/rich-text-layout-Ch_N0Ubu.js +0 -52
  137. package/dist/rich-text-layout-yJGuThtC.cjs +0 -3
  138. package/dist/runtime-D8AlfJ6S.js +0 -234
  139. package/dist/runtime-ywf3oLBR.cjs +0 -1
  140. package/dist/workbook-session-BclW7KKH.cjs +0 -29
@@ -1,16 +1,16 @@
1
- import { r as q, a as te, L as ke, c as _t, R as Ce, k as Jt, m as L, D as Te } from "./diagnostic-collector-gB07PHy2.js";
2
- import { w as D, h as oe } from "./textwrap-BywMBMXM.js";
3
- import { e as Re, n as W, b as Ee, q as H, s as Ut, t as qt } from "./computed-f3pOqWLX.js";
4
- import { d as Qe, R as A, f as X, k as Ze, b as Xt, i as Yt, v as Ie, c as Qt, P as ae, l as $e, t as et, m as tt, h as rt, n as Zt, o as er, D as tr, e as we } from "./record-bindings-Cv7lFiof.js";
5
- import { c as rr, e as nr } from "./matrix-b6T291xo.js";
6
- import { f as nt, d as or, e as ar, c as ot } from "./template-serialization-CWmHq7lX.js";
7
- import { j as sr, r as ir, k as cr, b as Oe, v as lr, R as dr } from "./template-registry-DeVgwEZj.js";
8
- import { g as ur } from "./report-params-D9tBuM9B.js";
9
- import { a as We } from "./param-validation-CnDEd2l-.js";
10
- import { f as fr, i as mr } from "./number-format-BA_KwrZe.js";
11
- import { v as at, d as gr } from "./dataset-DL83majE.js";
12
- const hr = 4096, Ve = 128 * 1024;
13
- function pr(e) {
1
+ import { r as q, a as ee, L as Ee, c as nr, R as Oe, k as or, m as L, D as $e } from "./diagnostic-collector-C-JBA016.js";
2
+ import { w as H, h as ne } from "./textwrap-Bt_tnI6V.js";
3
+ import { e as rt, n as G, q as ar, b as Ie, s as D, t as sr, u as ir } from "./computed-CH3NYPOW.js";
4
+ import { d as nt, R as A, f as V, k as ot, b as cr, i as lr, v as Fe, c as ur, P as oe, l as Ae, t as at, m as st, h as it, n as dr, o as fr, D as mr, e as ae } from "./record-bindings-DBrCu6zO.js";
5
+ import { c as hr, e as gr } from "./matrix-CB9TqTEy.js";
6
+ import { f as ct, d as pr, e as wr, c as lt } from "./template-serialization-BgGWYV_1.js";
7
+ import { j as yr, r as br, k as vr, b as je, v as Mr, R as Sr } from "./template-registry-PSuLsnyq.js";
8
+ import { g as xr } from "./report-params-D9tBuM9B.js";
9
+ import { a as _e } from "./param-validation-CnDEd2l-.js";
10
+ import { f as Pr, i as kr } from "./number-format-BA_KwrZe.js";
11
+ import { v as Cr, d as Tr, i as Rr } from "./dataset-B8oTsC6o.js";
12
+ const Er = 4096, Je = 128 * 1024;
13
+ function Or(e) {
14
14
  const t = /* @__PURE__ */ new Map();
15
15
  let r = 0;
16
16
  return { measureMm(n, o) {
@@ -18,8 +18,8 @@ function pr(e) {
18
18
  if (s !== void 0)
19
19
  return t.delete(a), t.set(a, s), s;
20
20
  const i = e.measureMm(n, o);
21
- if (Number.isFinite(i) && a.length <= Ve) {
22
- for (; t.size >= hr || r + a.length > Ve; ) {
21
+ if (Number.isFinite(i) && a.length <= Je) {
22
+ for (; t.size >= Er || r + a.length > Je; ) {
23
23
  const c = t.keys().next().value;
24
24
  r -= c.length, t.delete(c);
25
25
  }
@@ -28,10 +28,63 @@ function pr(e) {
28
28
  return i;
29
29
  } };
30
30
  }
31
- function wr(e, t) {
31
+ async function xe(e, t) {
32
+ let r = performance.now(), n = 0;
33
+ try {
34
+ for (; ; ) {
35
+ Ue(t);
36
+ const o = e.next();
37
+ if (o.done) return o.value;
38
+ ++n < 8192 && (n % 64 !== 0 || performance.now() - r < 4) || (await new Promise((a) => setTimeout(a, 0)), Ue(t), r = performance.now(), n = 0);
39
+ }
40
+ } finally {
41
+ e.return(void 0);
42
+ }
43
+ }
44
+ function Ue(e) {
45
+ if (e?.aborted)
46
+ throw Object.assign(new Error("报表处理已取消"), { name: "AbortError", cause: e.reason });
47
+ }
48
+ const se = /* @__PURE__ */ new WeakMap();
49
+ function ut(e, t) {
50
+ return !t.formula && !e.tree && !e.computed?.some((r) => typeof r.expression == "string");
51
+ }
52
+ function $r(e) {
53
+ return se.set(e, /* @__PURE__ */ new Map()), () => {
54
+ se.delete(e);
55
+ };
56
+ }
57
+ function Ir(e, t, r) {
58
+ const n = r === t ? void 0 : new Map(r.map((a, s) => [a, t[s]]));
59
+ return { rows: e.rowVisibleWhen ? r.filter(G(e.rowVisibleWhen)) : r, originals: n };
60
+ }
61
+ function dt(e, t, r, n) {
62
+ const o = ut(e, n) ? se.get(r) : void 0, a = o?.get(e);
63
+ if (a?.input === t) return a.prepared;
64
+ const s = e.computed?.length ? rt(t, { fields: e.computed, ...n }).rows : t, i = Ir(e, t, s);
65
+ return o?.set(e, { input: t, prepared: i }), i;
66
+ }
67
+ function* Fr(e, t, r) {
68
+ const n = e.computed?.length ? (yield* ar(t, { fields: e.computed, ...r })).rows : t, o = n === t ? void 0 : /* @__PURE__ */ new Map(), a = e.rowVisibleWhen ? G(e.rowVisibleWhen) : void 0, s = a ? [] : n;
69
+ for (const [i, c] of n.entries())
70
+ o?.set(c, t[i]), a?.(c) && s.push(c), yield;
71
+ return { rows: s, originals: o };
72
+ }
73
+ async function Ar(e, t, r) {
74
+ const n = se.get(t);
75
+ if (n)
76
+ for (const o of e.pages) for (const a of o.components) {
77
+ if (a.kind !== "list") continue;
78
+ const s = a;
79
+ if (!ut(s, r) || !s.computed?.length && !s.rowVisibleWhen) continue;
80
+ const i = t[s.dataset] ?? [], c = await xe(Fr(s, i, r), r.signal);
81
+ n.set(s, { input: i, prepared: c });
82
+ }
83
+ }
84
+ function jr(e, t) {
32
85
  return { member: "body", subtotal: "subtotal", total: "grand-total" }[e?.rows.get(t)?.kind ?? "member"];
33
86
  }
34
- function yr(e) {
87
+ function Kr(e) {
35
88
  const t = e.matrix;
36
89
  if (!t.hierarchy) return t;
37
90
  const r = new Map(e.columns.map((o) => [o.field, o.header])), n = { sum: "求和", count: "计数", avg: "平均", min: "最小", max: "最大", weightedAvg: "加权平均" };
@@ -44,10 +97,10 @@ function yr(e) {
44
97
  return o.label === void 0 && a ? { ...o, label: `${a}(${n[o.op]})` } : o;
45
98
  }) };
46
99
  }
47
- function br(e, t) {
100
+ function Nr(e, t) {
48
101
  if (!e.matrix) return { list: e, rows: t };
49
102
  if (e.detail || e.groupBy || e.groups?.length || e.grandTotal) throw new Error("矩阵不能同时配置普通分组、总计或主从明细");
50
- const r = rr(t, yr(e)), n = r.columns.map((i) => ({ ...i, widthMm: i.semanticRole === "dimension" ? e.matrix.rowWidthMm ?? 40 : e.matrix.columnWidthMm ?? 28, editable: !1, align: e.align ?? "auto" })), o = { ...e, columns: n, headerGrid: r.headerGrid, rowKey: void 0, revisionField: void 0, sourceTokenField: void 0 };
103
+ const r = hr(t, Kr(e)), n = r.columns.map((i) => ({ ...i, widthMm: i.semanticRole === "dimension" ? e.matrix.rowWidthMm ?? 40 : e.matrix.columnWidthMm ?? 28, editable: !1, align: e.align ?? "auto" })), o = { ...e, columns: n, headerGrid: r.headerGrid, rowKey: void 0, revisionField: void 0, sourceTokenField: void 0 };
51
104
  e.layout === "wide" && (o.widthMm = n.reduce((i, c) => i + c.widthMm, 0));
52
105
  const a = r.metadata, s = a ? { rows: new WeakMap(r.rows.map((i, c) => [i, a.rows[c]])), header: {
53
106
  columns: a.columns,
@@ -58,37 +111,37 @@ function br(e, t) {
58
111
  } } : void 0;
59
112
  return { list: o, rows: r.rows, ...s ? { matrix: s } : {} };
60
113
  }
61
- function vr(e, t) {
114
+ function Lr(e, t) {
62
115
  if (!e.matrix?.hierarchy || !e.headerGrid) return e.headerGrid;
63
116
  const r = e.paddingMm ?? 1, n = e.headerGrid.cells.map(() => e.rowHeightMm ?? 0), o = e.columns.map((c) => c.widthMm), a = q({ ...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: d, widthMm: f } of a.cells) {
65
- const u = { ...Qe(e, e.columns[l]), ...c.style }, m = te(u).fontSizePt, b = (D(c.text ?? "", Math.max(1, f - r * 2), { fontSizePt: m, fontFamily: u.fontFamily, bold: u.bold, italic: u.italic, letterSpacingPt: u.letterSpacing }, t).length * m * (u.lineHeight ?? ke) * 25.4 / 72 + r * 2) / (c.rowSpan ?? 1);
66
- for (let y = d; y < d + (c.rowSpan ?? 1); y++) n[y] = Math.max(n[y] ?? 0, b);
67
- s.set(c, u);
117
+ for (const { cell: c, ci: l, ri: u, widthMm: f } of a.cells) {
118
+ const d = { ...nt(e, e.columns[l]), ...c.style }, m = ee(d).fontSizePt, y = (H(c.text ?? "", Math.max(1, f - r * 2), { fontSizePt: m, fontFamily: d.fontFamily, bold: d.bold, italic: d.italic, letterSpacingPt: d.letterSpacing }, t).length * m * (d.lineHeight ?? Ee) * 25.4 / 72 + r * 2) / (c.rowSpan ?? 1);
119
+ for (let w = u; w < u + (c.rowSpan ?? 1); w++) n[w] = Math.max(n[w] ?? 0, y);
120
+ s.set(c, d);
68
121
  }
69
122
  const i = e.headerGrid.cells.map((c) => c.map((l) => l ? { ...l, style: s.get(l) } : null));
70
123
  return { ...e.headerGrid, cells: i, rowHeightsMm: n };
71
124
  }
72
- function Mr(e, t, r) {
125
+ function Dr(e, t, r) {
73
126
  const n = /* @__PURE__ */ new Set(), o = e.cells.map((a, s) => {
74
127
  const i = [];
75
128
  let c = 0;
76
129
  for (const l of a) {
77
130
  for (; n.has(`${s}:${c}`); ) c++;
78
- const d = l?.colSpan ?? 1, f = l?.rowSpan ?? 1;
79
- let u = 0;
80
- for (let m = c; m < c + d; m++) {
81
- t.has(m) && u++;
82
- for (let g = s + 1; g < s + f; g++)
83
- n.add(`${g}:${m}`);
131
+ const u = l?.colSpan ?? 1, f = l?.rowSpan ?? 1;
132
+ let d = 0;
133
+ for (let m = c; m < c + u; m++) {
134
+ t.has(m) && d++;
135
+ for (let h = s + 1; h < s + f; h++)
136
+ n.add(`${h}:${m}`);
84
137
  }
85
- u && i.push(l ? { ...l, colSpan: u } : null), c += d;
138
+ d && i.push(l ? { ...l, colSpan: d } : null), c += u;
86
139
  }
87
140
  return i;
88
141
  });
89
142
  return { ...e, cells: o, colWidthsMm: r };
90
143
  }
91
- function Sr(e) {
144
+ function Hr(e) {
92
145
  if (!e.columns.some((n) => n.hidden)) return e;
93
146
  const t = /* @__PURE__ */ new Set(), r = e.columns.filter((n, o) => n.hidden ? !1 : (t.add(o), !0));
94
147
  if (!r.length) throw new Error("列表至少需要一列可见列");
@@ -96,7 +149,7 @@ function Sr(e) {
96
149
  ...e,
97
150
  columns: r,
98
151
  ...e.headerGrid ? {
99
- headerGrid: Mr(
152
+ headerGrid: Dr(
100
153
  e.headerGrid,
101
154
  t,
102
155
  r.map((n) => n.widthMm)
@@ -104,34 +157,34 @@ function Sr(e) {
104
157
  } : {}
105
158
  };
106
159
  }
107
- function* xr(e) {
160
+ function* Br(e) {
108
161
  const { page: t } = e;
109
- sr(t.components, t.flow);
162
+ yr(t.components, t.flow);
110
163
  let r = 0, n = 0;
111
- for (const o of ir(t.components, t.flow)) {
164
+ for (const o of br(t.components, t.flow)) {
112
165
  e.active();
113
- 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);
166
+ 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);
114
167
  let c = Math.max(e.top(), n + a.topMm - r);
115
168
  if (!s && i > e.bottom() - e.top() + 1e-3) throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);
116
169
  !s && c + i > e.bottom() + 1e-3 && (e.nextPage(), yield* e.takePages(), e.active(), c = e.top());
117
170
  let l = c + i;
118
- for (const d of o.components) {
119
- const f = c + d.topMm - a.topMm;
120
- d.kind === "list" ? (yield* e.list(d, f, (u) => {
121
- l = s ? u : Math.max(l, u);
122
- }), e.active()) : e.append({ ...d, topMm: f });
171
+ for (const u of o.components) {
172
+ const f = c + u.topMm - a.topMm;
173
+ u.kind === "list" ? (yield* e.list(u, f, (d) => {
174
+ l = s ? d : Math.max(l, d);
175
+ }), e.active()) : e.append({ ...u, topMm: f });
123
176
  }
124
177
  n = l, r = a.topMm + a.heightMm;
125
178
  }
126
179
  }
127
- function Pr(e) {
180
+ function Wr(e) {
128
181
  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));
129
182
  }
130
- function Fe(e) {
131
- return e.pages.some((t) => t.components.some((r) => r.kind === "list" ? Pr(r) : !!r.chartBinding));
183
+ function Ke(e) {
184
+ return e.pages.some((t) => t.components.some((r) => r.kind === "list" ? Wr(r) : !!r.chartBinding));
132
185
  }
133
- const kr = 512, ze = 256 * 1024;
134
- function Cr() {
186
+ const Gr = 512, qe = 256 * 1024;
187
+ function Vr() {
135
188
  const e = /* @__PURE__ */ new Map();
136
189
  let t = 0, r;
137
190
  return (n, o, a, s) => {
@@ -139,111 +192,111 @@ function Cr() {
139
192
  const i = JSON.stringify([n, o, a.fontSizePt, a.fontFamily, a.bold, a.italic, a.letterSpacingPt]), c = e.get(i);
140
193
  if (c)
141
194
  return e.delete(i), e.set(i, c), c.lines.slice();
142
- const l = D(n, o, a, s), d = i.length + l.reduce((f, u) => f + u.length, 0);
143
- if (d <= ze) {
144
- for (; e.size >= kr || t + d > ze; ) {
195
+ const l = H(n, o, a, s), u = i.length + l.reduce((f, d) => f + d.length, 0);
196
+ if (u <= qe) {
197
+ for (; e.size >= Gr || t + u > qe; ) {
145
198
  const f = e.keys().next().value;
146
199
  t -= e.get(f).units, e.delete(f);
147
200
  }
148
- e.set(i, { lines: l.slice(), units: d }), t += d;
201
+ e.set(i, { lines: l.slice(), units: u }), t += u;
149
202
  }
150
203
  return l;
151
204
  };
152
205
  }
153
- const Tr = 1e4, _e = 25e4;
154
- function Ae(e) {
206
+ const zr = 1e4, Xe = 25e4;
207
+ function Ne(e) {
155
208
  if (e?.aborted) throw e.reason ?? new DOMException("标签生成已取消", "AbortError");
156
209
  }
157
- function st(e, t, r) {
158
- const n = typeof e.copies == "object" ? Ze(t, e.copies.field, r) : e.copies ?? 1;
210
+ function ft(e, t, r) {
211
+ const n = typeof e.copies == "object" ? ot(t, e.copies.field, r) : e.copies ?? 1;
159
212
  if (typeof n != "number" || !Number.isSafeInteger(n) || n < 1 || n > 1e3) throw new A(`$.datasets.${r.dataset}[${r.rowIndex}]`, "每条记录复制数必须是 1..1000 的数值型整数", r.rowIndex, typeof e.copies == "object" ? e.copies.field : void 0);
160
213
  return n;
161
214
  }
162
- function it(e, t, r) {
215
+ function mt(e, t, r) {
163
216
  if (e.rowKey === void 0) return;
164
- const n = Ze(t, e.rowKey, r);
217
+ const n = ot(t, e.rowKey, r);
165
218
  if (typeof n == "string" && n.trim() || typeof n == "number" && Number.isFinite(n)) return n;
166
219
  throw new A(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`, "业务主键必须是非空字符串或有限数字", r.rowIndex, e.rowKey);
167
220
  }
168
- function Rr(e) {
221
+ function _r(e) {
169
222
  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);
170
223
  return e.pages.reduce((r, n) => r + n.components.reduce((o, a) => o + t(a), 0), 0);
171
224
  }
172
- function Er(e, t, r) {
225
+ function Jr(e, t, r) {
173
226
  const n = e.repeat, o = Object.prototype.hasOwnProperty.call(t, n.dataset) ? t[n.dataset] : void 0;
174
227
  if (!Array.isArray(o)) throw new A(`$.datasets.${n.dataset}`, "逐记录标签数据集缺失,应提供对象数组(允许空数组)");
175
- const a = /* @__PURE__ */ new Set(), s = r.maxPages ?? Tr, i = Rr(e);
228
+ const a = /* @__PURE__ */ new Set(), s = r.maxPages ?? zr, i = _r(e);
176
229
  let c = 0, l = 0;
177
- for (const [d, f] of o.entries()) {
178
- if (Ae(r.signal), !f || typeof f != "object" || Array.isArray(f)) throw new A(`$.datasets.${n.dataset}[${d}]`, "标签记录应为对象", d);
179
- const u = { rowIndex: d, dataset: n.dataset }, m = it(n, f, u);
230
+ for (const [u, f] of o.entries()) {
231
+ if (Ne(r.signal), !f || typeof f != "object" || Array.isArray(f)) throw new A(`$.datasets.${n.dataset}[${u}]`, "标签记录应为对象", u);
232
+ const d = { rowIndex: u, dataset: n.dataset }, m = mt(n, f, d);
180
233
  if (m !== void 0) {
181
- const b = JSON.stringify([typeof m, m]);
182
- if (a.has(b)) throw new A(`$.datasets.${n.dataset}[${d}].${n.rowKey}`, "业务主键重复;请先确认记录来源,避免重复打印标签", d, n.rowKey);
183
- a.add(b);
234
+ const y = JSON.stringify([typeof m, m]);
235
+ if (a.has(y)) throw new A(`$.datasets.${n.dataset}[${u}].${n.rowKey}`, "业务主键重复;请先确认记录来源,避免重复打印标签", u, n.rowKey);
236
+ a.add(y);
184
237
  }
185
- const g = st(n, f, u);
186
- if (c += g * e.pages.length, l += g * i, c > s) throw new X(s, c);
187
- if (l > _e) throw new A("$.repeat", `标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${_e},请分批生成`, d);
238
+ const h = ft(n, f, d);
239
+ if (c += h * e.pages.length, l += h * i, c > s) throw new V(s, c);
240
+ if (l > Xe) throw new A("$.repeat", `标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Xe},请分批生成`, u);
188
241
  }
189
242
  return o;
190
243
  }
191
- function Ir(e, t, r) {
244
+ function Ur(e, t, r) {
192
245
  if (!e.binding) return e;
193
- const { binding: n, ...o } = e, a = Xt(n, t.row, t);
246
+ const { binding: n, ...o } = e, a = cr(n, t.row, t);
194
247
  if (e.kind === "image") {
195
248
  if (!a) return;
196
- if (!Yt(a)) throw new A(`${r}.binding`, "图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换", t.rowIndex, n.field);
249
+ if (!lr(a)) throw new A(`${r}.binding`, "图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换", t.rowIndex, n.field);
197
250
  return { ...o, imageData: a };
198
251
  }
199
252
  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 });
200
253
  }
201
- function $r(e, t, r) {
254
+ function qr(e, t, r) {
202
255
  if (e.kind !== "text" || e.grid || e.richParagraphs?.length) return e;
203
- const n = e.style ?? {}, o = te(n).fontSizePt, a = e.text ?? e.lines?.join(`
256
+ const n = e.style ?? {}, o = ee(n).fontSizePt, a = e.text ?? e.lines?.join(`
204
257
  `) ?? "";
205
258
  if (a.length > 16384) throw new A(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 ?? oe), i = s.length * o * _t(n) * 25.4 / 72;
259
+ const s = t.wrapText(a, e.widthMm, { fontSizePt: o, bold: n.bold, italic: n.italic, fontFamily: n.fontFamily, letterSpacingPt: n.letterSpacing }, t.options.measurer ?? ne), i = s.length * o * nr(n) * 25.4 / 72;
207
260
  if (i > e.heightMm + 0.05) throw new A(r, `标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`, t.rowIndex, e.binding?.field);
208
261
  return { ...e, lines: s };
209
262
  }
210
- function ct(e, t, r) {
211
- Ae(t.options.signal);
212
- const n = Ir(e, t, r);
263
+ function ht(e, t, r) {
264
+ Ne(t.options.signal);
265
+ const n = Ur(e, t, r);
213
266
  if (!n) return;
214
267
  let o = n.grid;
215
- return o && (o = { ...o, cells: o.cells.map((a, s) => a.map((i, c) => i?.children?.length ? { ...i, children: i.children.flatMap((l, d) => {
216
- const f = ct(l, t, `${r}.grid.cells.${s}.${c}.children.${d}`);
268
+ return o && (o = { ...o, cells: o.cells.map((a, s) => a.map((i, c) => i?.children?.length ? { ...i, children: i.children.flatMap((l, u) => {
269
+ const f = ht(l, t, `${r}.grid.cells.${s}.${c}.children.${u}`);
217
270
  return f ? [f] : [];
218
- }) } : i)) }), $r(o === n.grid ? n : { ...n, grid: o }, t, r);
271
+ }) } : i)) }), qr(o === n.grid ? n : { ...n, grid: o }, t, r);
219
272
  }
220
- function Or(e, t, r, n, o, a) {
273
+ function Xr(e, t, r, n, o, a) {
221
274
  return {
222
275
  ...e,
223
276
  components: e.components.flatMap((s, i) => {
224
- const c = ct(s, r, `$.pages.${t}.components.${i}`);
277
+ const c = ht(s, r, `$.pages.${t}.components.${i}`);
225
278
  return c ? [{ ...c, meta: { ...c.meta, labelSource: { pageIndex: t, componentIndex: i } } }] : [];
226
279
  }),
227
280
  meta: { ...e.meta, record: { dataset: r.dataset, rowIndex: r.rowIndex, ...a === void 0 ? {} : { rowKey: a }, copyIndex: n, copyCount: o, templatePageIndex: t } }
228
281
  };
229
282
  }
230
- function* Fr(e, t, r) {
283
+ function* Yr(e, t, r) {
231
284
  const n = [];
232
- if (cr(e, n), n.length) throw new A(n[0].path, n[0].message);
285
+ if (vr(e, n), n.length) throw new A(n[0].path, n[0].message);
233
286
  if (!e.repeat) {
234
287
  for (const [i, c] of e.pages.entries()) yield { page: c, pageIndex: i };
235
288
  return;
236
289
  }
237
- const o = e.repeat, a = Er(e, t, r), s = Cr();
290
+ const o = e.repeat, a = Jr(e, t, r), s = Vr();
238
291
  for (const [i, c] of a.entries()) {
239
- const l = { row: c, rowIndex: i, dataset: o.dataset, options: r, wrapText: s }, d = st(o, c, l), f = it(o, c, l);
240
- for (let u = 0; u < d; u++) for (const [m, g] of e.pages.entries())
241
- Ae(r.signal), yield { page: Or(g, m, l, u, d, f), pageIndex: m };
292
+ const l = { row: c, rowIndex: i, dataset: o.dataset, options: r, wrapText: s }, u = ft(o, c, l), f = mt(o, c, l);
293
+ for (let d = 0; d < u; d++) for (const [m, h] of e.pages.entries())
294
+ Ne(r.signal), yield { page: Xr(h, m, l, d, u, f), pageIndex: m };
242
295
  }
243
296
  }
244
- const Ar = Object.freeze({}), jr = 16;
245
- function Kr(e) {
246
- if (e === void 0) return Ar;
297
+ const Qr = Object.freeze({}), Zr = 16;
298
+ function en(e) {
299
+ if (e === void 0) return Qr;
247
300
  try {
248
301
  const t = Object.getPrototypeOf(e);
249
302
  if (t !== Object.prototype && t !== null || Object.getOwnPropertySymbols(e).length) return;
@@ -260,23 +313,23 @@ function Kr(e) {
260
313
  return;
261
314
  }
262
315
  }
263
- function Nr(e, t) {
316
+ function tn(e, t) {
264
317
  const r = Object.keys(t);
265
318
  return r.length === Object.keys(e).length && r.every((n) => Object.prototype.hasOwnProperty.call(e, n) && Object.is(e[n], t[n]));
266
319
  }
267
- function Lr(e) {
320
+ function rn(e) {
268
321
  const t = [];
269
322
  return (r, n, o, a) => {
270
- if (!Number.isInteger(r) || r < 0 || r >= jr) return e(o, a);
271
- const s = Kr(a);
323
+ if (!Number.isInteger(r) || r < 0 || r >= Zr) return e(o, a);
324
+ const s = en(a);
272
325
  if (!s) return e(o, a);
273
326
  const i = t[r];
274
- if (i?.firstRow === n && i.label === o && Nr(i.style, s)) return i.row;
327
+ if (i?.firstRow === n && i.label === o && tn(i.style, s)) return i.row;
275
328
  const c = e(o, a);
276
329
  return t[r] = { firstRow: n, label: o, style: s, row: c }, c;
277
330
  };
278
331
  }
279
- function Hr(e) {
332
+ function nn(e) {
280
333
  return {
281
334
  widthMm: e.widthMm,
282
335
  heightMm: e.heightMm,
@@ -287,119 +340,119 @@ function Hr(e) {
287
340
  components: []
288
341
  };
289
342
  }
290
- function se(e, t) {
343
+ function ie(e, t) {
291
344
  const r = t.heightMm - (e.layout === "wide" ? t.marginBottomMm : e.marginBottomMm ?? t.marginBottomMm);
292
345
  return e.components.reduce((n, o) => o.kind !== "list" && o.pageAnchor === "footer" ? Math.min(n, o.topMm) : n, r);
293
346
  }
294
- function Y(e) {
347
+ function X(e) {
295
348
  return e.components.reduce((t, r) => r.kind !== "list" && r.pageAnchor === "header" ? Math.max(t, r.topMm + r.heightMm) : t, 0);
296
349
  }
297
- function lt(e, t) {
350
+ function gt(e, t) {
298
351
  let r = e.textMetrics.get(t);
299
352
  if (!r) {
300
- const n = te(t).fontSizePt;
353
+ const n = ee(t).fontSizePt;
301
354
  r = {
302
355
  measureOptions: {
303
356
  fontSizePt: n,
304
- fontFamily: t.fontFamily ?? Te,
357
+ fontFamily: t.fontFamily ?? $e,
305
358
  italic: t.italic,
306
359
  bold: t.bold,
307
360
  letterSpacingPt: t.letterSpacing
308
361
  },
309
- lineMm: n * (t.lineHeight ?? ke) * 25.4 / 72
362
+ lineMm: n * (t.lineHeight ?? Ee) * 25.4 / 72
310
363
  }, e.textMetrics.set(t, r);
311
364
  }
312
365
  return r;
313
366
  }
314
- function Dr(e) {
367
+ function on(e) {
315
368
  if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
316
369
  }
317
- function je(e, t, r = [], n) {
318
- const o = e.fontSizePt ?? Jt, a = e.paddingMm ?? 1, s = e.columns.map((p) => p.align ?? p.style?.align ?? e.align ?? "auto"), i = e.columns.map((p, h) => ({
370
+ function Le(e, t, r = [], n) {
371
+ const o = e.fontSizePt ?? or, a = e.paddingMm ?? 1, s = e.columns.map((p) => p.align ?? p.style?.align ?? e.align ?? "auto"), i = e.columns.map((p, g) => ({
319
372
  ...L({
320
373
  fontSize: o,
321
374
  verticalAlign: "middle"
322
375
  }, p.style),
323
- align: s[h] === "auto" ? "left" : s[h]
324
- })), c = i.map((p, h) => s[h] === "auto" ? { left: p, center: { ...p, align: "center" }, right: { ...p, align: "right" } } : void 0), l = e.columns.map((p, h) => p.rules?.map((S) => {
325
- const T = c[h];
326
- if (T) return {
327
- left: L(T.left, S.style),
328
- center: L(T.center, S.style),
329
- right: L(T.right, S.style)
376
+ align: s[g] === "auto" ? "left" : s[g]
377
+ })), c = i.map((p, g) => s[g] === "auto" ? { left: p, center: { ...p, align: "center" }, right: { ...p, align: "right" } } : void 0), l = e.columns.map((p, g) => p.rules?.map((S) => {
378
+ const R = c[g];
379
+ if (R) return {
380
+ left: L(R.left, S.style),
381
+ center: L(R.center, S.style),
382
+ right: L(R.right, S.style)
330
383
  };
331
- const R = L(i[h], S.style);
332
- return { left: R, center: R, right: R };
333
- })), d = e.columns.map((p) => Qe(e, p)), f = e.columns.map((p) => p.header);
334
- let u = e.rowHeightMm ?? 0;
384
+ const E = L(i[g], S.style);
385
+ return { left: E, center: E, right: E };
386
+ })), u = e.columns.map((p) => nt(e, p)), f = e.columns.map((p) => p.header);
387
+ let d = e.rowHeightMm ?? 0;
335
388
  for (let p = 0; p < f.length; p++) {
336
- const h = d[p], S = te(h).fontSizePt, T = D(
389
+ const g = u[p], S = ee(g).fontSizePt, R = H(
337
390
  f[p],
338
391
  e.columns[p].widthMm - a * 2,
339
- { fontSizePt: S, fontFamily: h.fontFamily ?? Te, italic: h.italic, bold: h.bold, letterSpacingPt: h.letterSpacing },
392
+ { fontSizePt: S, fontFamily: g.fontFamily ?? $e, italic: g.italic, bold: g.bold, letterSpacingPt: g.letterSpacing },
340
393
  t
341
- ), R = S * (h.lineHeight ?? ke) * 25.4 / 72;
342
- u = Math.max(u, Math.max(T.length, 1) * R + a * 2);
394
+ ), E = S * (g.lineHeight ?? Ee) * 25.4 / 72;
395
+ d = Math.max(d, Math.max(R.length, 1) * E + a * 2);
343
396
  }
344
- const m = f.map((p, h) => ({
397
+ const m = f.map((p, g) => ({
345
398
  text: p,
346
- style: d[h]
347
- })), g = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, b = e.columns.map((p) => p.widthMm), y = Br(vr(e, t), b, {
399
+ style: u[g]
400
+ })), h = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 }, y = e.columns.map((p) => p.widthMm), w = an(Lr(e, t), y, {
348
401
  cells: [m],
349
- colWidthsMm: b,
350
- rowHeightsMm: [u],
402
+ colWidthsMm: y,
403
+ rowHeightsMm: [d],
351
404
  paddingMm: a
352
405
  });
353
406
  return {
354
407
  fontSizePt: o,
355
408
  paddingMm: a,
356
- visuals: ar(e.columns, r, n),
357
- visibility: e.columns.map((p) => p.visibleWhen ? W(p.visibleWhen) : void 0),
358
- ruleReaders: e.columns.map((p) => p.rules?.map((h) => W(h.when))),
409
+ visuals: wr(e.columns, r, n),
410
+ visibility: e.columns.map((p) => p.visibleWhen ? G(p.visibleWhen) : void 0),
411
+ ruleReaders: e.columns.map((p) => p.rules?.map((g) => G(g.when))),
359
412
  cellStyles: i,
360
413
  autoStyles: c,
361
414
  ruleStyles: l,
362
415
  textMetrics: /* @__PURE__ */ new WeakMap(),
363
- numberFormats: e.columns.map((p) => et(p.format)),
416
+ numberFormats: e.columns.map((p) => at(p.format)),
364
417
  derivedFields: new Set(e.computed?.map((p) => p.field)),
365
- borderStyle: g,
366
- headerHeightMm: y.rowHeightsMm.reduce((p, h) => p + h, 0),
367
- headerGrid: y,
368
- colWidthsMm: b,
418
+ borderStyle: h,
419
+ headerHeightMm: w.rowHeightsMm.reduce((p, g) => p + g, 0),
420
+ headerGrid: w,
421
+ colWidthsMm: y,
369
422
  columns: e.columns
370
423
  };
371
424
  }
372
- function Br(e, t, r) {
425
+ function an(e, t, r) {
373
426
  if (!e) return r;
374
427
  if (!e.cells.length) throw new Error("自定义列表表头至少需要一行");
375
428
  const n = e.rowHeightsMm ?? e.cells.map(() => r.rowHeightsMm[0]);
376
429
  if (n.length !== e.cells.length || n.some((o) => !Number.isFinite(o) || o <= 0)) throw new Error("自定义列表表头行高无效");
377
430
  return { ...e, colWidthsMm: t, rowHeightsMm: n };
378
431
  }
379
- function Gr(e, t, r) {
432
+ function sn(e, t, r) {
380
433
  const n = t.format?.kind === "number" || t.format?.kind === "percent";
381
434
  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);
382
435
  }
383
- function Q(e, t, r) {
436
+ function Y(e, t, r) {
384
437
  const n = e.columns, o = e.tree?.rows.get(t);
385
438
  let a = e.rowHeightFloorMm;
386
439
  const s = new Array(n.length);
387
440
  for (let i = 0; i < n.length; i++) {
388
- const c = n[i], l = e.visibility[i]?.(t) !== !1, d = l ? t[c.field] : null, f = e.autoStyles[i] ? tt(d, c.format, c.semanticRole, c.valueType) : "left";
389
- let u = e.autoStyles[i]?.[f] ?? e.cellStyles[i];
441
+ const c = n[i], l = e.visibility[i]?.(t) !== !1, u = l ? t[c.field] : null, f = e.autoStyles[i] ? st(u, c.format, c.semanticRole, c.valueType) : "left";
442
+ let d = e.autoStyles[i]?.[f] ?? e.cellStyles[i];
390
443
  if (c.rules) {
391
444
  for (let S = 0; S < c.rules.length; S++)
392
445
  if (e.ruleReaders[i][S](t)) {
393
- u = e.ruleStyles[i][S][f];
446
+ d = e.ruleStyles[i][S][f];
394
447
  break;
395
448
  }
396
449
  }
397
- const m = c.format ? rt(d, c.format) : $e(d), g = Wr(e, c, o);
398
- u = Vr(e, c, u, o);
399
- const b = lt(e, u), y = D(m, Math.max(1, c.widthMm - e.paddingMm * 2 - g), b.measureOptions, r);
400
- a = Math.max(a, y.length * b.lineMm + e.paddingMm * 2);
401
- const p = Dr(d), h = { text: m, style: u };
402
- d != null && e.visuals[i]?.apply(h, t), p !== void 0 && (h.value = p), Gr(h, c, e.numberFormats[i]), zr(h, c, e, o, g), e.derivedFields.has(c.field) && (h.derived = !0, h.editable = !1), l || (h.editable = !1), s[i] = h;
450
+ const m = c.format ? it(u, c.format) : Ae(u), h = cn(e, c, o);
451
+ d = ln(e, c, d, o);
452
+ const y = gt(e, d), w = H(m, Math.max(1, c.widthMm - e.paddingMm * 2 - h), y.measureOptions, r);
453
+ a = Math.max(a, w.length * y.lineMm + e.paddingMm * 2);
454
+ const p = on(u), g = { text: m, style: d };
455
+ u != null && e.visuals[i]?.apply(g, t), p !== void 0 && (g.value = p), sn(g, c, e.numberFormats[i]), un(g, c, e, o, h), e.derivedFields.has(c.field) && (g.derived = !0, g.editable = !1), l || (g.editable = !1), s[i] = g;
403
456
  }
404
457
  return {
405
458
  grid: { cells: [s], colWidthsMm: e.colWidthsMm, rowHeightsMm: [a], paddingMm: e.paddingMm },
@@ -407,20 +460,20 @@ function Q(e, t, r) {
407
460
  ...e.matrix ? { meta: { matrix: { row: e.matrix.rows.get(t) } } } : {}
408
461
  };
409
462
  }
410
- function Wr(e, t, r) {
411
- return !r || t.field !== e.tree.list.tree.labelField ? 0 : Zt(e.tree.list, t, r, e.paddingMm);
463
+ function cn(e, t, r) {
464
+ return !r || t.field !== e.tree.list.tree.labelField ? 0 : dr(e.tree.list, t, r, e.paddingMm);
412
465
  }
413
- function Vr(e, t, r, n) {
466
+ function ln(e, t, r, n) {
414
467
  return !n || t.field !== e.tree.list.tree.labelField || r.align === "left" ? r : { ...r, align: "left" };
415
468
  }
416
- function zr(e, t, r, n, o = 0) {
417
- n && (o && (e.indentMm = o), er(e, t, n, r.tree.list));
469
+ function un(e, t, r, n, o = 0) {
470
+ n && (o && (e.indentMm = o), fr(e, t, n, r.tree.list));
418
471
  }
419
- function dt(e) {
472
+ function pt(e) {
420
473
  if (e != null && typeof e != "string" && typeof e != "boolean" && !(typeof e == "number" && Number.isFinite(e))) throw new Error("分组字段应为有限 JSON 标量");
421
474
  return JSON.stringify([typeof e, e ?? null]);
422
475
  }
423
- function* ut(e, t, r = 0) {
476
+ function* wt(e, t, r = 0) {
424
477
  const n = t[r];
425
478
  if (!n) {
426
479
  for (const a of e) yield { kind: "row", row: a };
@@ -428,54 +481,54 @@ function* ut(e, t, r = 0) {
428
481
  }
429
482
  const o = /* @__PURE__ */ new Map();
430
483
  for (const a of e) {
431
- const s = dt(a[n.field]), i = o.get(s);
484
+ const s = pt(a[n.field]), i = o.get(s);
432
485
  i ? i.push(a) : o.set(s, [a]);
433
486
  }
434
487
  for (const a of o.values())
435
- yield { kind: "groupHeader", label: (n.headerTemplate ?? "{value}").replace(/\{value\}/g, $e(a[0][n.field])), firstRow: a[0], group: n, depth: r, rows: a }, yield* ut(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 };
488
+ yield { kind: "groupHeader", label: (n.headerTemplate ?? "{value}").replace(/\{value\}/g, Ae(a[0][n.field])), firstRow: a[0], group: n, depth: r, rows: a }, yield* wt(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 };
436
489
  }
437
- function ft(e, t, r, n = []) {
490
+ function yt(e, t, r, n = []) {
438
491
  const o = [...r.filter((a) => !n.some((s) => s.field === a)).map((a) => ({ field: a, op: "sum" })), ...n];
439
492
  return new Map(o.map((a) => {
440
- const s = e.find((c) => c.field === a.field)?.format ?? { kind: "number", thousands: !0 }, i = Ee(t, { ...a, field: a.valueField ?? a.field });
441
- return [a.field, { text: rt(i, s), ...i === null ? {} : { value: i }, ...typeof i == "number" ? { numberFormat: et(s) } : {} }];
493
+ const s = e.find((c) => c.field === a.field)?.format ?? { kind: "number", thousands: !0 }, i = Ie(t, { ...a, field: a.valueField ?? a.field });
494
+ return [a.field, { text: it(i, s), ...i === null ? {} : { value: i }, ...typeof i == "number" ? { numberFormat: at(s) } : {} }];
442
495
  }));
443
496
  }
444
- function mt(e, t) {
497
+ function bt(e, t) {
445
498
  const r = e.findIndex((n) => t.includes(n.field));
446
499
  return r < 0 ? 1 : r;
447
500
  }
448
- function ie(e, t, r, n, o, a) {
501
+ function ce(e, t, r, n, o, a) {
449
502
  const s = [], i = Math.max(0, Math.min(a, e.columns.length)), c = L({ fontSize: e.fontSizePt }, o);
450
503
  i && s.push({ text: r, colSpan: i, style: { bold: !0, ...c } });
451
- for (let u = i; u < e.columns.length; u++) {
452
- const m = e.columns[u], g = n.get(m.field), b = e.autoStyles[u]?.[tt(g?.value, m.format, m.semanticRole, m.valueType)] ?? e.cellStyles[u];
453
- s.push({ ...g, text: g?.text ?? "", style: L(b, o) });
504
+ for (let d = i; d < e.columns.length; d++) {
505
+ const m = e.columns[d], h = n.get(m.field), y = e.autoStyles[d]?.[st(h?.value, m.format, m.semanticRole, m.valueType)] ?? e.cellStyles[d];
506
+ s.push({ ...h, text: h?.text ?? "", style: L(y, o) });
454
507
  }
455
- const l = { text: r, colSpan: e.columns.length, style: { bold: !0, ...c } }, d = i ? [s] : [[l], s], f = d.map((u) => _r(e, u, t));
508
+ const l = { text: r, colSpan: e.columns.length, style: { bold: !0, ...c } }, u = i ? [s] : [[l], s], f = u.map((d) => dn(e, d, t));
456
509
  return {
457
- grid: { cells: d, colWidthsMm: e.colWidthsMm, rowHeightsMm: f, paddingMm: e.paddingMm },
458
- heightMm: f.reduce((u, m) => u + m, 0)
510
+ grid: { cells: u, colWidthsMm: e.colWidthsMm, rowHeightsMm: f, paddingMm: e.paddingMm },
511
+ heightMm: f.reduce((d, m) => d + m, 0)
459
512
  };
460
513
  }
461
- function _r(e, t, r) {
514
+ function dn(e, t, r) {
462
515
  let n = e.rowHeightFloorMm, o = 0;
463
516
  for (const a of t) {
464
517
  let s = 0;
465
518
  const i = o + (a.colSpan ?? 1);
466
519
  for (; o < i; o++) s += e.colWidthsMm[o] ?? 0;
467
- const c = lt(e, a.style), l = D(a.text ?? "", s - e.paddingMm * 2, c.measureOptions, r);
520
+ const c = gt(e, a.style), l = H(a.text ?? "", s - e.paddingMm * 2, c.measureOptions, r);
468
521
  n = Math.max(n, l.length * c.lineMm + e.paddingMm * 2);
469
522
  }
470
523
  return n;
471
524
  }
472
- function Jr(e, t, r) {
473
- const { templatePage: n, current: o, warnings: a, nextId: s, pushCurrent: i } = r, c = () => se(n, o), l = Math.max(o.marginTopMm, Y(n)), d = n.layout === "wide" ? Y(n) : l, f = {
525
+ function fn(e, t, r) {
526
+ const { templatePage: n, current: o, warnings: a, nextId: s, pushCurrent: i } = r, c = () => ie(n, o), l = Math.max(o.marginTopMm, X(n)), u = n.layout === "wide" ? X(n) : l, f = {
474
527
  id: r.tableId,
475
- columnKeys: e.columns.map((w) => w.field),
528
+ columnKeys: e.columns.map((x) => x.field),
476
529
  ...e.layout === void 0 ? {} : { layout: e.layout },
477
530
  ...e.title === void 0 ? {} : { title: e.title }
478
- }, u = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = {
531
+ }, d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = {
479
532
  kind: "rect",
480
533
  leftMm: e.leftMm,
481
534
  topMm: 0,
@@ -486,53 +539,53 @@ function Jr(e, t, r) {
486
539
  table: { ...f, role: "header", rowIndex: -1 },
487
540
  style: t.borderStyle,
488
541
  ...e.meta || t.matrix ? { meta: { ...e.meta, ...t.matrix ? { matrix: t.matrix.header } : {} } } : {}
489
- }, b = (w) => o.components.push({ ...g, topMm: w });
542
+ }, y = (x) => o.components.push({ ...h, topMm: x });
490
543
  if (r.flow && e.header !== !1 && t.headerHeightMm > c() - l + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的表头高度超出单页可用范围`);
491
- let y = Math.max(r.startTop ?? e.topMm, l);
492
- e.header !== !1 && (b(y), y += t.headerHeightMm + r.mmPerRow);
544
+ let w = Math.max(r.startTop ?? e.topMm, l);
545
+ e.header !== !1 && (y(w), w += t.headerHeightMm + r.mmPerRow);
493
546
  function p() {
494
- const w = Math.max(r.flow || n.layout === "wide" ? 0 : e.topMm, d);
495
- return (e.header !== !1 && e.headerEveryPage !== !1 ? w + t.headerHeightMm : d) + [...m.values()].reduce((P, E) => P + E.heightMm, 0);
547
+ const x = Math.max(r.flow || n.layout === "wide" ? 0 : e.topMm, u);
548
+ return (e.header !== !1 && e.headerEveryPage !== !1 ? x + t.headerHeightMm : u) + [...m.values()].reduce((P, k) => P + k.heightMm, 0);
496
549
  }
497
- function h() {
498
- const w = n.layout === "wide" ? 0 : o.marginBottomMm;
499
- return Math.min(n.heightMm - w, se(n, o)) - p();
550
+ function g() {
551
+ const x = n.layout === "wide" ? 0 : o.marginBottomMm;
552
+ return Math.min(n.heightMm - x, ie(n, o)) - p();
500
553
  }
501
- function S(w) {
502
- if (y + w <= c()) return;
554
+ function S(x) {
555
+ if (w + x <= c()) return;
503
556
  i(), o.components = [], o.heightMm = n.heightMm, n.layout === "wide" && (o.marginTopMm = 0, o.marginBottomMm = 0);
504
- const x = Math.max(r.flow || n.layout === "wide" ? 0 : e.topMm, d);
505
- e.header !== !1 && e.headerEveryPage !== !1 ? (b(x), y = x + t.headerHeightMm) : y = d;
506
- for (const P of m.values()) R(P, "listgr", "group-header");
507
- }
508
- function T(w, x, P, E) {
509
- const k = h();
510
- if (r.flow && w.heightMm > k + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的单行高度超出单页可用范围`);
511
- w.heightMm > k && a.push(`列表 ${e.id ?? e.dataset} 行高 ${w.heightMm.toFixed(2)}mm 超出单页可用高度 ${k.toFixed(2)}mm,预览与打印可能截断内容`), S(w.heightMm), R(w, x, P, E);
512
- }
513
- function R(w, x, P, E) {
514
- const k = w.table?.id ?? f.id, M = P === "header" ? -1 : u.get(k) ?? 0;
515
- P !== "header" && u.set(k, M + w.grid.cells.length), o.components.push({
557
+ const b = Math.max(r.flow || n.layout === "wide" ? 0 : e.topMm, u);
558
+ e.header !== !1 && e.headerEveryPage !== !1 ? (y(b), w = b + t.headerHeightMm) : w = u;
559
+ for (const P of m.values()) E(P, "listgr", "group-header");
560
+ }
561
+ function R(x, b, P, k) {
562
+ const C = g();
563
+ if (r.flow && x.heightMm > C + 1e-3) throw new Error(`流式列表 ${e.id ?? e.dataset} 的单行高度超出单页可用范围`);
564
+ x.heightMm > C && a.push(`列表 ${e.id ?? e.dataset} 行高 ${x.heightMm.toFixed(2)}mm 超出单页可用高度 ${C.toFixed(2)}mm,预览与打印可能截断内容`), S(x.heightMm), E(x, b, P, k);
565
+ }
566
+ function E(x, b, P, k) {
567
+ const C = x.table?.id ?? f.id, M = P === "header" ? -1 : d.get(C) ?? 0;
568
+ P !== "header" && d.set(C, M + x.grid.cells.length), o.components.push({
516
569
  kind: "rect",
517
570
  leftMm: e.leftMm,
518
- topMm: y,
571
+ topMm: w,
519
572
  widthMm: e.widthMm,
520
- heightMm: w.heightMm,
521
- grid: w.grid,
522
- nid: s(x),
523
- table: { ...f, ...w.table, role: P, rowIndex: M, ...E ? { source: E } : {} },
573
+ heightMm: x.heightMm,
574
+ grid: x.grid,
575
+ nid: s(b),
576
+ table: { ...f, ...x.table, role: P, rowIndex: M, ...k ? { source: k } : {} },
524
577
  style: t.borderStyle,
525
- ...e.meta || w.meta ? { meta: { ...e.meta, ...w.meta } } : {}
526
- }), y += w.heightMm;
578
+ ...e.meta || x.meta ? { meta: { ...e.meta, ...x.meta } } : {}
579
+ }), w += x.heightMm;
527
580
  }
528
- function O(w) {
529
- w <= h() && S(w);
581
+ function I(x) {
582
+ x <= g() && S(x);
530
583
  }
531
- return { keepTogether: O, placeGridRow: T, setGroupHeader: (w, x) => {
532
- x ? m.set(w, x) : m.delete(w);
533
- }, bottom: () => y };
584
+ return { keepTogether: I, placeGridRow: R, setGroupHeader: (x, b) => {
585
+ b ? m.set(x, b) : m.delete(x);
586
+ }, bottom: () => w };
534
587
  }
535
- function Ur(e, t) {
588
+ function mn(e, t) {
536
589
  if (!e.rowKey) return;
537
590
  const r = t[e.rowKey];
538
591
  if ((typeof r != "string" || !r.trim()) && !(typeof r == "number" && Number.isFinite(r)))
@@ -542,175 +595,172 @@ function Ur(e, t) {
542
595
  if (o !== void 0 && typeof o != "string") throw new Error("来源令牌应为字符串");
543
596
  return { datasetId: e.dataset, rowKey: r, ...n === void 0 ? {} : { revision: n }, ...o === void 0 ? {} : { sourceToken: o } };
544
597
  }
545
- function le(e, t) {
598
+ function me(e, t) {
546
599
  const r = /* @__PURE__ */ new Map();
547
600
  if (!e.rowKey) return r;
548
601
  const n = /* @__PURE__ */ new Set();
549
602
  for (const o of t) {
550
- const a = Ur(e, o), s = JSON.stringify(a.rowKey);
603
+ const a = mn(e, o), s = JSON.stringify(a.rowKey);
551
604
  if (n.has(s)) throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);
552
605
  n.add(s), r.set(o, a);
553
606
  }
554
607
  return r;
555
608
  }
556
- function qr(e, t, r, n, o) {
609
+ function hn(e, t, r, n, o) {
557
610
  if (!e.grandTotal) return;
558
- const a = typeof e.grandTotal == "object" ? e.grandTotal : void 0, s = de(e)[0], i = a?.fields ?? s?.subtotal ?? [], c = a?.aggregates ?? s?.aggregates ?? [];
611
+ const a = typeof e.grandTotal == "object" ? e.grandTotal : void 0, s = he(e)[0], i = a?.fields ?? s?.subtotal ?? [], c = a?.aggregates ?? s?.aggregates ?? [];
559
612
  if (i.length === 0 && c.length === 0) {
560
613
  n.warnings.push(`列表 ${e.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
561
614
  return;
562
615
  }
563
- const l = ie(r, n.measurer, a?.label ?? "合计", ft(e.columns, t, i, c), a?.style ?? {}, mt(e.columns, [...i, ...c.map((d) => d.field)]));
616
+ const l = ce(r, n.measurer, a?.label ?? "合计", yt(e.columns, t, i, c), a?.style ?? {}, bt(e.columns, [...i, ...c.map((u) => u.field)]));
564
617
  o.placeGridRow(l, "listgt", "grand-total");
565
618
  }
566
- function K(e) {
619
+ function N(e) {
567
620
  if (e?.aborted) {
568
621
  const t = new Error("报表排版已取消");
569
622
  throw t.name = "AbortError", t;
570
623
  }
571
624
  }
572
- function de(e) {
625
+ function he(e) {
573
626
  const t = e.groups ?? (e.groupBy ? [e.groupBy] : []);
574
627
  if (t.length > 16) throw new Error("列表最多支持 16 级分组");
575
628
  return t;
576
629
  }
577
- function Ke(e) {
578
- const t = Sr(e), r = t.columns.reduce((o, a) => o + a.widthMm, 0), n = r > t.widthMm ? t.widthMm / r : 1;
630
+ function De(e) {
631
+ const t = Hr(e), r = t.columns.reduce((o, a) => o + a.widthMm, 0), n = r > t.widthMm ? t.widthMm / r : 1;
579
632
  return n === 1 ? t : { ...t, columns: t.columns.map((o) => ({ ...o, widthMm: o.widthMm * n })) };
580
633
  }
581
- function Xr(e, t, r) {
634
+ function gn(e, t, r) {
582
635
  const n = e.detail;
583
636
  if (!n) return;
584
637
  const o = /* @__PURE__ */ new Set();
585
638
  for (const l of t) {
586
- const d = ye(l[n.parentKey]);
587
- if (o.has(d)) throw new Error("主从明细的主表关联键重复");
588
- o.add(d);
639
+ const u = Pe(l[n.parentKey]);
640
+ if (o.has(u)) throw new Error("主从明细的主表关联键重复");
641
+ o.add(u);
589
642
  }
590
643
  const a = r.datasets[n.dataset] ?? [], s = /* @__PURE__ */ new Map(), i = [];
591
644
  for (const l of a) {
592
- const d = l[n.foreignKey];
593
- if (!gt(d) && n.unmatched === "ignore") continue;
594
- const f = ye(d);
645
+ const u = l[n.foreignKey];
646
+ if (!vt(u) && n.unmatched === "ignore") continue;
647
+ const f = Pe(u);
595
648
  if (!o.has(f)) {
596
649
  if (n.unmatched !== "ignore") throw new Error(`明细数据集 ${n.dataset} 存在未关联的业务键`);
597
650
  continue;
598
651
  }
599
- const u = s.get(f);
600
- u ? u.push(l) : s.set(f, [l]), i.push(l);
652
+ const d = s.get(f);
653
+ d ? d.push(l) : s.set(f, [l]), i.push(l);
601
654
  }
602
- const c = Ke({ ...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 });
603
- return { list: c, inter: { ...je(c, r.measurer, i, r.signal), rowHeightFloorMm: c.rowHeightMm ?? 0 }, rows: s, sources: le(c, i) };
655
+ const c = De({ ...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 });
656
+ return { list: c, inter: { ...Le(c, r.measurer, i, r.signal), rowHeightFloorMm: c.rowHeightMm ?? 0 }, rows: s, sources: me(c, i) };
604
657
  }
605
- function gt(e) {
658
+ function vt(e) {
606
659
  return typeof e == "string" && !!e.trim() || typeof e == "number" && Number.isFinite(e);
607
660
  }
608
- function ye(e) {
609
- if (!gt(e)) throw new Error("主从关联键必须是非空字符串或有限数字");
610
- return dt(e);
661
+ function Pe(e) {
662
+ if (!vt(e)) throw new Error("主从关联键必须是非空字符串或有限数字");
663
+ return pt(e);
611
664
  }
612
- function* Yr(e, t, r, n, o) {
665
+ function* pn(e, t, r, n, o) {
613
666
  if (!r) return;
614
- const a = r.rows.get(ye(t[e.detail.parentKey])) ?? [];
667
+ const a = r.rows.get(Pe(t[e.detail.parentKey])) ?? [];
615
668
  if (!a.length) return;
616
669
  const s = { id: `${n.tableId}:detail`, columnKeys: r.list.columns.map((i) => i.field), title: e.detail.label };
617
- e.detail.label && o.placeGridRow({ ...ie(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();
670
+ e.detail.label && o.placeGridRow({ ...ce(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();
618
671
  for (const i of a)
619
- K(n.signal), o.placeGridRow({ ...Q(r.inter, i, n.measurer), table: s }, "listdr", "body", r.sources.get(i)), yield* n.takePages();
672
+ N(n.signal), o.placeGridRow({ ...Y(r.inter, i, n.measurer), table: s }, "listdr", "body", r.sources.get(i)), yield* n.takePages();
620
673
  }
621
- function ht(e) {
674
+ function Mt(e) {
622
675
  if (e.matrix || e.detail || e.groups?.length || e.groupBy || e.rowVisibleWhen) throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");
623
676
  if (e.rowKey && e.rowKey !== e.tree.idField) throw new Error("树形布局的 rowKey 应与 idField 一致");
624
677
  if (!e.columns.some((t) => t.field === e.tree.labelField && !t.hidden)) throw new Error("树形布局需要可见的标签列");
625
- or(e.tree, e.computed);
678
+ pr(e.tree, e.computed);
626
679
  }
627
- function Qr(e, t, r) {
628
- ht(e);
629
- const n = ot(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 = le(o, n.entries.map((c) => c.original)), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap();
680
+ function wn(e, t, r) {
681
+ Mt(e);
682
+ const n = lt(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 = me(o, n.entries.map((c) => c.original)), s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap();
630
683
  for (const c of n.entries)
631
684
  s.set(c.row, a.get(c.original)), i.set(c.row, c);
632
685
  return { list: o, rows: n.rows, sources: s, treeRows: i, totalRows: n.leaves };
633
686
  }
634
- function Zr(e, t) {
687
+ function yn(e, t) {
635
688
  if (e.cardinality === "record") {
636
689
  if (t.length > 1) throw new Error(`单记录区域 ${e.id ?? e.dataset} 仅允许 0 或 1 行数据`);
637
690
  if (e.tree || e.matrix || e.detail || e.groups?.length || e.groupBy || e.grandTotal || e.rowVisibleWhen) throw new Error("单记录区域不能配置树、矩阵、主从、分组、总计或行过滤");
638
691
  if (!t.length) return { list: { ...e, columns: e.columns.map((r) => ({ ...r, editable: !1 })) }, rows: [{}], sources: /* @__PURE__ */ new Map() };
639
692
  }
640
693
  }
641
- function pt(e, t, r) {
694
+ function St(e, t, r) {
642
695
  const n = r.prepared.get(e);
643
696
  if (n) return n;
644
- const o = Zr(e, t);
697
+ const o = yn(e, t);
645
698
  if (o)
646
699
  return r.prepared.set(e, o), o;
647
700
  if (e.tree) {
648
- const c = Qr(e, t, r);
701
+ const c = wn(e, t, r);
649
702
  return r.prepared.set(e, c), c;
650
703
  }
651
- let a = e.computed?.length ? Re(t, { fields: e.computed, signal: r.signal, formula: r.formula }).rows : t;
652
- const s = a === t ? void 0 : new Map(a.map((c, l) => [c, t[l]]));
653
- e.rowVisibleWhen && (a = a.filter(W(e.rowVisibleWhen)));
654
- const i = br(e, a);
704
+ const { rows: a, originals: s } = dt(e, t, r.datasets, r), i = Nr(e, a);
655
705
  if (!e.matrix) {
656
- const c = le(e, s ? a.map((l) => s.get(l)) : a);
706
+ const c = me(e, s ? a.map((l) => s.get(l)) : a);
657
707
  i.sources = s ? new Map(a.map((l) => [l, c.get(s.get(l))])) : c;
658
708
  }
659
709
  return r.prepared.set(e, i), i;
660
710
  }
661
- function en(e, t, r, n) {
711
+ function bn(e, t, r, n) {
662
712
  if (!n.flow) return;
663
- const { current: o, templatePage: a } = n, s = Math.max(o.marginTopMm, Y(a)), i = Math.max(n.startTop ?? e.topMm, s), c = (e.header === !1 ? 0 : t.headerHeightMm) + (r[0] ? Q(t, r[0], n.measurer).heightMm : 0);
664
- i + c <= se(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, Y(a)));
713
+ const { current: o, templatePage: a } = n, s = Math.max(o.marginTopMm, X(a)), i = Math.max(n.startTop ?? e.topMm, s), c = (e.header === !1 ? 0 : t.headerHeightMm) + (r[0] ? Y(t, r[0], n.measurer).heightMm : 0);
714
+ i + c <= ie(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, X(a)));
665
715
  }
666
- function* tn(e, t, r) {
667
- const n = pt(e, t, r), o = n.rows;
716
+ function* vn(e, t, r) {
717
+ const n = St(e, t, r), o = n.rows;
668
718
  e = n.list, e.layout === "wide" && (r.current.widthMm = Math.max(r.current.widthMm, e.leftMm + e.widthMm + r.current.marginRightMm));
669
- const a = n.sources ?? le(e, o), s = Ke(e), i = de(s), c = { ...je(s, r.measurer, o, r.signal), rowHeightFloorMm: s.rowHeightMm ?? 0, matrix: n.matrix, ...n.treeRows ? { tree: { list: s, rows: n.treeRows } } : {} };
670
- en(s, c, o, r);
671
- const l = Jr(s, c, r), d = Xr(s, o, r), f = Lr((m, g) => ie(c, r.measurer, m, /* @__PURE__ */ new Map(), g ?? {}, s.columns.length));
672
- let u;
673
- for (const m of ut(o, i)) {
674
- if (K(r.signal), m.kind === "row")
675
- l.placeGridRow(u ?? Q(c, m.row, r.measurer), "listr", wr(n.matrix, m.row), a.get(m.row)), u = void 0, yield* r.takePages(), yield* Yr(s, m.row, d, r, l);
719
+ const a = n.sources ?? me(e, o), s = De(e), i = he(s), c = { ...Le(s, r.measurer, o, r.signal), rowHeightFloorMm: s.rowHeightMm ?? 0, matrix: n.matrix, ...n.treeRows ? { tree: { list: s, rows: n.treeRows } } : {} };
720
+ bn(s, c, o, r);
721
+ const l = fn(s, c, r), u = gn(s, o, r), f = rn((m, h) => ce(c, r.measurer, m, /* @__PURE__ */ new Map(), h ?? {}, s.columns.length));
722
+ let d;
723
+ for (const m of wt(o, i)) {
724
+ if (N(r.signal), m.kind === "row")
725
+ l.placeGridRow(d ?? Y(c, m.row, r.measurer), "listr", jr(n.matrix, m.row), a.get(m.row)), d = void 0, yield* r.takePages(), yield* pn(s, m.row, u, r, l);
676
726
  else if (m.kind === "groupHeader") {
677
- const g = f(m.depth, m.firstRow, m.label, m.group.headerStyle);
727
+ const h = f(m.depth, m.firstRow, m.label, m.group.headerStyle);
678
728
  if (m.group.keepWithNext !== !1) {
679
- u ??= Q(c, m.firstRow, r.measurer);
680
- let b = 0;
681
- for (let y = m.depth + 1; y < i.length; y++) {
682
- const p = i[y], h = (p.headerTemplate ?? "{value}").replace(/\{value\}/g, $e(m.firstRow[p.field]));
683
- b += f(y, m.firstRow, h, p.headerStyle).heightMm;
729
+ d ??= Y(c, m.firstRow, r.measurer);
730
+ let y = 0;
731
+ for (let w = m.depth + 1; w < i.length; w++) {
732
+ const p = i[w], g = (p.headerTemplate ?? "{value}").replace(/\{value\}/g, Ae(m.firstRow[p.field]));
733
+ y += f(w, m.firstRow, g, p.headerStyle).heightMm;
684
734
  }
685
- l.keepTogether(g.heightMm + b + u.heightMm);
735
+ l.keepTogether(h.heightMm + y + d.heightMm);
686
736
  }
687
- l.placeGridRow(g, "listg", "group-header"), m.group.repeatHeader && l.setGroupHeader(m.depth, g);
737
+ l.placeGridRow(h, "listg", "group-header"), m.group.repeatHeader && l.setGroupHeader(m.depth, h);
688
738
  } else if (m.kind === "subtotal") {
689
- const g = m.group.subtotal ?? [], b = m.group.aggregates ?? [], y = ie(c, r.measurer, m.label, ft(s.columns, m.rows, g, b), m.group.subtotalStyle ?? {}, mt(s.columns, [...g, ...b.map((p) => p.field)]));
690
- l.placeGridRow(y, "listst", "subtotal");
739
+ const h = m.group.subtotal ?? [], y = m.group.aggregates ?? [], w = ce(c, r.measurer, m.label, yt(s.columns, m.rows, h, y), m.group.subtotalStyle ?? {}, bt(s.columns, [...h, ...y.map((p) => p.field)]));
740
+ l.placeGridRow(w, "listst", "subtotal");
691
741
  } else l.setGroupHeader(m.depth);
692
742
  yield* r.takePages();
693
743
  }
694
- qr(s, n.totalRows ?? o, c, r, l), r.finished?.(l.bottom()), yield* r.takePages();
744
+ hn(s, n.totalRows ?? o, c, r, l), r.finished?.(l.bottom()), yield* r.takePages();
695
745
  }
696
- function ue(e) {
746
+ function ge(e) {
697
747
  return e.kind !== "list" && (e.pageAnchor !== void 0 || e.kind === "text" && typeof e.text == "string" && (e.text.includes("{page}") || e.text.includes("{totalPages}")));
698
748
  }
699
- function fe(e, t) {
749
+ function pe(e, t) {
700
750
  return {
701
751
  ...e,
702
752
  ...e.text === void 0 ? {} : { text: t(e.text) },
703
753
  ...e.lines ? { lines: e.lines.map(t) } : {},
704
754
  ...e.richParagraphs ? { richParagraphs: e.richParagraphs.map((r) => ({ ...r, segments: r.segments.map((n) => ({ ...n, ...n.text === void 0 ? {} : { text: t(n.text) } })) })) } : {},
705
- ...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) => fe(o, t)) } : {} } : null)) } } : {}
755
+ ...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) => pe(o, t)) } : {} } : null)) } } : {}
706
756
  };
707
757
  }
708
- function rn(e) {
758
+ function Mn(e) {
709
759
  let t = !1;
710
- for (const r of e.pages) for (const n of r.components) ue(n) && fe(n, (o) => (o.includes("{totalPages}") && (t = !0), o));
760
+ for (const r of e.pages) for (const n of r.components) ge(n) && pe(n, (o) => (o.includes("{totalPages}") && (t = !0), o));
711
761
  return t;
712
762
  }
713
- function nn(e, t, r, n, o, a) {
763
+ function Sn(e, t, r, n, o, a) {
714
764
  const s = {
715
765
  pageWidthMm: t.widthMm,
716
766
  pageHeightMm: t.heightMm,
@@ -725,38 +775,38 @@ function nn(e, t, r, n, o, a) {
725
775
  const l = c.replace(/\{page\}/g, String(n));
726
776
  return a === void 0 ? l : l.replace(/\{totalPages\}/g, String(a));
727
777
  };
728
- for (const c of r) s.components.push(fe(c, i));
778
+ for (const c of r) s.components.push(pe(c, i));
729
779
  if (e.layout === "wide") {
730
- const c = s.components.reduce((l, d) => Math.max(l, d.topMm + d.heightMm), 0);
780
+ const c = s.components.reduce((l, u) => Math.max(l, u.topMm + u.heightMm), 0);
731
781
  s.marginBottomMm = o ? e.marginBottomMm ?? 0 : 0, s.pageHeightMm = Math.max(1, c + s.marginBottomMm);
732
782
  }
733
783
  return s;
734
784
  }
735
- function Ne(e) {
736
- return e.cells.reduce((t, r) => t + r.reduce((n, o) => n + (o ? 1 + (o.children?.reduce((a, s) => a + wt(s), 0) ?? 0) : 0), 0), 0);
785
+ function He(e) {
786
+ return e.cells.reduce((t, r) => t + r.reduce((n, o) => n + (o ? 1 + (o.children?.reduce((a, s) => a + xt(s), 0) ?? 0) : 0), 0), 0);
737
787
  }
738
- function wt(e) {
739
- return e.grid ? Ne(e.grid) : 0;
788
+ function xt(e) {
789
+ return e.grid ? He(e.grid) : 0;
740
790
  }
741
- function me(e) {
791
+ function we(e) {
742
792
  for (const t of ["maxPages", "maxCells", "knownTotalPages"]) if (e[t] !== void 0 && (!Number.isSafeInteger(e[t]) || e[t] < 1)) throw new RangeError(`${t} 应为正安全整数`);
743
- Ie(e.maxChartComponents);
793
+ Fe(e.maxChartComponents);
744
794
  }
745
- function on(e, t) {
746
- const r = pt(e, t.datasets[e.dataset] ?? [], t), n = Ke(r.list), o = { ...je(n, t.measurer, r.rows, t.signal), rowHeightFloorMm: n.rowHeightMm ?? 0 };
747
- return (n.header === !1 ? 0 : o.headerHeightMm) + r.rows.reduce((a, s) => a + Q(o, s, t.measurer).heightMm, 0);
795
+ function xn(e, t) {
796
+ const r = St(e, t.datasets[e.dataset] ?? [], t), n = De(r.list), o = { ...Le(n, t.measurer, r.rows, t.signal), rowHeightFloorMm: n.rowHeightMm ?? 0 };
797
+ return (n.header === !1 ? 0 : o.headerHeightMm) + r.rows.reduce((a, s) => a + Y(o, s, t.measurer).heightMm, 0);
748
798
  }
749
- function* an(e) {
799
+ function* Pn(e) {
750
800
  const { templatePage: t, current: r } = e, n = new Map(t.components.map((a, s) => [a, s])), o = (a, s, i) => {
751
801
  const c = e.datasets[a.dataset];
752
- return Array.isArray(c) || e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id ?? ""} 输出为空`), tn(a, Array.isArray(c) ? c : [], { ...e, tableId: `${e.tableId}:${n.get(a)}`, startTop: s, finished: i, flow: !!t.flow });
802
+ return Array.isArray(c) || e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id ?? ""} 输出为空`), vn(a, Array.isArray(c) ? c : [], { ...e, tableId: `${e.tableId}:${n.get(a)}`, startTop: s, finished: i, flow: !!t.flow });
753
803
  };
754
804
  if (t.flow) {
755
- yield* xr({
805
+ yield* Br({
756
806
  page: t,
757
- active: () => K(e.signal),
758
- top: () => Math.max(r.marginTopMm, Y(t)),
759
- bottom: () => se(t, r),
807
+ active: () => N(e.signal),
808
+ top: () => Math.max(r.marginTopMm, X(t)),
809
+ bottom: () => ie(t, r),
760
810
  append: (a) => {
761
811
  r.components.push(...e.resolveChart(a));
762
812
  },
@@ -764,173 +814,171 @@ function* an(e) {
764
814
  e.pushCurrent(), r.components = [], r.heightMm = t.heightMm, t.layout === "wide" && (r.marginTopMm = 0, r.marginBottomMm = 0);
765
815
  },
766
816
  takePages: e.takePages,
767
- height: (a) => on(a, e),
817
+ height: (a) => xn(a, e),
768
818
  list: o
769
819
  });
770
820
  return;
771
821
  }
772
822
  for (const a of t.components)
773
- ue(a) || (a.kind === "list" ? yield* o(a) : r.components.push(...e.resolveChart(a)));
823
+ ge(a) || (a.kind === "list" ? yield* o(a) : r.components.push(...e.resolveChart(a)));
774
824
  }
775
- function* Z(e, t, r, n, o, a = /* @__PURE__ */ new WeakMap(), s) {
825
+ function* Q(e, t, r, n, o, a = /* @__PURE__ */ new WeakMap(), s) {
776
826
  let i = 0, c = 0, l = 0;
777
- const d = pr(r.measurer ?? oe), f = Qt(t, r.signal, r.maxChartComponents), u = (m) => `${m}_${(++i).toString(36)}`;
778
- for (const { pageIndex: m, page: g } of Fr(e, t, r)) {
779
- K(r.signal);
780
- const b = Hr(g), y = g.components.filter(ue);
827
+ const u = Or(r.measurer ?? ne), f = ur(t, r.signal, r.maxChartComponents), d = (m) => `${m}_${(++i).toString(36)}`;
828
+ for (const { pageIndex: m, page: h } of Yr(e, t, r)) {
829
+ N(r.signal);
830
+ const y = nn(h), w = h.components.filter(ge);
781
831
  let p = [];
782
- const h = (T = !1) => {
783
- if (K(r.signal), r.maxPages !== void 0 && c >= r.maxPages) throw new X(r.maxPages, c + 1);
784
- if (r.maxCells !== void 0 && (l += [...b.components, ...y].reduce((R, O) => R + wt(O), 0), l > r.maxCells))
785
- throw new ae(r.maxCells, l);
786
- p.push(nn(g, b, y, ++c, T, o));
832
+ const g = (R = !1) => {
833
+ if (N(r.signal), r.maxPages !== void 0 && c >= r.maxPages) throw new V(r.maxPages, c + 1);
834
+ if (r.maxCells !== void 0 && (l += [...y.components, ...w].reduce((E, I) => E + xt(I), 0), l > r.maxCells))
835
+ throw new oe(r.maxCells, l);
836
+ p.push(Sn(h, y, w, ++c, R, o));
787
837
  }, S = () => {
788
- const T = p;
789
- return p = [], T;
838
+ const R = p;
839
+ return p = [], R;
790
840
  };
791
- yield* an({
792
- templatePage: g,
793
- current: b,
841
+ yield* Pn({
842
+ templatePage: h,
843
+ current: y,
794
844
  warnings: n,
795
- nextId: u,
796
- pushCurrent: h,
845
+ nextId: d,
846
+ pushCurrent: g,
797
847
  takePages: S,
798
848
  datasets: t,
799
849
  resolveChart: f,
800
850
  signal: r.signal,
801
851
  formula: r.formula,
802
852
  prepared: a,
803
- measurer: d,
853
+ measurer: u,
804
854
  mmPerRow: r.mmPerRow ?? 0,
805
855
  tableId: `table:${m}`
806
- }), h(!0), yield* S();
856
+ }), g(!0), yield* S();
807
857
  }
808
858
  s && (s.chartComponents = f.used());
809
859
  }
810
- function $o(e, t, r = {}) {
811
- me(r);
860
+ function ra(e, t, r = {}) {
861
+ we(r);
812
862
  let n = 0;
813
- for (const o of Z(e, t, { ...r, onWarning: void 0 }, [])) n++;
863
+ for (const o of Q(e, t, { ...r, onWarning: void 0 }, [])) n++;
814
864
  return n;
815
865
  }
816
- function* Oo(e, t, r = {}) {
817
- yield* sn(e, t, r);
866
+ function* na(e, t, r = {}) {
867
+ yield* kn(e, t, r);
818
868
  }
819
- function* sn(e, t, r, n) {
820
- me(r);
821
- const o = rn(e), a = /* @__PURE__ */ new WeakMap();
869
+ function* kn(e, t, r, n) {
870
+ we(r);
871
+ const o = Mn(e), a = /* @__PURE__ */ new WeakMap();
822
872
  let s = r.knownTotalPages;
823
873
  if (o && s === void 0) {
824
874
  s = 0;
825
- for (const l of Z(e, t, r, [], void 0, a)) s++;
875
+ for (const l of Q(e, t, r, [], void 0, a)) s++;
826
876
  }
827
877
  const i = [];
828
878
  let c = 0;
829
- for (const l of Z(e, t, r, i, s, a, n)) {
879
+ for (const l of Q(e, t, r, i, s, a, n)) {
830
880
  for (; c < i.length; c++) r.onWarning?.(i[c]);
831
881
  yield l;
832
882
  }
833
883
  }
834
- function yt(e, t, r = {}) {
884
+ function Pt(e, t, r = {}) {
835
885
  const n = typeof r == "number" ? { mmPerRow: r } : r;
836
- me(n);
837
- const o = [], a = { chartComponents: 0 }, s = [...Z(e, t, n, o, n.knownTotalPages, void 0, a)];
838
- return vt(e, n, s, o, a);
886
+ we(n);
887
+ const o = [], a = { chartComponents: 0 }, s = [...Q(e, t, n, o, n.knownTotalPages, void 0, a)];
888
+ return Ct(e, n, s, o, a);
839
889
  }
840
- async function bt(e, t, r = {}) {
841
- me(r), K(r.signal);
890
+ async function kt(e, t, r = {}) {
891
+ we(r), N(r.signal);
842
892
  const n = [], o = [], a = { chartComponents: 0 };
843
893
  let s = performance.now(), i = 0;
844
- for (const c of Z(e, t, r, n, r.knownTotalPages, void 0, a))
845
- o.push(c), (++i >= 8 || performance.now() - s >= 8) && (await new Promise((l) => setTimeout(l, 0)), K(r.signal), s = performance.now(), i = 0);
846
- return K(r.signal), vt(e, r, o, n, a);
894
+ for (const c of Q(e, t, r, n, r.knownTotalPages, void 0, a))
895
+ o.push(c), (++i >= 8 || performance.now() - s >= 8) && (await new Promise((l) => setTimeout(l, 0)), N(r.signal), s = performance.now(), i = 0);
896
+ return N(r.signal), Ct(e, r, o, n, a);
847
897
  }
848
- function vt(e, t, r, n, o) {
849
- for (const a of r) a.components = a.components.map((s) => ue(s) ? fe(s, (i) => i.replace(/\{totalPages\}/g, String(r.length))) : s);
850
- return n.forEach((a) => t.onWarning?.(a)), { plan: { schemaVersion: Ce, ...Fe(e) ? { requiresRecalculation: !0 } : {}, pages: r }, warnings: n, ...o };
898
+ function Ct(e, t, r, n, o) {
899
+ for (const a of r) a.components = a.components.map((s) => ge(s) ? pe(s, (i) => i.replace(/\{totalPages\}/g, String(r.length))) : s);
900
+ return n.forEach((a) => t.onWarning?.(a)), { plan: { schemaVersion: Oe, ...Ke(e) ? { requiresRecalculation: !0 } : {}, pages: r }, warnings: n, ...o };
851
901
  }
852
- function cn(e) {
902
+ function Cn(e) {
853
903
  const t = e.columns.find((a) => !a.hidden)?.field;
854
904
  if (!t) return { groups: 0, total: 0 };
855
- const r = de(e), n = (a = [], s = []) => a.includes(t) || s.some((i) => i.field === t), o = typeof e.grandTotal == "object" ? e.grandTotal : void 0;
905
+ const r = he(e), n = (a = [], s = []) => a.includes(t) || s.some((i) => i.field === t), o = typeof e.grandTotal == "object" ? e.grandTotal : void 0;
856
906
  return { groups: r.filter((a) => n(a.subtotal, a.aggregates)).length, total: Number(n(o?.fields ?? r[0]?.subtotal, o?.aggregates ?? r[0]?.aggregates)) };
857
907
  }
858
- function ln(e, t, r) {
859
- ht(e);
860
- const n = nt(t[e.dataset] ?? [], e.tree, r), o = e.columns.filter((s) => !s.hidden).length, a = e.header === !1 ? 0 : e.headerGrid ? Ne(e.headerGrid) : o;
908
+ function Tn(e, t, r) {
909
+ Mt(e);
910
+ const n = ct(t[e.dataset] ?? [], e.tree, r), o = e.columns.filter((s) => !s.hidden).length, a = e.header === !1 ? 0 : e.headerGrid ? He(e.headerGrid) : o;
861
911
  return n.length * o + a + +!!e.grandTotal * 2 * o;
862
912
  }
863
- function Fo(e, t, r = {}) {
864
- if (e.tree) return ln(e, t, r.signal);
913
+ function oa(e, t, r = {}) {
914
+ if (e.tree) return Tn(e, t, r.signal);
865
915
  if (e.matrix) {
866
- let c = t[e.dataset] ?? [];
867
- e.computed?.length && (c = Re(c, { fields: e.computed, ...r }).rows), e.rowVisibleWhen && (c = c.filter(W(e.rowVisibleWhen)));
868
- const l = nr(c, e.matrix);
916
+ const { rows: c } = dt(e, t[e.dataset] ?? [], t, r), l = gr(c, e.matrix);
869
917
  return l.cells + (e.header === !1 ? 0 : l.columnCount * (e.matrix.hierarchy ? e.matrix.columnFields.length + 1 : 1));
870
918
  }
871
- const n = t[e.dataset]?.length ?? 0, o = e.columns.filter((c) => !c.hidden).length, a = de(e).length, s = cn(e);
919
+ const n = t[e.dataset]?.length ?? 0, o = e.columns.filter((c) => !c.hidden).length, a = he(e).length, s = Cn(e);
872
920
  let i = (n * (1 + 2 * a + s.groups) + +!!e.grandTotal * (1 + s.total)) * o;
873
- if (i += e.header === !1 ? 0 : e.headerGrid ? Ne(e.headerGrid) : o, e.cardinality === "record" && n === 0 && (i += o), e.detail) {
874
- const c = t[e.detail.dataset]?.length ?? 0, l = e.detail.columns.filter((d) => !d.hidden).length;
921
+ if (i += e.header === !1 ? 0 : e.headerGrid ? He(e.headerGrid) : o, e.cardinality === "record" && n === 0 && (i += o), e.detail) {
922
+ const c = t[e.detail.dataset]?.length ?? 0, l = e.detail.columns.filter((u) => !u.hidden).length;
875
923
  i += (c + n * (+(e.detail.header !== !1) + +!!e.detail.label)) * l;
876
924
  }
877
925
  if (!Number.isSafeInteger(i)) throw new RangeError("报表单元格估算超出安全整数预算");
878
926
  return i;
879
927
  }
880
- class dn extends Error {
928
+ class Rn extends Error {
881
929
  constructor(t) {
882
930
  super(t.map((r) => r.message).join(";")), this.issues = t, this.name = "ReportValidationError";
883
931
  }
884
932
  }
885
- function Je(e, t, r) {
933
+ function Ye(e, t, r) {
886
934
  if (!Number.isSafeInteger(e) || e < 1 || e > r) throw new Error(`校验 ${t} 超出预算`);
887
935
  return e;
888
936
  }
889
- function un(e) {
937
+ function En(e) {
890
938
  if (e.aggregates && e.scope !== "dataset") throw new Error("仅数据集规则允许汇总");
891
939
  if (e.aggregates && (!Array.isArray(e.aggregates) || e.aggregates.length > 64)) throw new Error("校验汇总最多 64 项");
892
940
  const t = /* @__PURE__ */ new Set();
893
941
  for (const r of e.aggregates ?? []) {
894
- if (H(r.field), t.has(r.field)) throw new Error("校验汇总字段重复");
895
- t.add(r.field), r.valueField !== void 0 && H(r.valueField), r.weightField !== void 0 && H(r.weightField), Ee([], { ...r, field: r.valueField ?? r.field });
942
+ if (D(r.field), t.has(r.field)) throw new Error("校验汇总字段重复");
943
+ t.add(r.field), r.valueField !== void 0 && D(r.valueField), r.weightField !== void 0 && D(r.weightField), Ie([], { ...r, field: r.valueField ?? r.field });
896
944
  }
897
945
  }
898
- function Mt(e) {
946
+ function Tt(e) {
899
947
  if (!Array.isArray(e) || e.length > 256 || Object.keys(e).length !== e.length) throw new Error("校验规则最多 256 条且不允许空位");
900
948
  const t = /* @__PURE__ */ new Set();
901
949
  return e.map((r) => {
902
950
  if (!r || typeof r != "object") throw new Error("校验规则应为声明式对象");
903
- if (H(r.id), t.has(r.id)) throw new Error("校验规则 id 重复");
904
- if (t.add(r.id), r.field !== void 0 && H(r.field), r.dataset !== void 0 && H(r.dataset), typeof r.message != "string" || !r.message.trim() || r.message.length > 2048) throw new Error("校验规则需要有界提示文案");
951
+ if (D(r.id), t.has(r.id)) throw new Error("校验规则 id 重复");
952
+ if (t.add(r.id), r.field !== void 0 && D(r.field), r.dataset !== void 0 && D(r.dataset), typeof r.message != "string" || !r.message.trim() || r.message.length > 2048) throw new Error("校验规则需要有界提示文案");
905
953
  if (r.severity !== void 0 && !["error", "warning"].includes(r.severity)) throw new Error("未知校验严重程度");
906
954
  if (r.scope !== void 0 && !["row", "dataset"].includes(r.scope)) throw new Error("未知校验范围");
907
- un(r);
908
- const n = { nodes: 0 }, o = W(r.assert, n), a = r.when ? W(r.when, n) : void 0;
955
+ En(r);
956
+ const n = { nodes: 0 }, o = G(r.assert, n), a = r.when ? G(r.when, n) : void 0;
909
957
  return { rule: r, assert: o, when: a, checks: n.nodes };
910
958
  });
911
959
  }
912
- function Ue(e) {
960
+ function Qe(e) {
913
961
  if (e?.aborted) {
914
962
  const t = new Error("报表校验已取消");
915
963
  throw t.name = "AbortError", t;
916
964
  }
917
965
  }
918
- function fn(e, t, r, n) {
966
+ function On(e, t, r, n) {
919
967
  const o = n && Object.prototype.hasOwnProperty.call(t, n) ? t[n] : void 0;
920
968
  if (o !== void 0 && typeof o != "string" && !(typeof o == "number" && Number.isFinite(o))) throw new Error("校验定位需要稳定的文本或数值业务键");
921
969
  return { ruleId: e.id, rowIndex: r, ...o === void 0 ? {} : { rowKey: o }, field: e.field, severity: e.severity ?? "error", message: e.message };
922
970
  }
923
- function mn(e, t) {
971
+ function $n(e, t) {
924
972
  const r = t.computed?.length ? { fields: t.computed, formula: t.formula, signal: t.signal } : void 0;
925
973
  if (t.tree) {
926
- const o = ot(e, t.tree, { signal: t.signal, computed: r });
974
+ const o = lt(e, t.tree, { signal: t.signal, computed: r });
927
975
  if (o.rows.length > 1e5) throw new Error("校验展开后数据最多 100000 行");
928
976
  return { rows: o.rows, summaryRows: o.leaves, rowKey: t.tree.idField };
929
977
  }
930
- const n = r ? Re(e, r).rows : e;
978
+ const n = r ? rt(e, r).rows : e;
931
979
  return { rows: n, summaryRows: n, rowKey: t.rowKey };
932
980
  }
933
- function gn(e, t) {
981
+ function In(e, t) {
934
982
  const r = /* @__PURE__ */ new Set();
935
983
  e.forEach((n) => {
936
984
  if (!n || typeof n != "object" || Array.isArray(n)) throw new Error("校验数据行应为对象");
@@ -941,49 +989,49 @@ function gn(e, t) {
941
989
  r.add(o);
942
990
  });
943
991
  }
944
- function Ao(e, t) {
945
- return St(e, t, { checks: 0 });
992
+ function aa(e, t) {
993
+ return Rt(e, t, { checks: 0 });
946
994
  }
947
- function St(e, t, r) {
995
+ function Rt(e, t, r) {
948
996
  if (!Array.isArray(e) || e.length > 1e5) throw new Error("校验数据最多 100000 行");
949
- Ue(t.signal);
950
- const n = Je(t.maxChecks ?? 2e6, "maxChecks", 1e7), o = Je(t.maxIssues ?? 1e3, "maxIssues", 1e4);
951
- t.rowKey !== void 0 && H(t.rowKey);
952
- const a = mn(e, t), { rows: s, summaryRows: i, rowKey: c } = a;
953
- gn(s, c);
954
- const l = Mt(t.rules), d = l.reduce((u, m) => u + (m.rule.scope === "dataset" ? m.checks + i.length * (m.rule.aggregates?.length ?? 0) : s.length * m.checks), 0);
955
- if (r.checks += d, r.checks > n) throw new Error("整批校验超出 maxChecks 预算");
997
+ Qe(t.signal);
998
+ const n = Ye(t.maxChecks ?? 2e6, "maxChecks", 1e7), o = Ye(t.maxIssues ?? 1e3, "maxIssues", 1e4);
999
+ t.rowKey !== void 0 && D(t.rowKey);
1000
+ const a = $n(e, t), { rows: s, summaryRows: i, rowKey: c } = a;
1001
+ In(s, c);
1002
+ const l = Tt(t.rules), u = l.reduce((d, m) => d + (m.rule.scope === "dataset" ? m.checks + i.length * (m.rule.aggregates?.length ?? 0) : s.length * m.checks), 0);
1003
+ if (r.checks += u, r.checks > n) throw new Error("整批校验超出 maxChecks 预算");
956
1004
  const f = [];
957
- for (const u of l)
958
- (u.rule.scope === "dataset" ? [Object.fromEntries((u.rule.aggregates ?? []).map((g) => [g.field, Ee(i, { ...g, field: g.valueField ?? g.field })]))] : s).forEach((g, b) => {
959
- if (Ue(t.signal), !g || typeof g != "object" || Array.isArray(g)) throw new Error("校验数据行应为对象");
960
- if (!(u.when && !u.when(g) || u.assert(g))) {
1005
+ for (const d of l)
1006
+ (d.rule.scope === "dataset" ? [Object.fromEntries((d.rule.aggregates ?? []).map((h) => [h.field, Ie(i, { ...h, field: h.valueField ?? h.field })]))] : s).forEach((h, y) => {
1007
+ if (Qe(t.signal), !h || typeof h != "object" || Array.isArray(h)) throw new Error("校验数据行应为对象");
1008
+ if (!(d.when && !d.when(h) || d.assert(h))) {
961
1009
  if (f.length >= o) throw new Error("校验问题超出 maxIssues 预算,请缩小范围");
962
- f.push(fn(u.rule, g, u.rule.scope === "dataset" ? void 0 : b, u.rule.scope === "dataset" ? void 0 : c));
1010
+ f.push(On(d.rule, h, d.rule.scope === "dataset" ? void 0 : y, d.rule.scope === "dataset" ? void 0 : c));
963
1011
  }
964
1012
  });
965
1013
  return f;
966
1014
  }
967
- function hn(e, t = "allow") {
1015
+ function Fn(e, t = "allow") {
968
1016
  if (!["allow", "block"].includes(t)) throw new Error("未知校验警告策略");
969
1017
  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("校验问题结构无效");
970
- if (e.some((r) => r.severity === "error" || t === "block")) throw new dn(e);
1018
+ if (e.some((r) => r.severity === "error" || t === "block")) throw new Rn(e);
971
1019
  }
972
- function qe(e, t, r) {
1020
+ function Ze(e, t, r) {
973
1021
  const n = e.get(t);
974
1022
  if (n && JSON.stringify(n) !== JSON.stringify(r)) throw new Error("同一数据集的校验计算/业务键存在歧义,请统一绑定");
975
1023
  e.set(t, r);
976
1024
  }
977
- function pn(e, t, r, n = []) {
978
- Mt(t.rules);
1025
+ function An(e, t, r, n = []) {
1026
+ Tt(t.rules);
979
1027
  const o = [], a = { checks: 0 };
980
1028
  for (const [i, c] of e.entries()) {
981
1029
  const l = /* @__PURE__ */ new Map();
982
- for (const d of c.template.pages) for (const f of d.components)
983
- f.kind === "list" && (qe(l, f.dataset, { rowKey: f.tree?.idField ?? f.rowKey, computed: f.computed, tree: f.tree }), f.detail && qe(l, f.detail.dataset, { rowKey: f.detail.rowKey }));
984
- for (const [d, f] of l) {
985
- const u = t.rules.filter((m) => !m.dataset || m.dataset === d);
986
- if (u.length && (o.push(...St(c.datasets[d] ?? [], { ...t, rules: u, ...f, formula: n[i], signal: r }, a).map((m) => ({ ...m, dataset: d, sourceScope: c.sourceScope }))), o.length > (t.maxIssues ?? 1e3)))
1030
+ for (const u of c.template.pages) for (const f of u.components)
1031
+ f.kind === "list" && (Ze(l, f.dataset, { rowKey: f.tree?.idField ?? f.rowKey, computed: f.computed, tree: f.tree }), f.detail && Ze(l, f.detail.dataset, { rowKey: f.detail.rowKey }));
1032
+ for (const [u, f] of l) {
1033
+ const d = t.rules.filter((m) => !m.dataset || m.dataset === u);
1034
+ if (d.length && (o.push(...Rt(c.datasets[u] ?? [], { ...t, rules: d, ...f, formula: n[i], signal: r }, a).map((m) => ({ ...m, dataset: u, sourceScope: c.sourceScope }))), o.length > (t.maxIssues ?? 1e3)))
987
1035
  throw new Error("整批候选校验问题超出 maxIssues 预算");
988
1036
  }
989
1037
  }
@@ -991,10 +1039,10 @@ function pn(e, t, r, n = []) {
991
1039
  if (t.rules.some((i) => i.dataset && !s.has(i.dataset))) throw new Error("校验目标数据集不存在");
992
1040
  return o;
993
1041
  }
994
- function xt(e) {
1042
+ function Et(e) {
995
1043
  return !e || typeof e != "object" ? !1 : [e.pageIndex, e.componentIndex, e.rowIndex, e.columnIndex].every((t) => Number.isInteger(t) && t >= 0);
996
1044
  }
997
- function Pt(e, t, r) {
1045
+ function Ot(e, t, r) {
998
1046
  const n = e.grid;
999
1047
  if (!n) return null;
1000
1048
  const o = n.cells[t];
@@ -1002,20 +1050,20 @@ function Pt(e, t, r) {
1002
1050
  const s = q(n, e.widthMm, e.heightMm).cells.filter((c) => c.ri === t).findIndex((c) => c.ci === r), i = o[s];
1003
1051
  return i ? { cell: i, sourceColumnIndex: s } : null;
1004
1052
  }
1005
- function wn(e) {
1053
+ function jn(e) {
1006
1054
  return e.value !== void 0 ? e.value : e.rawText ?? e.text ?? null;
1007
1055
  }
1008
- function yn(e, t) {
1056
+ function Kn(e, t) {
1009
1057
  return e.valueType ? e.valueType : typeof t == "number" ? "number" : typeof t == "boolean" ? "boolean" : t === null && e.numberFormat && /[0#?]/.test(e.numberFormat) ? "number" : "text";
1010
1058
  }
1011
- function bn(e, t) {
1059
+ function Nn(e, t) {
1012
1060
  if (e.derived) return "derived";
1013
1061
  if (e.editable === !1) return "cell";
1014
1062
  if (e.formula !== void 0) return "formula";
1015
1063
  if (e.children?.length || e.richParagraphs?.length) return "complex";
1016
1064
  if (t.table && t.table.role !== "body" && e.editable !== !0) return "structure";
1017
1065
  }
1018
- function vn(e, t) {
1066
+ function Ln(e, t) {
1019
1067
  const r = e.table;
1020
1068
  if (r)
1021
1069
  return {
@@ -1025,64 +1073,64 @@ function vn(e, t) {
1025
1073
  columnKey: r.columnKeys[t.columnIndex]
1026
1074
  };
1027
1075
  }
1028
- function Mn(e, t, r) {
1076
+ function Dn(e, t, r) {
1029
1077
  if (e.derived) return;
1030
1078
  if (e.source) return { ...e.source };
1031
1079
  const n = t.table?.source, o = t.table?.columnKeys[r.columnIndex];
1032
1080
  if (!(!n || n.rowKey === void 0 || o === void 0))
1033
1081
  return { ...n, rowKey: n.rowKey, field: o };
1034
1082
  }
1035
- function be(e, t, r) {
1036
- const n = wn(r), o = bn(r, e);
1083
+ function ke(e, t, r) {
1084
+ const n = jn(r), o = Nn(r, e);
1037
1085
  return {
1038
1086
  address: { ...t },
1039
1087
  cell: r,
1040
1088
  component: e,
1041
1089
  value: n,
1042
- valueType: yn(r, n),
1043
- table: vn(e, t),
1044
- source: Mn(r, e, t),
1090
+ valueType: Kn(r, n),
1091
+ table: Ln(e, t),
1092
+ source: Dn(r, e, t),
1045
1093
  editable: o === void 0,
1046
1094
  readOnlyReason: o
1047
1095
  };
1048
1096
  }
1049
- function Le(e, t) {
1050
- if (!xt(t)) return null;
1097
+ function Be(e, t) {
1098
+ if (!Et(t)) return null;
1051
1099
  const r = e.pages[t.pageIndex]?.components[t.componentIndex];
1052
1100
  if (!r) return null;
1053
- const n = Pt(r, t.rowIndex, t.columnIndex);
1054
- return n ? be(r, t, n.cell) : null;
1101
+ const n = Ot(r, t.rowIndex, t.columnIndex);
1102
+ return n ? ke(r, t, n.cell) : null;
1055
1103
  }
1056
- function Sn(e, t = !0) {
1104
+ function Hn(e, t = !0) {
1057
1105
  const r = /* @__PURE__ */ new Map();
1058
1106
  function n(i) {
1059
1107
  if (!i.grid) return;
1060
1108
  let c = r.get(i);
1061
1109
  if (!c) {
1062
- const l = q(i.grid, i.widthMm, i.heightMm), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
1063
- for (const u of l.cells) {
1064
- const m = d.get(u.ri) ?? 0;
1065
- d.set(u.ri, m + 1);
1066
- const g = i.grid.cells[u.ri]?.[m];
1067
- g && f.set(`${u.ri}:${u.ci}`, g);
1110
+ const l = q(i.grid, i.widthMm, i.heightMm), u = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
1111
+ for (const d of l.cells) {
1112
+ const m = u.get(d.ri) ?? 0;
1113
+ u.set(d.ri, m + 1);
1114
+ const h = i.grid.cells[d.ri]?.[m];
1115
+ h && f.set(`${d.ri}:${d.ci}`, h);
1068
1116
  }
1069
1117
  c = { layout: t ? l : void 0, cells: f }, r.set(i, c);
1070
1118
  }
1071
1119
  return c;
1072
1120
  }
1073
1121
  function o(i) {
1074
- if (!xt(i)) return null;
1122
+ if (!Et(i)) return null;
1075
1123
  const c = e.pages[i.pageIndex]?.components[i.componentIndex];
1076
1124
  if (!c) return null;
1077
1125
  const l = n(c)?.cells.get(`${i.rowIndex}:${i.columnIndex}`);
1078
- return l ? be(c, i, l) : null;
1126
+ return l ? ke(c, i, l) : null;
1079
1127
  }
1080
1128
  function* a(i, c) {
1081
- const l = e.pages[i]?.components[c], d = l && n(l);
1082
- if (d)
1129
+ const l = e.pages[i]?.components[c], u = l && n(l);
1130
+ if (u)
1083
1131
  for (const f of s(l).cells) {
1084
- const u = d.cells.get(`${f.ri}:${f.ci}`);
1085
- u && (yield be(l, { pageIndex: i, componentIndex: c, rowIndex: f.ri, columnIndex: f.ci }, u));
1132
+ const d = u.cells.get(`${f.ri}:${f.ci}`);
1133
+ d && (yield ke(l, { pageIndex: i, componentIndex: c, rowIndex: f.ri, columnIndex: f.ci }, d));
1086
1134
  }
1087
1135
  }
1088
1136
  function s(i) {
@@ -1092,27 +1140,27 @@ function Sn(e, t = !0) {
1092
1140
  return { resolve: o, entries: a, layout: s };
1093
1141
  }
1094
1142
  function z(e) {
1095
- return Sn(e, !1).resolve;
1143
+ return Hn(e, !1).resolve;
1096
1144
  }
1097
1145
  class v extends Error {
1098
1146
  constructor(t) {
1099
1147
  super(`Invalid report cell edit: ${t}`), this.code = t, this.name = "ReportCellEditError";
1100
1148
  }
1101
1149
  }
1102
- function xn(e, t) {
1150
+ function Bn(e, t) {
1103
1151
  let r = e.trim();
1104
1152
  const n = t && r.endsWith("%");
1105
1153
  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 v("number");
1106
1154
  return Number(r) / (n ? 100 : 1);
1107
1155
  }
1108
- function Pn(e, t) {
1156
+ function Wn(e, t) {
1109
1157
  if (e === null || typeof e == "string" && e.trim() === "") return null;
1110
1158
  if (typeof e != "string" && typeof e != "number") throw new v("number");
1111
- const r = typeof e == "number" ? e : xn(e, mr(t.cell.numberFormat));
1159
+ const r = typeof e == "number" ? e : Bn(e, kr(t.cell.numberFormat));
1112
1160
  if (!Number.isFinite(r) || Number.isInteger(r) && !Number.isSafeInteger(r)) throw new v("number");
1113
1161
  return r;
1114
1162
  }
1115
- function kn(e) {
1163
+ function Gn(e) {
1116
1164
  if (e === null || typeof e == "string" && e.trim() === "") return null;
1117
1165
  if (typeof e == "boolean") return e;
1118
1166
  const t = String(e).trim().toLowerCase();
@@ -1120,24 +1168,24 @@ function kn(e) {
1120
1168
  if (["false", "no", "否", "0"].includes(t)) return !1;
1121
1169
  throw new v("boolean");
1122
1170
  }
1123
- function kt(e, t) {
1124
- return e.valueType === "number" ? Pn(t, e) : e.valueType === "boolean" ? kn(t) : t === null ? null : String(t);
1171
+ function $t(e, t) {
1172
+ return e.valueType === "number" ? Wn(t, e) : e.valueType === "boolean" ? Gn(t) : t === null ? null : String(t);
1125
1173
  }
1126
- function Cn(e, t) {
1174
+ function Vn(e, t) {
1127
1175
  const r = t.cell.text, o = [["是", "否"], ["TRUE", "FALSE"], ["True", "False"], ["true", "false"], ["1", "0"]].find((a) => a.includes(r ?? ""));
1128
1176
  return o ? o[e ? 0 : 1] : String(e);
1129
1177
  }
1130
- function re(e, t) {
1131
- return t === null ? "" : typeof t == "boolean" ? Cn(t, e) : typeof t == "number" ? fr(t, e.cell.numberFormat) : String(t);
1178
+ function te(e, t) {
1179
+ return t === null ? "" : typeof t == "boolean" ? Vn(t, e) : typeof t == "number" ? Pr(t, e.cell.numberFormat) : String(t);
1132
1180
  }
1133
- function jo(e, t, r) {
1134
- const n = Le(e, t);
1181
+ function sa(e, t, r) {
1182
+ const n = Be(e, t);
1135
1183
  if (!n) throw new v("missing");
1136
- return ne(n, r);
1184
+ return re(n, r);
1137
1185
  }
1138
- function ne(e, t) {
1186
+ function re(e, t) {
1139
1187
  if (!e.editable) throw new v("readonly");
1140
- const r = kt(e, t);
1188
+ const r = $t(e, t);
1141
1189
  return {
1142
1190
  address: { ...e.address },
1143
1191
  table: e.table,
@@ -1145,58 +1193,58 @@ function ne(e, t) {
1145
1193
  previousValue: e.value,
1146
1194
  previousText: e.cell.text ?? "",
1147
1195
  value: r,
1148
- text: re(e, r)
1196
+ text: te(e, r)
1149
1197
  };
1150
1198
  }
1151
- function Tn(e, t) {
1199
+ function zn(e, t) {
1152
1200
  const r = e.table, n = t.table;
1153
1201
  return !r || !n || r.columnKey === void 0 ? !1 : r.id === n.id && r.rowIndex === n.rowIndex && r.role === n.role && r.columnKey === n.columnKey;
1154
1202
  }
1155
- function Ct(e, t, r) {
1156
- const n = e.grid, { rowIndex: o, columnIndex: a } = t.address, s = Pt(e, o, a), i = [...n.cells], c = [...i[o]], l = re(t, r.value), d = { ...s.cell, value: r.value, text: l, rawText: l };
1157
- return c[s.sourceColumnIndex] = d, i[o] = c, { ...e, grid: { ...n, cells: i } };
1203
+ function It(e, t, r) {
1204
+ const n = e.grid, { rowIndex: o, columnIndex: a } = t.address, s = Ot(e, o, a), i = [...n.cells], c = [...i[o]], l = te(t, r.value), u = { ...s.cell, value: r.value, text: l, rawText: l };
1205
+ return c[s.sourceColumnIndex] = u, i[o] = c, { ...e, grid: { ...n, cells: i } };
1158
1206
  }
1159
- function Rn(e, t) {
1207
+ function _n(e, t) {
1160
1208
  const r = e.table?.columnKeys, n = t.table?.columnKey;
1161
1209
  return r && n !== void 0 ? r.flatMap((o, a) => o === n ? [a] : []) : [];
1162
1210
  }
1163
- function En(e, t, r, n, o, a) {
1211
+ function Jn(e, t, r, n, o, a) {
1164
1212
  const s = t.table, i = o.table;
1165
1213
  if (!s || !i || s.id !== i.id || s.role !== i.role || !t.grid) return t;
1166
1214
  const c = i.rowIndex - s.rowIndex;
1167
1215
  if (c < 0 || c >= t.grid.cells.length) return t;
1168
1216
  let l = t;
1169
- for (const d of Rn(t, o)) {
1170
- const f = Le(e, { pageIndex: r, componentIndex: n, rowIndex: c, columnIndex: d });
1171
- f?.editable && Tn(o, f) && (l = Ct(l, f, a));
1217
+ for (const u of _n(t, o)) {
1218
+ const f = Be(e, { pageIndex: r, componentIndex: n, rowIndex: c, columnIndex: u });
1219
+ f?.editable && zn(o, f) && (l = It(l, f, a));
1172
1220
  }
1173
1221
  return l;
1174
1222
  }
1175
- function In(e, t, r, n, o, a) {
1223
+ function Un(e, t, r, n, o, a) {
1176
1224
  const s = o.address;
1177
- return o.table?.columnKey !== void 0 ? En(e, t, r, n, o, a) : s.pageIndex === r && s.componentIndex === n ? Ct(t, o, a) : t;
1225
+ return o.table?.columnKey !== void 0 ? Jn(e, t, r, n, o, a) : s.pageIndex === r && s.componentIndex === n ? It(t, o, a) : t;
1178
1226
  }
1179
- function He(e, t) {
1227
+ function We(e, t) {
1180
1228
  const r = t.source;
1181
1229
  if (!r) return !1;
1182
1230
  const n = e.source;
1183
1231
  return !n || ["sourceScope", "datasetId", "rowKey", "field", "revision", "sourceToken"].some((o) => !Object.is(n[o], r[o]));
1184
1232
  }
1185
- function Ko(e, t) {
1186
- const r = Le(e, t.address);
1233
+ function ia(e, t) {
1234
+ const r = Be(e, t.address);
1187
1235
  if (!r) throw new v("missing");
1188
1236
  if (!r.editable) throw new v("readonly");
1189
- if (He(r, t)) throw new v("conflict");
1237
+ if (We(r, t)) throw new v("conflict");
1190
1238
  if (!Object.is(r.value, t.previousValue) || (r.cell.text ?? "") !== t.previousText) throw new v("conflict");
1191
- const n = kt(r, t.value), o = { ...t, value: n, text: re(r, n) };
1239
+ const n = $t(r, t.value), o = { ...t, value: n, text: te(r, n) };
1192
1240
  if (Object.is(n, r.value) && o.text === r.cell.text) return e;
1193
1241
  const a = e.pages.map((s, i) => {
1194
- const c = s.components.map((l, d) => In(e, l, i, d, r, o));
1195
- return c.every((l, d) => l === s.components[d]) ? s : { ...s, components: c };
1242
+ const c = s.components.map((l, u) => Un(e, l, i, u, r, o));
1243
+ return c.every((l, u) => l === s.components[u]) ? s : { ...s, components: c };
1196
1244
  });
1197
1245
  return { ...e, pages: a };
1198
1246
  }
1199
- function Tt(e) {
1247
+ function Ft(e) {
1200
1248
  const t = [];
1201
1249
  for (const r of e.template.pages) for (const n of r.components)
1202
1250
  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] ?? [] } }));
@@ -1205,70 +1253,70 @@ function Tt(e) {
1205
1253
  function _(e) {
1206
1254
  return JSON.stringify([e.sourceScope, e.datasetId]);
1207
1255
  }
1208
- function ce(e) {
1256
+ function le(e) {
1209
1257
  return JSON.stringify([e.sourceScope, e.datasetId, e.rowKey]);
1210
1258
  }
1211
- function Rt(e) {
1259
+ function At(e) {
1212
1260
  const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
1213
1261
  return e.forEach((n, o) => {
1214
- for (const a of Tt(n)) {
1262
+ for (const a of Ft(n)) {
1215
1263
  if (!a.rowKey) continue;
1216
1264
  const s = a.relation, i = s ? new Set(s.parentRows.map((c) => JSON.stringify(c[s.detail.parentKey]))) : void 0;
1217
1265
  (n.datasets[a.dataset] ?? []).forEach((c, l) => {
1218
1266
  if (s && !i.has(JSON.stringify(c[s.detail.foreignKey]))) return;
1219
- const d = c[a.rowKey];
1220
- if (typeof d != "string" && typeof d != "number") return;
1267
+ const u = c[a.rowKey];
1268
+ if (typeof u != "string" && typeof u != "number") return;
1221
1269
  const f = `${o}:${a.dataset}:${l}:${a.rowKey}`;
1222
1270
  if (r.has(f)) return;
1223
1271
  r.add(f);
1224
- const u = ce({ sourceScope: n.sourceScope, datasetId: a.dataset, rowKey: d }), m = t.get(u) ?? [];
1225
- m.push({ partIndex: o, dataset: a.dataset, rowIndex: l, row: c, binding: a }), t.set(u, m);
1272
+ const d = le({ sourceScope: n.sourceScope, datasetId: a.dataset, rowKey: u }), m = t.get(d) ?? [];
1273
+ m.push({ partIndex: o, dataset: a.dataset, rowIndex: l, row: c, binding: a }), t.set(d, m);
1226
1274
  });
1227
1275
  }
1228
1276
  }), (n) => {
1229
- const o = t.get(ce(n));
1277
+ const o = t.get(le(n));
1230
1278
  if (!o?.length) throw new v("missing");
1231
1279
  if (new Set(o.map((a) => `${a.partIndex}:${a.dataset}`)).size !== o.length) throw new v("conflict");
1232
1280
  return o;
1233
1281
  };
1234
1282
  }
1235
- function Et(e, t) {
1283
+ function jt(e, t) {
1236
1284
  const r = e.map((o) => ({ ...o, datasets: { ...o.datasets } })), n = /* @__PURE__ */ new Map();
1237
1285
  for (const { row: o, field: a, value: s } of t) {
1238
1286
  const i = r[o.partIndex], c = JSON.stringify([o.partIndex, o.dataset]);
1239
1287
  let l = n.get(c);
1240
1288
  l || (i.datasets[o.dataset] = [...i.datasets[o.dataset]], n.set(c, l = /* @__PURE__ */ new Set()));
1241
- const d = i.datasets[o.dataset];
1242
- l.has(o.rowIndex) || (d[o.rowIndex] = { ...d[o.rowIndex] }, l.add(o.rowIndex));
1243
- const f = d[o.rowIndex];
1289
+ const u = i.datasets[o.dataset];
1290
+ l.has(o.rowIndex) || (u[o.rowIndex] = { ...u[o.rowIndex] }, l.add(o.rowIndex));
1291
+ const f = u[o.rowIndex];
1244
1292
  Object.prototype.hasOwnProperty.call(f, a) ? f[a] = s : Object.defineProperty(f, a, { value: s, enumerable: !0, writable: !0, configurable: !0 });
1245
1293
  }
1246
1294
  for (const o of n.keys()) {
1247
1295
  const [a, s] = JSON.parse(o);
1248
- Ut(e[a].datasets[s], r[a].datasets[s]);
1296
+ sr(e[a].datasets[s], r[a].datasets[s]);
1249
1297
  }
1250
1298
  return r;
1251
1299
  }
1252
- function $n(e, t, r) {
1300
+ function qn(e, t, r) {
1253
1301
  const n = [], o = /* @__PURE__ */ new Set();
1254
1302
  return e.forEach((a, s) => {
1255
- for (const i of Tt(a))
1303
+ for (const i of Ft(a))
1256
1304
  t.has(_({ sourceScope: a.sourceScope, datasetId: i.dataset })) && (a.datasets[i.dataset] ?? []).forEach((c, l) => {
1257
- const d = { partIndex: s, dataset: i.dataset, rowIndex: l, row: c, binding: i };
1258
- for (const [f, u] of [[i.revisionField, r.revision], [i.sourceTokenField, r.sourceToken]]) {
1259
- if (!f || u === void 0) continue;
1305
+ const u = { partIndex: s, dataset: i.dataset, rowIndex: l, row: c, binding: i };
1306
+ for (const [f, d] of [[i.revisionField, r.revision], [i.sourceTokenField, r.sourceToken]]) {
1307
+ if (!f || d === void 0) continue;
1260
1308
  const m = `${s}:${i.dataset}:${l}:${f}`;
1261
- o.has(m) || (o.add(m), n.push({ row: d, field: f, value: u }));
1309
+ o.has(m) || (o.add(m), n.push({ row: u, field: f, value: d }));
1262
1310
  }
1263
1311
  });
1264
1312
  }), n;
1265
1313
  }
1266
- function On(e, t, r) {
1314
+ function Xn(e, t, r) {
1267
1315
  if (!r || r.revision === void 0 && r.sourceToken === void 0) return e;
1268
1316
  const n = new Set(t.edits.flatMap((o) => o.source ? [_(o.source)] : []));
1269
- return It(e, new Map([...n].map((o) => [o, r])));
1317
+ return Kt(e, new Map([...n].map((o) => [o, r])));
1270
1318
  }
1271
- function It(e, t) {
1319
+ function Kt(e, t) {
1272
1320
  if (!t.size) return e;
1273
1321
  function r(a) {
1274
1322
  const s = a.datasetId && t.get(_({ ...a, datasetId: a.datasetId }));
@@ -1276,14 +1324,14 @@ function It(e, t) {
1276
1324
  }
1277
1325
  function n(a) {
1278
1326
  const s = a.map((i) => {
1279
- 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) => {
1280
- const m = u.map((g) => {
1281
- if (!g) return g;
1282
- const b = g.source ? r(g.source) : void 0, y = g.children ? n(g.children) : void 0;
1283
- return b === g.source && y === g.children ? g : { ...g, source: b, children: y };
1327
+ 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) => {
1328
+ const m = d.map((h) => {
1329
+ if (!h) return h;
1330
+ const y = h.source ? r(h.source) : void 0, w = h.children ? n(h.children) : void 0;
1331
+ return y === h.source && w === h.children ? h : { ...h, source: y, children: w };
1284
1332
  });
1285
- return m.some((g, b) => g !== u[b]) ? m : u;
1286
- }), f = i.grid && d?.some((u, m) => u !== i.grid.cells[m]) ? { ...i.grid, cells: d } : i.grid;
1333
+ return m.some((h, y) => h !== d[y]) ? m : d;
1334
+ }), f = i.grid && u?.some((d, m) => d !== i.grid.cells[m]) ? { ...i.grid, cells: u } : i.grid;
1287
1335
  return l !== i.table || f !== i.grid ? { ...i, table: l, grid: f } : i;
1288
1336
  });
1289
1337
  return s.some((i, c) => i !== a[c]) ? s : a;
@@ -1294,33 +1342,33 @@ function It(e, t) {
1294
1342
  });
1295
1343
  return o.some((a, s) => a !== e.pages[s]) ? { ...e, pages: o } : e;
1296
1344
  }
1297
- function Fn(e) {
1345
+ function Yn(e) {
1298
1346
  return JSON.stringify([e.pageIndex, e.componentIndex, e.rowIndex, e.columnIndex]);
1299
1347
  }
1300
- function Xe(e) {
1348
+ function et(e) {
1301
1349
  const t = e.table;
1302
- return t?.columnKey !== void 0 ? JSON.stringify([t.id, t.role, t.rowIndex, t.columnKey]) : Fn(e.address);
1350
+ return t?.columnKey !== void 0 ? JSON.stringify([t.id, t.role, t.rowIndex, t.columnKey]) : Yn(e.address);
1303
1351
  }
1304
- function An(e, t) {
1352
+ function Qn(e, t) {
1305
1353
  if (!t.length) return e;
1306
- const r = new Map(t.map((c) => [Xe(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 = z(e);
1307
- function s(c, l, d) {
1354
+ const r = new Map(t.map((c) => [et(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 = z(e);
1355
+ function s(c, l, u) {
1308
1356
  const f = c.grid;
1309
- if (!f || !o.has(`${l}:${d}`) && !n.has(c.table?.id ?? "")) return c;
1310
- const u = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
1311
- for (const g of q(f, c.widthMm, c.heightMm).cells) {
1312
- const b = m.get(g.ri) ?? 0;
1313
- m.set(g.ri, b + 1);
1314
- const y = a({ pageIndex: l, componentIndex: d, rowIndex: g.ri, columnIndex: g.ci }), p = y && r.get(Xe(y));
1315
- if (!p || !y.editable) continue;
1316
- const h = u.get(g.ri) ?? [...f.cells[g.ri]], S = re(y, p.value);
1317
- Object.is(y.value, p.value) && S === y.cell.text || (h[b] = { ...g.cell, value: p.value, text: S, rawText: S }, u.set(g.ri, h));
1357
+ if (!f || !o.has(`${l}:${u}`) && !n.has(c.table?.id ?? "")) return c;
1358
+ const d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
1359
+ for (const h of q(f, c.widthMm, c.heightMm).cells) {
1360
+ const y = m.get(h.ri) ?? 0;
1361
+ m.set(h.ri, y + 1);
1362
+ const w = a({ pageIndex: l, componentIndex: u, rowIndex: h.ri, columnIndex: h.ci }), p = w && r.get(et(w));
1363
+ if (!p || !w.editable) continue;
1364
+ const g = d.get(h.ri) ?? [...f.cells[h.ri]], S = te(w, p.value);
1365
+ Object.is(w.value, p.value) && S === w.cell.text || (g[y] = { ...h.cell, value: p.value, text: S, rawText: S }, d.set(h.ri, g));
1318
1366
  }
1319
- return u.size ? { ...c, grid: { ...f, cells: f.cells.map((g, b) => u.get(b) ?? g) } } : c;
1367
+ return d.size ? { ...c, grid: { ...f, cells: f.cells.map((h, y) => d.get(y) ?? h) } } : c;
1320
1368
  }
1321
1369
  const i = e.pages.map((c, l) => {
1322
- const d = c.components.map((f, u) => s(f, l, u));
1323
- return d.every((f, u) => f === c.components[u]) ? c : { ...c, components: d };
1370
+ const u = c.components.map((f, d) => s(f, l, d));
1371
+ return u.every((f, d) => f === c.components[d]) ? c : { ...c, components: u };
1324
1372
  });
1325
1373
  return i.every((c, l) => c === e.pages[l]) ? e : { ...e, pages: i };
1326
1374
  }
@@ -1332,31 +1380,31 @@ function j(e) {
1332
1380
  const n = e.address;
1333
1381
  return JSON.stringify([n.pageIndex, n.componentIndex, n.rowIndex, n.columnIndex]);
1334
1382
  }
1335
- function No(e, t, r) {
1383
+ function ca(e, t, r) {
1336
1384
  if (typeof r != "string" || !r.trim() || !Array.isArray(t)) throw new v("missing");
1337
1385
  if (t.length > 1e4) throw new v("limit");
1338
1386
  const n = /* @__PURE__ */ new Set(), o = z(e), a = t.map(({ address: s, value: i }) => {
1339
1387
  const c = o(s);
1340
1388
  if (!c) throw new v("missing");
1341
- const l = ne(c, i), d = j(l);
1342
- if (n.has(d)) throw new v("duplicate");
1343
- return n.add(d), l;
1389
+ const l = re(c, i), u = j(l);
1390
+ if (n.has(u)) throw new v("duplicate");
1391
+ return n.add(u), l;
1344
1392
  });
1345
1393
  return { requestId: r, edits: a };
1346
1394
  }
1347
- function Lo(e, t) {
1395
+ function la(e, t) {
1348
1396
  if (t.edits.length > 1e4) throw new v("limit");
1349
1397
  const r = z(e), n = /* @__PURE__ */ new Set(), o = t.edits.map((a) => {
1350
1398
  const s = r(a.address);
1351
1399
  if (!s) throw new v("missing");
1352
1400
  const i = j(a);
1353
1401
  if (n.has(i)) throw new v("duplicate");
1354
- if (n.add(i), He(s, a) || !Object.is(s.value, a.previousValue) || (s.cell.text ?? "") !== a.previousText) throw new v("conflict");
1355
- return ne(s, a.value);
1402
+ if (n.add(i), We(s, a) || !Object.is(s.value, a.previousValue) || (s.cell.text ?? "") !== a.previousText) throw new v("conflict");
1403
+ return re(s, a.value);
1356
1404
  });
1357
- return An(e, o);
1405
+ return Qn(e, o);
1358
1406
  }
1359
- function Ho(e) {
1407
+ function ua(e) {
1360
1408
  const t = /* @__PURE__ */ new Map();
1361
1409
  for (const r of e) {
1362
1410
  const n = j(r), o = t.get(n), a = o ? { ...r, previousValue: o.previousValue, previousText: o.previousText } : { ...r };
@@ -1364,7 +1412,7 @@ function Ho(e) {
1364
1412
  }
1365
1413
  return [...t.values()];
1366
1414
  }
1367
- function $t(e) {
1415
+ function Nt(e) {
1368
1416
  const t = /* @__PURE__ */ new Map(), r = z(e);
1369
1417
  return e.pages.forEach((n, o) => n.components.forEach((a, s) => {
1370
1418
  if (!(!a.grid || a.table?.role !== "body"))
@@ -1374,23 +1422,44 @@ function $t(e) {
1374
1422
  }
1375
1423
  })), t;
1376
1424
  }
1377
- function Do(e, t, r) {
1378
- const n = $t(e), o = z(e);
1425
+ function da(e, t, r) {
1426
+ const n = Nt(e), o = z(e);
1379
1427
  return t.map((a) => {
1380
1428
  const s = a.source ? n.get(j(a)) : o(a.address);
1381
1429
  if (!s || j(s) !== j(a)) throw new v("missing");
1382
1430
  return { address: { ...s.address }, value: a[r] };
1383
1431
  });
1384
1432
  }
1385
- function Ot(e, t) {
1433
+ function Zn(e) {
1434
+ return e.stamp.date !== void 0 ? new Date(e.stamp.date) : e.stamp.length !== void 0 ? e.values : Object.fromEntries(e.stamp.keys.map((t, r) => [t, e.values[r]]));
1435
+ }
1436
+ function* eo(e, t) {
1437
+ const r = /* @__PURE__ */ new Map();
1438
+ for (const o of t)
1439
+ r.set(o.object, o), yield;
1440
+ const n = [{ stamp: r.get(e), values: [], index: 0 }];
1441
+ for (; n.length; ) {
1442
+ const o = n[n.length - 1];
1443
+ if (o.index === o.stamp.values.length) {
1444
+ const a = Zn(o);
1445
+ if (n.pop(), !n.length) return a;
1446
+ n[n.length - 1].values.push(a);
1447
+ } else {
1448
+ const a = o.stamp.values[o.index++];
1449
+ a !== null && typeof a == "object" ? n.push({ stamp: r.get(a), values: [], index: 0 }) : o.values.push(a);
1450
+ }
1451
+ yield;
1452
+ }
1453
+ }
1454
+ function Lt(e, t) {
1386
1455
  if (++e.nodes > 1e6 || t > 128) throw new v("limit");
1387
1456
  }
1388
- function ee(e, t) {
1457
+ function ue(e, t) {
1389
1458
  const r = Object.getOwnPropertyDescriptor(e, t);
1390
1459
  if (!r || r.get || r.set) throw new v("conflict");
1391
1460
  return r.value;
1392
1461
  }
1393
- function De(e) {
1462
+ function Dt(e) {
1394
1463
  if (Object.getOwnPropertyDescriptor(e, "toJSON")) throw new v("conflict");
1395
1464
  const t = Object.getPrototypeOf(e);
1396
1465
  if (Array.isArray(e) && (t !== Array.prototype || Object.keys(e).length !== e.length)) throw new v("conflict");
@@ -1401,50 +1470,60 @@ function De(e) {
1401
1470
  if (e instanceof Date || Array.isArray(e) && !/^(0|[1-9]\d*)$/.test(r)) throw new v("conflict");
1402
1471
  }
1403
1472
  }
1404
- function Ft(e, t, r, n, o, a) {
1405
- if (Ot(n, o), typeof e == "function" || typeof e == "symbol") throw new v("conflict");
1473
+ function to(e, t, r) {
1474
+ const n = Object.getPrototypeOf(e);
1475
+ if (t && n !== Array.prototype || !t && !r && n !== Object.prototype && n !== null) throw new v("conflict");
1476
+ return n;
1477
+ }
1478
+ function ro(e) {
1479
+ const t = Array.isArray(e), r = e instanceof Date, n = to(e, t, r), o = [], a = [];
1480
+ for (const s of Reflect.ownKeys(e)) {
1481
+ if (t && s === "length") continue;
1482
+ const i = Object.getOwnPropertyDescriptor(e, s);
1483
+ if (typeof s == "symbol" || s === "toJSON" || r || !i.enumerable || i.get || i.set) throw new v("conflict");
1484
+ if (t && !/^(0|[1-9]\d*)$/.test(s)) throw new v("conflict");
1485
+ o.push(s), a.push(i.value);
1486
+ }
1487
+ if (t && o.length !== e.length) throw new v("conflict");
1488
+ return { object: e, prototype: n, keys: o, values: a, ...r ? { date: Date.prototype.getTime.call(e) } : {}, ...t ? { length: e.length } : {} };
1489
+ }
1490
+ function Ge(e, t, r, n, o, a) {
1491
+ if (Lt(n, o), typeof e == "function" || typeof e == "symbol") throw new v("conflict");
1406
1492
  if (e === null || typeof e != "object") return;
1407
- if (De(e), r.has(e)) throw new v("conflict");
1493
+ if (r.has(e)) throw new v("conflict");
1408
1494
  if (a?.has(e)) return;
1409
1495
  a?.add(e), r.add(e);
1410
- const s = Object.keys(e), i = s.map((c) => ee(e, c));
1411
- t.push({
1412
- object: e,
1413
- prototype: Object.getPrototypeOf(e),
1414
- keys: s,
1415
- values: i,
1416
- ...e instanceof Date ? { date: Date.prototype.getTime.call(e) } : {},
1417
- ...Array.isArray(e) ? { length: e.length } : {}
1418
- });
1419
- for (const c of i) Ft(c, t, r, n, o + 1, a);
1496
+ const s = ro(e);
1497
+ t.push(s);
1498
+ for (const i of s.values) Ge(i, t, r, n, o + 1, a);
1420
1499
  r.delete(e);
1421
1500
  }
1422
- function jn(e) {
1501
+ function no(e) {
1423
1502
  const { object: t, keys: r, values: n } = e;
1424
- if (De(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;
1503
+ if (Dt(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;
1425
1504
  const o = Object.keys(t);
1426
- return o.length === r.length && r.every((a, s) => o[s] === a && Object.is(ee(t, a), n[s]));
1505
+ return o.length === r.length && r.every((a, s) => o[s] === a && Object.is(ue(t, a), n[s]));
1427
1506
  }
1428
- function Kn(e) {
1429
- return At(e);
1507
+ function oo(e) {
1508
+ return Ht(e);
1430
1509
  }
1431
- function ve(e) {
1432
- return At(e, /* @__PURE__ */ new Set());
1510
+ function de(e) {
1511
+ return Ht(e, /* @__PURE__ */ new Set());
1433
1512
  }
1434
- function At(e, t) {
1513
+ function Ht(e, t) {
1435
1514
  const r = [];
1436
- return Ft(e, r, /* @__PURE__ */ new Set(), { nodes: 0 }, 0, t), () => {
1515
+ return Ge(e, r, /* @__PURE__ */ new Set(), { nodes: 0 }, 0, t), () => {
1437
1516
  try {
1438
- return r.every(jn);
1517
+ return r.every(no);
1439
1518
  } catch {
1440
1519
  return !1;
1441
1520
  }
1442
1521
  };
1443
1522
  }
1444
- function V(e, t, r, n = !1, o) {
1445
- if (Ot(t, r), n) {
1523
+ function Z(e, t, r, n = !1, o) {
1524
+ if (Lt(t, r), n) {
1446
1525
  if (typeof e == "function" || typeof e == "symbol") throw new v("conflict");
1447
- e !== null && typeof e == "object" && De(e);
1526
+ e !== null && typeof e == "object" && Dt(e);
1448
1527
  }
1449
1528
  if (e === null || typeof e != "object") return e;
1450
1529
  const a = o?.get(e);
@@ -1456,132 +1535,133 @@ function V(e, t, r, n = !1, o) {
1456
1535
  if (Array.isArray(e)) {
1457
1536
  const s = [];
1458
1537
  o?.set(e, s);
1459
- for (let i = 0; i < e.length; i++) s[i] = V(ee(e, String(i)), t, r + 1, n, o);
1538
+ for (let i = 0; i < e.length; i++) s[i] = Z(ue(e, String(i)), t, r + 1, n, o);
1460
1539
  return s;
1461
1540
  }
1462
- return Nn(e, t, r, n, o);
1541
+ return ao(e, t, r, n, o);
1463
1542
  }
1464
- function Nn(e, t, r, n, o) {
1465
- if (!o) return Object.fromEntries(Object.keys(e).map((s) => [s, V(ee(e, s), t, r + 1, n)]));
1543
+ function ao(e, t, r, n, o) {
1544
+ if (!o) return Object.fromEntries(Object.keys(e).map((s) => [s, Z(ue(e, s), t, r + 1, n)]));
1466
1545
  const a = {};
1467
1546
  o.set(e, a);
1468
- for (const s of Object.keys(e)) Object.defineProperty(a, s, { value: V(ee(e, s), t, r + 1, n, o), enumerable: !0, writable: !0, configurable: !0 });
1547
+ for (const s of Object.keys(e)) Object.defineProperty(a, s, { value: Z(ue(e, s), t, r + 1, n, o), enumerable: !0, writable: !0, configurable: !0 });
1469
1548
  return a;
1470
1549
  }
1471
- function Ln(e) {
1472
- return V(e, { nodes: 0 }, 0, !0, /* @__PURE__ */ new WeakMap());
1550
+ function so(e) {
1551
+ return Z(e, { nodes: 0 }, 0, !0, /* @__PURE__ */ new WeakMap());
1473
1552
  }
1474
- function Hn(e) {
1475
- return V(e, { nodes: 0 }, 0, !0);
1553
+ function io(e) {
1554
+ const t = [];
1555
+ return Ge(e, t, /* @__PURE__ */ new Set(), { nodes: 0 }, 0), eo(e, t);
1476
1556
  }
1477
- function Dn(e) {
1478
- const t = V(e, { nodes: 0 }, 0);
1479
- for (const r of t) for (const n of Object.values(r.datasets)) qt(n);
1557
+ function co(e) {
1558
+ const t = Z(e, { nodes: 0 }, 0);
1559
+ for (const r of t) for (const n of Object.values(r.datasets)) ir(n);
1480
1560
  return t;
1481
1561
  }
1482
- async function Bn(e, t, r = {}) {
1483
- return (await jt(e, t, r)).plan;
1562
+ async function lo(e, t, r = {}) {
1563
+ return (await Bt(e, t, r)).plan;
1484
1564
  }
1485
- async function jt(e, t, r = {}) {
1486
- return bt(e, t, { ...r, knownTotalPages: void 0 });
1565
+ async function Bt(e, t, r = {}) {
1566
+ return kt(e, t, { ...r, knownTotalPages: void 0 });
1487
1567
  }
1488
- function Gn(e) {
1568
+ function uo(e) {
1489
1569
  return e.computed || e.groupBy || e.groups || e.grandTotal || e.tree || e.matrix || e.detail || e.rowVisibleWhen || e.headerGrid ? !1 : e.columns.every((t) => !t.format && !t.rules && !t.visibleWhen && !t.visual);
1490
1570
  }
1491
- function Wn(e, t) {
1492
- return e.length !== t.length || t.some((r) => r?.measurer || r?.formula || r?.mmPerRow || r?.knownTotalPages !== void 0) ? !1 : e.every((r) => !r.template.repeat && r.template.pages.every((n) => !n.flow && n.components.every((o) => o.kind === "list" ? Gn(o) : !o.binding && !o.chartBinding && !o.grid && !o.table && !o.richParagraphs)));
1571
+ function fo(e, t) {
1572
+ return e.length !== t.length || t.some((r) => r?.measurer || r?.formula || r?.mmPerRow || r?.knownTotalPages !== void 0) ? !1 : e.every((r) => !r.template.repeat && r.template.pages.every((n) => !n.flow && n.components.every((o) => o.kind === "list" ? uo(o) : !o.binding && !o.chartBinding && !o.grid && !o.table && !o.richParagraphs)));
1493
1573
  }
1494
- function Vn(e) {
1574
+ function mo(e) {
1495
1575
  const t = /* @__PURE__ */ new Map();
1496
1576
  for (const r of e) {
1497
1577
  if (!r.source || typeof r.value != "string" || typeof r.previousValue != "string" || r.previousText !== r.previousValue || ![r.previousValue, r.value].every((a) => a.trim().length && a.length <= 16384 && !/[\r\n]/.test(a))) return null;
1498
- const n = ce(r.source), o = t.get(n) ?? /* @__PURE__ */ new Map();
1578
+ const n = le(r.source), o = t.get(n) ?? /* @__PURE__ */ new Map();
1499
1579
  o.set(r.source.field, r), t.set(n, o);
1500
1580
  }
1501
1581
  return t;
1502
1582
  }
1503
- function Be(e) {
1583
+ function Ve(e) {
1504
1584
  return !e.source && !e.formula && !e.derived && !e.richParagraphs && !e.children && !e.dataBar && !e.numberFormat && !e.colSpan && !e.rowSpan && !e.indentMm && !e.style?.rotateDeg;
1505
1585
  }
1506
- function zn(e) {
1507
- return e.pages.every((t) => t.components.every((r) => !r.grid || r.grid.cells.every((n) => n.every((o) => !!o && Be(o)))));
1586
+ function ho(e) {
1587
+ return e.pages.every((t) => t.components.every((r) => !r.grid || r.grid.cells.every((n) => n.every((o) => !!o && Ve(o)))));
1508
1588
  }
1509
- function _n(e, t, r, n) {
1510
- if (!Be(e) || e.value !== t.previousValue || e.text !== t.previousText) return !1;
1511
- const o = r - n * 2, a = e.style, s = te(a).fontSizePt;
1589
+ function go(e, t, r, n) {
1590
+ if (!Ve(e) || e.value !== t.previousValue || e.text !== t.previousText) return !1;
1591
+ const o = r - n * 2, a = e.style, s = ee(a).fontSizePt;
1512
1592
  if (!Number.isFinite(o) || o < 1 || !Number.isFinite(s) || s <= 0) return !1;
1513
- const i = { fontSizePt: s, fontFamily: a?.fontFamily ?? Te, italic: a?.italic, bold: a?.bold, letterSpacingPt: a?.letterSpacing };
1514
- return D(t.previousText, o, i, oe).length === D(t.value, o, i, oe).length;
1593
+ const i = { fontSizePt: s, fontFamily: a?.fontFamily ?? $e, italic: a?.italic, bold: a?.bold, letterSpacingPt: a?.letterSpacing };
1594
+ return H(t.previousText, o, i, ne).length === H(t.value, o, i, ne).length;
1515
1595
  }
1516
- function Jn(e, t) {
1596
+ function po(e, t) {
1517
1597
  const r = e.colWidthsMm;
1518
1598
  if (!r || r.length !== e.cells[0].length || r.length !== t.table.columnKeys.length) return !1;
1519
1599
  const n = r.reduce((o, a) => o + a, 0);
1520
1600
  return Number.isFinite(n) && Math.abs(n - t.widthMm) <= Math.max(1e-7, n * 1e-10);
1521
1601
  }
1522
- function Un(e, t, r) {
1602
+ function wo(e, t, r) {
1523
1603
  const n = e.table?.source;
1524
1604
  if (e.table?.role !== "body" || n?.rowKey === void 0) return e;
1525
- const o = t.get(ce({ ...n, rowKey: n.rowKey }));
1605
+ const o = t.get(le({ ...n, rowKey: n.rowKey }));
1526
1606
  if (!o) return e;
1527
1607
  const a = e.grid;
1528
- if (!a || a.cells.length !== 1 || !Jn(a, e) || e.style?.rotateDeg) return null;
1608
+ if (!a || a.cells.length !== 1 || !po(a, e) || e.style?.rotateDeg) return null;
1529
1609
  const s = a.cells[0], i = [...s];
1530
1610
  for (let c = 0; c < s.length; c++) {
1531
1611
  const l = s[c];
1532
- if (!l || !Be(l)) return null;
1533
- const d = o.get(e.table.columnKeys[c]);
1534
- if (d) {
1535
- if (!_n(l, d, a.colWidthsMm[c], a.paddingMm ?? 0.5)) return null;
1536
- i[c] = { ...l, value: d.value, text: d.value }, r.add(d);
1612
+ if (!l || !Ve(l)) return null;
1613
+ const u = o.get(e.table.columnKeys[c]);
1614
+ if (u) {
1615
+ if (!go(l, u, a.colWidthsMm[c], a.paddingMm ?? 0.5)) return null;
1616
+ i[c] = { ...l, value: u.value, text: u.value }, r.add(u);
1537
1617
  }
1538
1618
  }
1539
1619
  return i.some((c, l) => c !== s[l]) ? { ...e, grid: { ...a, cells: [i] } } : e;
1540
1620
  }
1541
- async function qn(e, t, r) {
1542
- const n = Vn(t);
1621
+ async function yo(e, t, r) {
1622
+ const n = mo(t);
1543
1623
  if (!n || !t.length) return null;
1544
1624
  const o = /* @__PURE__ */ new Set(), a = [];
1545
1625
  let s = 0;
1546
1626
  for (const c of e.pages) {
1547
1627
  const l = [];
1548
- for (const d of c.components) {
1628
+ for (const u of c.components) {
1549
1629
  if (r?.aborted) return null;
1550
- const f = Un(d, n, o);
1630
+ const f = wo(u, n, o);
1551
1631
  if (!f) return null;
1552
- l.push(f), ++s % 128 === 0 && await new Promise((u) => setTimeout(u, 0));
1632
+ l.push(f), ++s % 128 === 0 && await new Promise((d) => setTimeout(d, 0));
1553
1633
  }
1554
- a.push(l.some((d, f) => d !== c.components[f]) ? { ...c, components: l } : c);
1634
+ a.push(l.some((u, f) => u !== c.components[f]) ? { ...c, components: l } : c);
1555
1635
  }
1556
1636
  if (o.size !== t.length) return null;
1557
1637
  const i = { ...e, pages: a };
1558
- return Oe(i).ok ? i : null;
1638
+ return je(i).ok ? i : null;
1559
1639
  }
1560
- function Xn(e, t, r) {
1561
- let n = Wn(t, r), o = e, a;
1640
+ function bo(e, t, r) {
1641
+ let n = fo(t, r), o = e, a;
1562
1642
  function s(c) {
1563
1643
  if (o = c, a = void 0, !!n) {
1564
- if (!zn(c)) {
1644
+ if (!ho(c)) {
1565
1645
  n = !1;
1566
1646
  return;
1567
1647
  }
1568
1648
  try {
1569
- a = ve(c);
1649
+ a = de(c);
1570
1650
  } catch {
1571
1651
  n = !1;
1572
1652
  }
1573
1653
  }
1574
1654
  }
1575
1655
  s(e);
1576
- async function i(c, l, d) {
1656
+ async function i(c, l, u) {
1577
1657
  if (!n || c !== o || !a?.()) return null;
1578
- const f = a, u = await qn(c, l, d);
1579
- return u && f() ? { plan: u, unchanged: f } : null;
1658
+ const f = a, d = await yo(c, l, u);
1659
+ return d && f() ? { plan: d, unchanged: f } : null;
1580
1660
  }
1581
1661
  return { candidate: i, publish: s };
1582
1662
  }
1583
- function Yn(e, t) {
1584
- const r = t ? void 0 : ve(e);
1663
+ function vo(e, t) {
1664
+ const r = t ? void 0 : de(e);
1585
1665
  let n, o;
1586
1666
  function a() {
1587
1667
  if (r && !r() || o && !o()) throw new v("conflict");
@@ -1590,7 +1670,7 @@ function Yn(e, t) {
1590
1670
  get plan() {
1591
1671
  if (!n) {
1592
1672
  a();
1593
- const s = Ln(e), i = ve(s);
1673
+ const s = so(e), i = de(s);
1594
1674
  n = s, o = i;
1595
1675
  }
1596
1676
  return n;
@@ -1598,9 +1678,9 @@ function Yn(e, t) {
1598
1678
  assertUnchanged: a
1599
1679
  };
1600
1680
  }
1601
- const Me = /* @__PURE__ */ new WeakMap();
1602
- function Bo(e) {
1603
- return Me.get(e);
1681
+ const Ce = /* @__PURE__ */ new WeakMap();
1682
+ function fa(e) {
1683
+ return Ce.get(e);
1604
1684
  }
1605
1685
  function U(e) {
1606
1686
  if (e?.aborted) {
@@ -1608,42 +1688,42 @@ function U(e) {
1608
1688
  throw t.name = "AbortError", t;
1609
1689
  }
1610
1690
  }
1611
- function Kt(e, t) {
1691
+ function Wt(e, t) {
1612
1692
  return e[t] === void 0 ? "" : e[t];
1613
1693
  }
1614
- function Qn(e, t) {
1694
+ function Mo(e, t) {
1615
1695
  if (t.edits.length > 1e4) throw new v("limit");
1616
1696
  const r = z(e), n = /* @__PURE__ */ new Set(), o = [], a = t.edits.map((s) => {
1617
1697
  const i = r(s.address);
1618
1698
  if (!i?.source) throw new v("missing");
1619
1699
  const c = j(s);
1620
1700
  if (n.has(c)) throw new v("duplicate");
1621
- if (n.add(c), He(i, s) || !Object.is(i.value, s.previousValue) || (i.cell.text ?? "") !== s.previousText) throw new v("conflict");
1622
- return o.push(i), ne(i, s.value);
1701
+ if (n.add(c), We(i, s) || !Object.is(i.value, s.previousValue) || (i.cell.text ?? "") !== s.previousText) throw new v("conflict");
1702
+ return o.push(i), re(i, s.value);
1623
1703
  });
1624
1704
  return { batch: { requestId: t.requestId, edits: a }, contexts: o };
1625
1705
  }
1626
- function Zn(e, t) {
1627
- const r = Rt(e);
1706
+ function So(e, t) {
1707
+ const r = At(e);
1628
1708
  return t.flatMap((n) => {
1629
1709
  if (!n.source) throw new v("missing");
1630
1710
  return r(n.source).map((o) => {
1631
- if (!Object.is(Kt(o.row, n.source.field), n.previousValue)) throw new v("conflict");
1711
+ if (!Object.is(Wt(o.row, n.source.field), n.previousValue)) throw new v("conflict");
1632
1712
  if (o.binding.rowKey === n.source.field) throw new v("readonly");
1633
1713
  return { row: o, field: n.source.field, value: n.value };
1634
1714
  });
1635
1715
  });
1636
1716
  }
1637
- function he(e, t, r) {
1717
+ function Me(e, t, r) {
1638
1718
  const n = { ...e, value: t, source: { ...e.source, ...r?.revision === void 0 ? {} : { revision: r.revision }, ...r?.sourceToken === void 0 ? {} : { sourceToken: r.sourceToken } } };
1639
- return n.cell = { ...e.cell, value: n.value, text: re(n, n.value) }, n;
1719
+ return n.cell = { ...e.cell, value: n.value, text: te(n, n.value) }, n;
1640
1720
  }
1641
- function eo(e, t, r) {
1721
+ function xo(e, t, r) {
1642
1722
  if (!r || r.revision === void 0 && r.sourceToken === void 0) return [...e];
1643
1723
  const n = new Set(t.edits.flatMap((o) => o.source ? [_(o.source)] : []));
1644
- return Et(e, $n(e, n, r));
1724
+ return jt(e, qn(e, n, r));
1645
1725
  }
1646
- function to(e, t, r) {
1726
+ function Po(e, t, r) {
1647
1727
  const n = new Set(t.edits.map((o) => _(o.source)));
1648
1728
  for (const o of n) e.set(o, {
1649
1729
  ...e.get(o),
@@ -1652,83 +1732,83 @@ function to(e, t, r) {
1652
1732
  });
1653
1733
  return n;
1654
1734
  }
1655
- function Go(e, t) {
1656
- return Ge(e, t);
1735
+ function ma(e, t) {
1736
+ return ze(e, t);
1657
1737
  }
1658
- function Ge(e, t, r) {
1738
+ function ze(e, t, r) {
1659
1739
  let n = t.parts;
1660
- const o = t.rebuild, a = [...t.validationFormulas ?? []], s = r ? Xn(e, n, r) : void 0;
1661
- let i = Kn(n), c = e, l;
1662
- const d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
1663
- function u(b) {
1664
- if (b !== c) throw new v("conflict");
1740
+ const o = t.rebuild, a = [...t.validationFormulas ?? []], s = r ? bo(e, n, r) : void 0;
1741
+ let i = oo(n), c = e, l;
1742
+ const u = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
1743
+ function d(y) {
1744
+ if (y !== c) throw new v("conflict");
1665
1745
  if (l) return l;
1666
1746
  if (!i?.()) throw new v("conflict");
1667
- return Dn(n);
1668
- }
1669
- async function m(b, y, p, h = {}) {
1670
- U(h.signal), y = { requestId: y.requestId, edits: y.edits.map((M) => ({ ...M, address: { ...M.address }, source: M.source ? { ...M.source } : void 0, table: M.table ? { ...M.table } : void 0 })) }, p = p.map((M) => ({ ...M, address: { ...M.address }, source: M.source ? { ...M.source } : void 0, table: M.table ? { ...M.table } : void 0, cell: { ...M.cell } })), await new Promise((M) => setTimeout(M, 0)), U(h.signal);
1671
- const S = u(b), T = Et(S, Zn(S, y.edits)), R = await s?.candidate(b, y.edits, h.signal);
1672
- U(h.signal);
1673
- const O = It(R?.plan ?? await o(T, h.signal), f);
1674
- U(h.signal);
1675
- const F = Yn(O, r !== void 0);
1676
- let w = !1, x = [], P = "allow", E = !1;
1677
- function k(M) {
1678
- return E = !0, F.assertUnchanged(), x = Object.freeze(pn(T, M, h.signal, a).map(($) => Object.freeze({ ...$ }))), F.assertUnchanged(), E = !1, P = M.warningPolicy ?? "allow", x;
1747
+ return co(n);
1748
+ }
1749
+ async function m(y, w, p, g = {}) {
1750
+ U(g.signal), w = { requestId: w.requestId, edits: w.edits.map((M) => ({ ...M, address: { ...M.address }, source: M.source ? { ...M.source } : void 0, table: M.table ? { ...M.table } : void 0 })) }, p = p.map((M) => ({ ...M, address: { ...M.address }, source: M.source ? { ...M.source } : void 0, table: M.table ? { ...M.table } : void 0, cell: { ...M.cell } })), await new Promise((M) => setTimeout(M, 0)), U(g.signal);
1751
+ const S = d(y), R = jt(S, So(S, w.edits)), E = await s?.candidate(y, w.edits, g.signal);
1752
+ U(g.signal);
1753
+ const I = Kt(E?.plan ?? await o(R, g.signal), f);
1754
+ U(g.signal);
1755
+ const F = vo(I, r !== void 0);
1756
+ let x = !1, b = [], P = "allow", k = !1;
1757
+ function C(M) {
1758
+ return k = !0, F.assertUnchanged(), b = Object.freeze(An(R, M, g.signal, a).map(($) => Object.freeze({ ...$ }))), F.assertUnchanged(), k = !1, P = M.warningPolicy ?? "allow", b;
1679
1759
  }
1680
- return h.validation && k(h.validation), { get plan() {
1760
+ return g.validation && C(g.validation), { get plan() {
1681
1761
  return F.plan;
1682
1762
  }, get validationIssues() {
1683
- return x;
1684
- }, validate: k, commit(M) {
1685
- if (U(h.signal), w || c !== b) throw new v("conflict");
1686
- if (R && !R.unchanged()) throw new v("conflict");
1763
+ return b;
1764
+ }, validate: C, commit(M) {
1765
+ if (U(g.signal), x || c !== y) throw new v("conflict");
1766
+ if (E && !E.unchanged()) throw new v("conflict");
1687
1767
  if (F.assertUnchanged(), M?.conflicts?.length) throw new v("conflict");
1688
- if (E) throw new Error("候选规则校验未完成,不能提交");
1689
- hn(x, P);
1690
- const $ = eo(T, y, M), B = On(O, y, M);
1768
+ if (k) throw new Error("候选规则校验未完成,不能提交");
1769
+ Fn(b, P);
1770
+ const $ = xo(R, w, M), B = Xn(I, w, M);
1691
1771
  if (M) {
1692
- const G = to(f, y, M);
1693
- for (const [N, J] of d) G.has(_(J.source)) && d.set(N, he(J, J.value, M));
1772
+ const K = Po(f, w, M);
1773
+ for (const [W, J] of u) K.has(_(J.source)) && u.set(W, Me(J, J.value, M));
1694
1774
  }
1695
- return p.forEach((G, N) => d.set(j(G), he(G, y.edits[N].value, M))), w = !0, l = $, n = void 0, i = void 0, c = B, s?.publish(c), Me.set(c, g), c;
1775
+ return p.forEach((K, W) => u.set(j(K), Me(K, w.edits[W].value, M))), x = !0, l = $, n = void 0, i = void 0, c = B, s?.publish(c), Ce.set(c, h), c;
1696
1776
  } };
1697
1777
  }
1698
- const g = {
1778
+ const h = {
1699
1779
  get plan() {
1700
1780
  return c;
1701
1781
  },
1702
- async prepare(b, y, p) {
1703
- const h = Qn(b, y);
1704
- return m(b, h.batch, h.contexts, p);
1782
+ async prepare(y, w, p) {
1783
+ const g = Mo(y, w);
1784
+ return m(y, g.batch, g.contexts, p);
1705
1785
  },
1706
- async prepareHistory(b, y, p, h, S) {
1707
- if (!h.trim() || y.length > 1e4) throw new v("limit");
1708
- const T = u(b), R = Rt(T), O = $t(b), F = /* @__PURE__ */ new Set(), x = y.map((k) => {
1709
- if (!k.source) throw new v("missing");
1710
- const M = j(k);
1786
+ async prepareHistory(y, w, p, g, S) {
1787
+ if (!g.trim() || w.length > 1e4) throw new v("limit");
1788
+ const R = d(y), E = At(R), I = Nt(y), F = /* @__PURE__ */ new Set(), b = w.map((C) => {
1789
+ if (!C.source) throw new v("missing");
1790
+ const M = j(C);
1711
1791
  if (F.has(M)) throw new v("duplicate");
1712
1792
  F.add(M);
1713
- const $ = O.get(M) ?? d.get(M);
1793
+ const $ = I.get(M) ?? u.get(M);
1714
1794
  if (!$?.source) throw new v("missing");
1715
- const B = R($.source)[0];
1716
- return he($, Kt(B.row, $.source.field));
1717
- }).map((k, M) => ({ context: k, edit: ne(k, y[M][p]) })).filter(({ edit: k }) => !Object.is(k.previousValue, k.value)), P = { requestId: h, edits: x.map(({ edit: k }) => k) }, E = x.map(({ context: k }) => k);
1718
- return { batch: P, contexts: E, prepared: await m(b, P, E, S) };
1795
+ const B = E($.source)[0];
1796
+ return Me($, Wt(B.row, $.source.field));
1797
+ }).map((C, M) => ({ context: C, edit: re(C, w[M][p]) })).filter(({ edit: C }) => !Object.is(C.previousValue, C.value)), P = { requestId: g, edits: b.map(({ edit: C }) => C) }, k = b.map(({ context: C }) => C);
1798
+ return { batch: P, contexts: k, prepared: await m(y, P, k, S) };
1719
1799
  }
1720
1800
  };
1721
- return Me.set(e, g), g;
1801
+ return Ce.set(e, h), h;
1722
1802
  }
1723
- function Wo(e) {
1724
- const t = yt(e.template, e.datasets, e.pagination).plan;
1725
- return Ge(t, { validationFormulas: [e.pagination?.formula], parts: [{ template: e.template, datasets: e.datasets }], rebuild: (r, n) => Bn(r[0].template, r[0].datasets, { ...e.pagination, signal: n }) }, [e.pagination]);
1803
+ function ha(e) {
1804
+ const t = Pt(e.template, e.datasets, e.pagination).plan;
1805
+ return ze(t, { validationFormulas: [e.pagination?.formula], parts: [{ template: e.template, datasets: e.datasets }], rebuild: (r, n) => lo(r[0].template, r[0].datasets, { ...e.pagination, signal: n }) }, [e.pagination]);
1726
1806
  }
1727
- let ro = 0;
1728
- function no() {
1729
- return `report-${Date.now()}-${++ro}`;
1807
+ let ko = 0;
1808
+ function Co() {
1809
+ return `report-${Date.now()}-${++ko}`;
1730
1810
  }
1731
- function Ye(e, t, r) {
1811
+ function tt(e, t, r) {
1732
1812
  if (!r?.aborted)
1733
1813
  try {
1734
1814
  const n = e?.({ ...t });
@@ -1737,14 +1817,27 @@ function Ye(e, t, r) {
1737
1817
  } catch {
1738
1818
  }
1739
1819
  }
1740
- function oo(e) {
1741
- const t = e.taskId ?? no(), r = (n, o, a) => {
1742
- Ye(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: n, status: o, ...a === void 0 ? {} : { reportId: a } }, e.signal);
1820
+ function To(e) {
1821
+ const t = e.taskId ?? Co(), r = (n, o, a) => {
1822
+ tt(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: n, status: o, ...a === void 0 ? {} : { reportId: a } }, e.signal);
1743
1823
  };
1744
1824
  return {
1745
1825
  taskId: t,
1746
1826
  progress(n, o, a) {
1747
- Ye(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: n, status: "started", completed: o, total: a }, e.signal);
1827
+ tt(e.onEvent, { taskId: t, ...e.correlationId === void 0 ? {} : { correlationId: e.correlationId }, stage: n, status: "started", completed: o, total: a }, e.signal);
1828
+ },
1829
+ /** Internal preparation can preserve an exotic synchronous fallback while
1830
+ * owned work reports completion after its cooperative slices finish. */
1831
+ runMaybeAsync(n, o, a) {
1832
+ r(n, "started", a);
1833
+ try {
1834
+ const s = o();
1835
+ return s instanceof Promise ? s.then((i) => (r(n, "completed", a), i), (i) => {
1836
+ throw r(n, "failed", a), i;
1837
+ }) : (r(n, "completed", a), s);
1838
+ } catch (s) {
1839
+ throw r(n, "failed", a), s;
1840
+ }
1748
1841
  },
1749
1842
  async run(n, o, a) {
1750
1843
  r(n, "started", a);
@@ -1766,25 +1859,25 @@ function oo(e) {
1766
1859
  }
1767
1860
  };
1768
1861
  }
1769
- function Nt(e) {
1862
+ function Gt(e) {
1770
1863
  if (!e || typeof e != "object" || Array.isArray(e)) return !1;
1771
1864
  const t = e, r = (n) => typeof n == "string" && n.trim().length > 0 && n.length <= 256;
1772
1865
  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);
1773
1866
  }
1774
- function ao(e) {
1867
+ function Ro(e) {
1775
1868
  return e === "missing-source" || e === "not-applicable" || e === "not-calculable";
1776
1869
  }
1777
- function so(e) {
1778
- return e.target !== void 0 && !Nt(e.target) ? !1 : e.valueState === void 0 || ao(e.valueState) && e.target !== void 0;
1870
+ function Eo(e) {
1871
+ return e.target !== void 0 && !Gt(e.target) ? !1 : e.valueState === void 0 || Ro(e.valueState) && e.target !== void 0;
1779
1872
  }
1780
- function Vo(e, t) {
1781
- if (at([], e), !Nt(t)) throw new Error("数据说明目标无效");
1873
+ function ga(e, t) {
1874
+ if (Cr([], e), !Gt(t)) throw new Error("数据说明目标无效");
1782
1875
  const r = e.fields.find((o) => o.field === t.field);
1783
1876
  if (!r) throw new Error("数据说明字段未在契约中声明");
1784
1877
  const n = [];
1785
1878
  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;
1786
1879
  }
1787
- function Lt(e, t, r = {}) {
1880
+ function Vt(e, t, r = {}) {
1788
1881
  const n = /* @__PURE__ */ new Map();
1789
1882
  for (const a of e.pages) for (const s of a.components) {
1790
1883
  if (s.kind !== "list" || s.tree?.input !== "nested") continue;
@@ -1796,26 +1889,26 @@ function Lt(e, t, r = {}) {
1796
1889
  const o = { ...t };
1797
1890
  for (const [a, s] of n) {
1798
1891
  const i = Math.min(s.maxRows ?? 1e5, r.maxRows ?? 1 / 0);
1799
- o[a] = nt(t[a] ?? [], { ...s, maxRows: i }, r.signal);
1892
+ o[a] = ct(t[a] ?? [], { ...s, maxRows: i }, r.signal);
1800
1893
  }
1801
1894
  return o;
1802
1895
  }
1803
- function zo(e, t, r = {}) {
1804
- return Object.values(Lt(e, t, r)).reduce((n, o) => n + o.length, 0);
1896
+ function pa(e, t, r = {}) {
1897
+ return Object.values(Vt(e, t, r)).reduce((n, o) => n + o.length, 0);
1805
1898
  }
1806
- function _o(e, t, r) {
1807
- const n = gr(r), o = e?.pages.flatMap((i) => i.components).find((i) => i.kind === "list" && i.dataset === t && i.tree?.input === "nested");
1899
+ function wa(e, t, r) {
1900
+ const n = Tr(r), o = e?.pages.flatMap((i) => i.components).find((i) => i.kind === "list" && i.dataset === t && i.tree?.input === "nested");
1808
1901
  if (!o || o.kind !== "list" || !o.tree) return n;
1809
1902
  const a = n.items, s = o.tree.childrenField ?? "children";
1810
1903
  return { ...n, items: { $ref: "#/$defs/treeNode" }, $defs: { treeNode: { ...a, properties: { ...a.properties, [s]: { anyOf: [{ type: "null" }, { type: "array", items: { $ref: "#/$defs/treeNode" } }] } } } } };
1811
1904
  }
1812
- function Ht(e, t) {
1905
+ function zt(e, t) {
1813
1906
  return JSON.stringify([e, t]);
1814
1907
  }
1815
- function Dt(e, t, r) {
1816
- return r === void 0 ? Ht(e, t) : JSON.stringify(["shared", r]);
1908
+ function _t(e, t, r) {
1909
+ return r === void 0 ? zt(e, t) : JSON.stringify(["shared", r]);
1817
1910
  }
1818
- function Bt(e, t, r) {
1911
+ function Jt(e, t, r) {
1819
1912
  return e.map((n) => {
1820
1913
  const o = n.table ? {
1821
1914
  ...n.table,
@@ -1824,7 +1917,7 @@ function Bt(e, t, r) {
1824
1917
  } : void 0, a = n.grid?.cells.map((s) => s.map((i) => !i || !i.source && !i.children ? i : {
1825
1918
  ...i,
1826
1919
  ...i.source ? { source: { ...i.source, sourceScope: t } } : {},
1827
- ...i.children ? { children: Bt(i.children, t, r) } : {}
1920
+ ...i.children ? { children: Jt(i.children, t, r) } : {}
1828
1921
  }));
1829
1922
  return o || a ? {
1830
1923
  ...n,
@@ -1833,74 +1926,104 @@ function Bt(e, t, r) {
1833
1926
  } : n;
1834
1927
  });
1835
1928
  }
1836
- function Se(e) {
1837
- return Ie(e.maxChartComponents), { maxPages: e.maxPages, maxCells: e.maxCells, maxChartComponents: e.maxChartComponents ?? tr, usedPages: 0, usedCells: 0, usedChartComponents: 0 };
1929
+ function Te(e) {
1930
+ return Fe(e.maxChartComponents), { maxPages: e.maxPages, maxCells: e.maxCells, maxChartComponents: e.maxChartComponents ?? mr, usedPages: 0, usedCells: 0, usedChartComponents: 0 };
1838
1931
  }
1839
- function io(e, t) {
1932
+ function Oo(e, t) {
1840
1933
  if (!e.repeat) return !1;
1841
1934
  const r = Object.prototype.hasOwnProperty.call(t, e.repeat.dataset) ? t[e.repeat.dataset] : void 0;
1842
1935
  return Array.isArray(r) && r.length === 0;
1843
1936
  }
1844
- function co(e) {
1937
+ function $o(e) {
1845
1938
  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;
1846
1939
  return e.pages.reduce((r, n) => r + n.components.reduce((o, a) => o + t(a), 0), 0);
1847
1940
  }
1848
- function xe(e, t) {
1941
+ function fe(e, t) {
1849
1942
  return e === void 0 ? void 0 : e - t;
1850
1943
  }
1851
- function pe(e, t) {
1944
+ function Se(e, t) {
1852
1945
  return e === void 0 ? t : Math.max(1, Math.min(e, t ?? e));
1853
1946
  }
1854
- function Gt(e, t, r, n, o) {
1855
- Ie(e?.maxChartComponents);
1856
- const a = xe(t.maxPages, t.usedPages), s = t.maxChartComponents - t.usedChartComponents;
1857
- if (a !== void 0 && a < 1 && r.pages.length && !io(r, n)) throw new X(0, 1);
1858
- if (s < 1 && r.pages.some((i) => i.components.some((c) => c.kind !== "list" && c.chartBinding))) throw new we(s, 1);
1947
+ function Ut(e, t, r, n, o) {
1948
+ Fe(e?.maxChartComponents);
1949
+ const a = fe(t.maxPages, t.usedPages), s = t.maxChartComponents - t.usedChartComponents;
1950
+ if (a !== void 0 && a < 1 && r.pages.length && !Oo(r, n)) throw new V(0, 1);
1951
+ if (s < 1 && r.pages.some((i) => i.components.some((c) => c.kind !== "list" && c.chartBinding))) throw new ae(s, 1);
1859
1952
  return {
1860
1953
  ...e,
1861
1954
  signal: o ?? e?.signal,
1862
- maxPages: pe(a, e?.maxPages),
1863
- maxCells: pe(xe(t.maxCells, t.usedCells), e?.maxCells),
1864
- maxChartComponents: pe(s, e?.maxChartComponents)
1955
+ maxPages: Se(a, e?.maxPages),
1956
+ maxCells: Se(fe(t.maxCells, t.usedCells), e?.maxCells),
1957
+ maxChartComponents: Se(s, e?.maxChartComponents)
1865
1958
  };
1866
1959
  }
1867
- function Wt(e, t) {
1868
- const r = co(t.plan), n = xe(e.maxCells, e.usedCells);
1869
- if (n !== void 0 && r > n) throw new ae(n, r);
1870
- e.usedPages += t.plan.pages.length, e.usedCells += r, e.usedChartComponents += t.chartComponents;
1960
+ function qt(e, t) {
1961
+ const r = fe(e.maxPages, e.usedPages), n = e.maxChartComponents - e.usedChartComponents;
1962
+ if (r !== void 0 && t.plan.pages.length > r) throw new V(r, t.plan.pages.length);
1963
+ if (t.chartComponents > n) throw new ae(n, t.chartComponents);
1964
+ const o = $o(t.plan), a = fe(e.maxCells, e.usedCells);
1965
+ if (a !== void 0 && o > a) throw new oe(a, o);
1966
+ e.usedPages += t.plan.pages.length, e.usedCells += o, e.usedChartComponents += t.chartComponents;
1967
+ }
1968
+ function Xt(e, t) {
1969
+ return e instanceof V && t.maxPages !== void 0 && (e.limit === t.maxPages - t.usedPages || e.limit === 0) ? new V(t.maxPages, t.usedPages + e.actual) : e instanceof oe && t.maxCells !== void 0 ? new oe(t.maxCells, t.usedCells + e.actual) : e instanceof ae && e.limit === t.maxChartComponents - t.usedChartComponents ? new ae(t.maxChartComponents, t.usedChartComponents + e.estimated) : e;
1970
+ }
1971
+ function Io(e, t) {
1972
+ const r = Object.keys(e.datasets), n = Object.keys(t.datasets);
1973
+ return e.template === t.template && e.sourceScope === t.sourceScope && r.length === n.length && r.every((o, a) => o === n[a] && e.datasets[o] === t.datasets[o]);
1974
+ }
1975
+ function Fo() {
1976
+ const e = [];
1977
+ return async (t, r, n, o) => {
1978
+ if (n.formula || n.measurer || n.onWarning) return o();
1979
+ const a = e[t];
1980
+ if (a && Io(a.part, r) && a.unchanged()) return a.result;
1981
+ const s = await o();
1982
+ if (n.signal?.aborted) return s;
1983
+ try {
1984
+ e[t] = { part: r, result: s, unchanged: de(s.plan) };
1985
+ } catch {
1986
+ e[t] = void 0;
1987
+ }
1988
+ return s;
1989
+ };
1871
1990
  }
1872
- function Vt(e, t) {
1873
- return e instanceof X && t.maxPages !== void 0 && (e.limit === t.maxPages - t.usedPages || e.limit === 0) ? new X(t.maxPages, t.usedPages + e.actual) : e instanceof ae && t.maxCells !== void 0 ? new ae(t.maxCells, t.usedCells + e.actual) : e instanceof we && e.limit === t.maxChartComponents - t.usedChartComponents ? new we(t.maxChartComponents, t.usedChartComponents + e.estimated) : e;
1991
+ const Yt = /* @__PURE__ */ new WeakMap();
1992
+ function ya(e, t) {
1993
+ return Yt.set(e, t), e;
1874
1994
  }
1875
- function Jo(e) {
1995
+ function Qt(e, t, r, n) {
1996
+ Yt.get(e)?.(t, r, n);
1997
+ }
1998
+ function ba(e) {
1876
1999
  if (!("mapData" in e)) return e;
1877
2000
  const { load: t, mapData: r, ...n } = e;
1878
2001
  return { ...n, load: async (o) => {
1879
2002
  const a = await t(o);
1880
- I(o.signal);
2003
+ O(o.signal);
1881
2004
  try {
1882
2005
  return r(a, o);
1883
2006
  } catch (s) {
1884
- throw new C("validate", `报表 ${o.reportId} 数据映射失败`, s);
2007
+ throw new T("validate", `报表 ${o.reportId} 数据映射失败`, s);
1885
2008
  }
1886
2009
  } };
1887
2010
  }
1888
- class C extends Error {
2011
+ class T extends Error {
1889
2012
  constructor(t, r, n) {
1890
2013
  super(r), this.name = "ReportSourceError", this.code = t, this.cause = n;
1891
2014
  }
1892
2015
  }
1893
- function ge(e) {
2016
+ function ye(e) {
1894
2017
  const t = new Error("报表加载已取消");
1895
2018
  return t.name = "AbortError", Object.defineProperty(t, "cause", { value: e.reason }), t;
1896
2019
  }
1897
- function I(e) {
1898
- if (e?.aborted) throw ge(e);
2020
+ function O(e) {
2021
+ if (e?.aborted) throw ye(e);
1899
2022
  }
1900
- function Pe(e, t) {
2023
+ function Re(e, t) {
1901
2024
  return t ? new Promise((r, n) => {
1902
2025
  const o = () => t.removeEventListener("abort", a), a = () => {
1903
- o(), n(ge(t));
2026
+ o(), n(ye(t));
1904
2027
  };
1905
2028
  t.addEventListener("abort", a, { once: !0 }), t.aborted && a(), Promise.resolve(e).then(
1906
2029
  (s) => {
@@ -1912,174 +2035,204 @@ function Pe(e, t) {
1912
2035
  );
1913
2036
  }) : Promise.resolve(e);
1914
2037
  }
1915
- function lo(e, t) {
2038
+ function Ao(e, t) {
1916
2039
  if (!e || typeof e != "object" || Array.isArray(e))
1917
- throw new C("validate", `报表 ${t} 的数据集应为对象`);
2040
+ throw new T("validate", `报表 ${t} 的数据集应为对象`);
1918
2041
  for (const [r, n] of Object.entries(e))
1919
2042
  if (!Array.isArray(n) || n.some((o) => !o || typeof o != "object" || Array.isArray(o)))
1920
- throw new C("validate", `报表 ${t} 的数据集 ${r} 应为对象数组`);
2043
+ throw new T("validate", `报表 ${t} 的数据集 ${r} 应为对象数组`);
1921
2044
  }
1922
- async function uo(e, t, r) {
2045
+ async function jo(e, t, r) {
1923
2046
  const { reportId: n, signal: o } = t;
1924
2047
  try {
1925
- const a = await Pe(e(t), o);
1926
- I(o);
1927
- const s = lr(a);
2048
+ const a = await Re(e(t), o);
2049
+ O(o);
2050
+ const s = Mr(a);
1928
2051
  if (!s.ok)
1929
- throw new C("validate", `报表 ${n} 模板校验失败:${s.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ")}`);
2052
+ throw new T("validate", `报表 ${n} 模板校验失败:${s.errors.slice(0, 3).map((i) => `${i.path}: ${i.message}`).join("; ")}`);
1930
2053
  return r.push(...s.warnings.map((i) => `${n}: ${i.path}: ${i.message}`)), a;
1931
2054
  } catch (a) {
1932
- throw o?.aborted ? ge(o) : a instanceof C ? a : a instanceof dr ? new C("validate", `报表 ${n} 模板校验失败:${a.message}`, a) : new C("fetch", `报表 ${n} 模板加载失败:${a instanceof Error ? a.message : String(a)}`, a);
2055
+ throw o?.aborted ? ye(o) : a instanceof T ? a : a instanceof Sr ? new T("validate", `报表 ${n} 模板校验失败:${a.message}`, a) : new T("fetch", `报表 ${n} 模板加载失败:${a instanceof Error ? a.message : String(a)}`, a);
1933
2056
  }
1934
2057
  }
1935
- async function fo(e, t, r, n) {
2058
+ async function Ko(e, t, r, n) {
1936
2059
  const o = t.signal;
1937
2060
  let a;
1938
2061
  try {
1939
- if (e.load) a = await Pe(e.load(t), o);
2062
+ if (e.load) a = await Re(e.load(t), o);
1940
2063
  else if (e.provider) {
1941
- const s = await Pe(e.provider.query(t), o);
1942
- I(o), mo(s, r), a = s.datasets, n?.(r, s);
2064
+ const s = await Re(e.provider.query(t), o);
2065
+ O(o), No(s, r), a = s.datasets, n?.(r, s);
1943
2066
  } else a = e.datasets ?? {};
1944
2067
  } catch (s) {
1945
- throw o?.aborted ? ge(o) : s instanceof C ? s : new C("fetch", `报表 ${r} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
2068
+ throw o?.aborted ? ye(o) : s instanceof T ? s : new T("fetch", `报表 ${r} 取数失败:${s instanceof Error ? s.message : String(s)}`, s);
1946
2069
  }
1947
- return I(o), a;
2070
+ return O(o), a;
1948
2071
  }
1949
- function mo(e, t) {
1950
- if (!e || typeof e != "object" || Array.isArray(e)) throw new C("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
2072
+ function No(e, t) {
2073
+ if (!e || typeof e != "object" || Array.isArray(e)) throw new T("validate", `报表 ${t} Provider 应返回 datasets 结果对象`);
1951
2074
  for (const r of ["revision", "sourceToken"])
1952
- if (e[r] !== void 0 && typeof e[r] != "string") throw new C("validate", `报表 ${t} Provider ${r} 应为字符串`);
2075
+ if (e[r] !== void 0 && typeof e[r] != "string") throw new T("validate", `报表 ${t} Provider ${r} 应为字符串`);
1953
2076
  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))))
1954
- throw new C("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
1955
- if (e.diagnostics?.some((r) => !so(r)))
1956
- throw new C("validate", `报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`);
2077
+ throw new T("validate", `报表 ${t} Provider diagnostics 不符合结构化诊断契约`);
2078
+ if (e.diagnostics?.some((r) => !Eo(r)))
2079
+ throw new T("validate", `报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`);
1957
2080
  }
1958
- function go(e, t, r, n, o) {
2081
+ function* Zt(e, t, r, n, o, a = !0) {
1959
2082
  try {
1960
- t = Lt(n, t, { maxRows: e.dataValidation?.maxRows, signal: o });
1961
- } catch (a) {
1962
- throw new C("validate", `报表 ${r} 树形数据无效:${a instanceof Error ? a.message : String(a)}`, a);
2083
+ t = Vt(n, t, { maxRows: e.dataValidation?.maxRows, signal: o });
2084
+ } catch (s) {
2085
+ throw new T("validate", `报表 ${r} 树形数据无效:${s instanceof Error ? s.message : String(s)}`, s);
1963
2086
  }
1964
- for (const [a, s] of Object.entries(e.dataSchema ?? {})) {
1965
- let i;
2087
+ for (const [s, i] of Object.entries(e.dataSchema ?? {})) {
2088
+ const c = Object.prototype.hasOwnProperty.call(t, s) ? t[s] : void 0, l = { ...e.dataValidation, path: `$.datasets.${s}` };
1966
2089
  try {
1967
- i = at(Object.prototype.hasOwnProperty.call(t, a) ? t[a] : void 0, s, { ...e.dataValidation, path: `$.datasets.${a}` });
1968
- } catch (c) {
1969
- throw new C("config", `报表 ${r} 数据集 ${a} 字段契约配置无效`, c);
2090
+ const u = yield* Rr(c, i, l, a);
2091
+ if (!u.ok) throw new T("validate", `报表 ${r} 数据集 ${s} 不符合字段契约:${u.issues[0]?.message}`, { issues: u.issues });
2092
+ } catch (u) {
2093
+ throw O(o), u instanceof T ? u : new T("config", `报表 ${r} 数据集 ${s} 字段契约配置无效`, u);
1970
2094
  }
1971
- if (!i.ok) throw new C("validate", `报表 ${r} 数据集 ${a} 不符合字段契约:${i.issues[0]?.message}`, { issues: i.issues });
1972
2095
  }
1973
2096
  }
1974
- async function ho(e, t, r, n, o) {
2097
+ function Lo(e, t, r, n, o) {
2098
+ let a;
2099
+ try {
2100
+ a = io({ part: e, validation: { dataSchema: t.dataSchema, dataValidation: t.dataValidation } });
2101
+ } catch {
2102
+ O(o);
2103
+ for (const s of Zt(t, e.datasets, r, e.template, o, !1))
2104
+ ;
2105
+ return Qt(n, r, e.datasets, e.template), { part: e, owned: !1, release: () => {
2106
+ } };
2107
+ }
2108
+ return Do(a, t, r, n, o);
2109
+ }
2110
+ async function Do(e, t, r, n, o) {
2111
+ const { part: a, validation: s } = await xe(e, o);
2112
+ await xe(Zt({ ...t, ...s }, a.datasets, r, a.template, o), o);
2113
+ const i = $r(a.datasets);
1975
2114
  try {
1976
- let a;
1977
2115
  try {
1978
- a = Hn(e);
1979
- } catch {
2116
+ await Ar(a.template, a.datasets, { ...t.pagination, signal: o ?? t.pagination?.signal });
2117
+ } catch (c) {
2118
+ throw O(o), new T("validate", `报表 ${r} 排版失败:${c instanceof Error ? c.message : String(c)}`, c);
1980
2119
  }
1981
- const s = a ?? e, i = Gt(t.pagination, n, s.template, s.datasets, o), c = a ? await bt(s.template, s.datasets, i) : yt(s.template, s.datasets, i);
1982
- return Wt(n, c), { result: c, part: s };
1983
- } catch (a) {
1984
- I(o);
1985
- const s = Vt(a, n);
1986
- throw new C("validate", `报表 ${r} 排版失败:${s instanceof Error ? s.message : String(s)}`, s);
2120
+ return Qt(n, r, a.datasets, a.template), { part: a, owned: !0, release: i };
2121
+ } catch (c) {
2122
+ throw i(), c;
1987
2123
  }
1988
2124
  }
1989
- function zt(e, t, r, n, o) {
2125
+ async function Ho(e, t, r, n, o, a) {
2126
+ try {
2127
+ const s = Ut(r.pagination, o, e.template, e.datasets, a), i = t ? await kt(e.template, e.datasets, s) : Pt(e.template, e.datasets, s);
2128
+ return qt(o, i), i;
2129
+ } catch (s) {
2130
+ O(a);
2131
+ const i = Xt(s, o);
2132
+ throw new T("validate", `报表 ${n} 排版失败:${i instanceof Error ? i.message : String(i)}`, i);
2133
+ }
2134
+ }
2135
+ function er(e, t, r, n, o) {
1990
2136
  const a = /* @__PURE__ */ new Map(), s = (i) => {
1991
2137
  let c = a.get(i);
1992
2138
  return c === void 0 && (c = JSON.stringify([r, n, i]), a.set(i, c)), c;
1993
2139
  };
1994
2140
  for (const i of t.pages) e.push({
1995
2141
  ...i,
1996
- meta: { ...i.meta, reportScope: Ht(r, n) },
1997
- components: Bt(i.components, o ?? Dt(r, n), s)
2142
+ meta: { ...i.meta, reportScope: zt(r, n) },
2143
+ components: Jt(i.components, o ?? _t(r, n), s)
1998
2144
  });
1999
2145
  }
2000
- async function po(e, t, r, n, o) {
2001
- const a = [], s = Se(n);
2002
- for (const [l, d] of e.entries()) {
2003
- I(o);
2146
+ async function Bo(e, t, r, n, o, a) {
2147
+ const s = [], i = Te(n);
2148
+ for (const [u, f] of e.entries()) {
2149
+ O(a);
2004
2150
  try {
2005
- const f = await jt(d.template, d.datasets, Gt(t[l]?.pagination, s, d.template, d.datasets, o));
2006
- Wt(s, f), zt(a, f.plan, l, r[l], d.sourceScope);
2007
- } catch (f) {
2008
- throw Vt(f, s);
2151
+ const d = Ut(t[u]?.pagination, i, f.template, f.datasets, a);
2152
+ O(d.signal);
2153
+ const m = await o(u, f, d, () => Bt(f.template, f.datasets, d));
2154
+ qt(i, m), er(s, m.plan, u, r[u], f.sourceScope);
2155
+ } catch (d) {
2156
+ throw Xt(d, i);
2009
2157
  }
2010
2158
  }
2011
- const i = { schemaVersion: Ce, ...e.some((l) => Fe(l.template)) ? { requiresRecalculation: !0 } : {}, pages: a }, c = Oe(i);
2012
- if (!c.ok) throw new C("validate", `重算渲染计划校验失败:${c.errors[0]?.message}`);
2013
- return i;
2159
+ const c = { schemaVersion: Oe, ...e.some((u) => Ke(u.template)) ? { requiresRecalculation: !0 } : {}, pages: s }, l = je(c);
2160
+ if (!l.ok) throw new T("validate", `重算渲染计划校验失败:${l.errors[0]?.message}`);
2161
+ return c;
2014
2162
  }
2015
- function Uo(e, t = {}) {
2016
- if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new C("config", "maxPages 应为正安全整数");
2017
- if (t.maxCells !== void 0 && (!Number.isSafeInteger(t.maxCells) || t.maxCells < 1)) throw new C("config", "maxCells 应为正安全整数");
2163
+ function va(e, t = {}) {
2164
+ if (t.maxPages !== void 0 && (!Number.isSafeInteger(t.maxPages) || t.maxPages < 1)) throw new T("config", "maxPages 应为正安全整数");
2165
+ if (t.maxCells !== void 0 && (!Number.isSafeInteger(t.maxCells) || t.maxCells < 1)) throw new T("config", "maxCells 应为正安全整数");
2018
2166
  try {
2019
- Se(t);
2167
+ Te(t);
2020
2168
  } catch (o) {
2021
- throw new C("config", "maxChartComponents 应为 1..1000000 的安全整数", o);
2169
+ throw new T("config", "maxChartComponents 应为 1..1000000 的安全整数", o);
2022
2170
  }
2023
2171
  function r(o) {
2024
2172
  const a = Object.prototype.hasOwnProperty.call(e, o) ? e[o] : void 0;
2025
- if (!a) throw new C("config", `未注册报表 ${o}`);
2026
- if (a.sourceScope !== void 0 && (typeof a.sourceScope != "string" || !a.sourceScope.trim() || a.sourceScope.length > 512)) throw new C("config", "sourceScope 应为不超过 512 字符的非空字符串");
2173
+ if (!a) throw new T("config", `未注册报表 ${o}`);
2174
+ if (a.sourceScope !== void 0 && (typeof a.sourceScope != "string" || !a.sourceScope.trim() || a.sourceScope.length > 512)) throw new T("config", "sourceScope 应为不超过 512 字符的非空字符串");
2027
2175
  return a;
2028
2176
  }
2029
2177
  return Object.assign(async ({ reportIds: o, params: a, signal: s, onWarning: i, onQueryResult: c, ...l }) => {
2030
- I(s);
2031
- const d = oo({ ...l, signal: s }), f = [...o], u = { ...a };
2032
- if (f.length === 0) throw new C("config", "缺少报表 ID");
2033
- const m = f.map(r), g = d.runSync("validate", () => m.map((w) => We(
2034
- w.params ?? (typeof w.template == "function" ? [] : w.template.params) ?? [],
2035
- u
2036
- ))), b = [], y = [], p = Se(t), h = [];
2037
- for (const [w, x] of m.entries()) {
2038
- I(s);
2039
- const P = f[w], E = { reportId: P, params: g[w], signal: s }, k = typeof x.template == "function" ? await d.run("query", () => uo(x.template, E, h), P) : x.template;
2040
- E.params = d.runSync("validate", () => We(x.params ?? k.params ?? [], E.params), P);
2041
- const M = await d.run("query", () => fo(x, E, P, (N, J) => c?.(N, J, w)), P);
2042
- d.runSync("validate", () => {
2043
- lo(M, P), t.onDatasets?.(P, M, k), go(x, M, P, k, s);
2044
- }, P), I(s);
2045
- const $ = Dt(w, P, x.sourceScope), { result: B, part: G } = await d.run("layout", () => ho({ template: k, datasets: M, sourceScope: $ }, x, P, p, s), P);
2046
- y.push(G), zt(b, B.plan, w, P, $), h.push(...B.warnings.map((N) => `${P}: ${N}`));
2178
+ O(s);
2179
+ const u = To({ ...l, signal: s }), f = [...o], d = { ...a };
2180
+ if (f.length === 0) throw new T("config", "缺少报表 ID");
2181
+ const m = f.map((b) => {
2182
+ const P = r(b);
2183
+ return { ...P, pagination: { ...P.pagination } };
2184
+ }), h = u.runSync("validate", () => m.map((b) => _e(
2185
+ b.params ?? (typeof b.template == "function" ? [] : b.template.params) ?? [],
2186
+ d
2187
+ ))), y = [], w = [], p = Te(t), g = [];
2188
+ for (const [b, P] of m.entries()) {
2189
+ O(s);
2190
+ const k = f[b], C = { reportId: k, params: h[b], signal: s }, M = typeof P.template == "function" ? await u.run("query", () => jo(P.template, C, g), k) : P.template;
2191
+ C.params = u.runSync("validate", () => _e(P.params ?? M.params ?? [], C.params), k);
2192
+ const $ = await u.run("query", () => Ko(P, C, k, (ve, rr) => c?.(ve, rr, b)), k), B = _t(b, k, P.sourceScope), K = u.runMaybeAsync("validate", () => (Ao($, k), t.onDatasets?.(k, $, M), Lo({ template: M, datasets: $, sourceScope: B }, P, k, t, s)), k), { part: W, owned: J, release: tr } = K instanceof Promise ? await K : K;
2193
+ let be;
2194
+ try {
2195
+ O(s), be = await u.run("layout", () => Ho(W, J, P, k, p, s), k);
2196
+ } finally {
2197
+ tr();
2198
+ }
2199
+ w.push(W), er(y, be.plan, b, k, B), g.push(...be.warnings.map((ve) => `${k}: ${ve}`));
2047
2200
  }
2048
- I(s);
2049
- const S = { schemaVersion: Ce, ...y.some((w) => Fe(w.template)) ? { requiresRecalculation: !0 } : {}, pages: b }, T = d.runSync("validate", () => {
2050
- const w = Oe(S);
2051
- if (!w.ok) throw new C("validate", `渲染计划校验失败:${w.errors.slice(0, 3).map((x) => `${x.path}: ${x.message}`).join("; ")}`);
2052
- return w;
2201
+ O(s);
2202
+ const S = { schemaVersion: Oe, ...w.some((b) => Ke(b.template)) ? { requiresRecalculation: !0 } : {}, pages: y }, R = u.runSync("validate", () => {
2203
+ const b = je(S);
2204
+ if (!b.ok) throw new T("validate", `渲染计划校验失败:${b.errors.slice(0, 3).map((P) => `${P.path}: ${P.message}`).join("; ")}`);
2205
+ return b;
2053
2206
  });
2054
- h.push(...T.warnings.map((w) => `${w.path}: ${w.message}`));
2055
- const R = m.map((w) => ({ ...w, pagination: { ...w.pagination } })), O = { maxPages: t.maxPages, maxCells: t.maxCells, maxChartComponents: t.maxChartComponents };
2207
+ g.push(...R.warnings.map((b) => `${b.path}: ${b.message}`));
2208
+ const E = m.map((b) => ({ ...b, pagination: { ...b.pagination } })), I = { maxPages: t.maxPages, maxCells: t.maxCells, maxChartComponents: t.maxChartComponents }, F = Fo();
2056
2209
  try {
2057
- Ge(S, { parts: y, validationFormulas: R.map((w) => w.pagination?.formula), rebuild: (w, x) => po(w, R, f, O, x) }, R.map((w) => w.pagination));
2210
+ ze(S, { parts: w, validationFormulas: E.map((b) => b.pagination?.formula), rebuild: (b, P) => Bo(b, E, f, I, F, P) }, E.map((b) => b.pagination));
2058
2211
  } catch {
2059
- h.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算");
2212
+ g.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算");
2060
2213
  }
2061
- const F = i ?? t.onWarning ?? ((w) => console.warn("[mach-report]", w));
2062
- for (const w of h)
2063
- I(s), F(w);
2064
- return I(s), S;
2214
+ const x = i ?? t.onWarning ?? ((b) => console.warn("[mach-report]", b));
2215
+ for (const b of g)
2216
+ O(s), x(b);
2217
+ return O(s), S;
2065
2218
  }, {
2066
- getParamDefs: (o) => ur(e, o)
2219
+ getParamDefs: (o) => xr(e, o)
2067
2220
  });
2068
2221
  }
2069
- const wo = /* @__PURE__ */ new Set([8, 9, 10, 12, 13]);
2070
- function yo(e, t) {
2222
+ const Wo = /* @__PURE__ */ new Set([8, 9, 10, 12, 13]);
2223
+ function Go(e, t) {
2071
2224
  const r = Array.isArray(e), n = Object.getPrototypeOf(e);
2072
2225
  if (n !== (r ? Array.prototype : Object.prototype) && !(n === null && !r) || Object.getOwnPropertySymbols(e).length) throw t("input", "快照应为普通 JSON 对象");
2073
2226
  const o = Object.getOwnPropertyNames(e).filter((a) => !(r && a === "length"));
2074
2227
  if (r && (o.length !== e.length || o.some((a, s) => a !== String(s)))) throw t("input", "快照数组应为连续数组");
2075
2228
  return { array: r, keys: o };
2076
2229
  }
2077
- function bo(e) {
2230
+ function Vo(e) {
2078
2231
  if (/^[\u0020-\u007e]*$/.test(e) && !/["\\]/.test(e)) return e.length + 2;
2079
2232
  let t = 2;
2080
2233
  for (let r = 0; r < e.length; r++) {
2081
2234
  const n = e.charCodeAt(r);
2082
- if (n < 32) t += wo.has(n) ? 2 : 6;
2235
+ if (n < 32) t += Wo.has(n) ? 2 : 6;
2083
2236
  else if (n === 34 || n === 92) t += 2;
2084
2237
  else if (n < 128) t++;
2085
2238
  else if (n < 2048) t += 2;
@@ -2090,93 +2243,94 @@ function bo(e) {
2090
2243
  }
2091
2244
  return t;
2092
2245
  }
2093
- function qo(e, t) {
2246
+ function Ma(e, t) {
2094
2247
  const r = t.maxNodes ?? 1e6;
2095
- if (![t.maxBytes, r].every((u) => Number.isSafeInteger(u) && u > 0)) throw t.error("budget", "快照预算应为正安全整数");
2248
+ if (![t.maxBytes, r].every((d) => Number.isSafeInteger(d) && d > 0)) throw t.error("budget", "快照预算应为正安全整数");
2096
2249
  let n = 0, o = 0;
2097
2250
  const a = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
2098
- function i(u) {
2099
- if (u.length + 2 > t.maxBytes - o) throw t.error("budget", "快照超过字节预算");
2100
- const m = s.get(u);
2251
+ function i(d) {
2252
+ if (d.length + 2 > t.maxBytes - o) throw t.error("budget", "快照超过字节预算");
2253
+ const m = s.get(d);
2101
2254
  if (m !== void 0) return m;
2102
- const g = bo(u);
2103
- return u.length <= 256 && s.size < 4096 && s.set(u, g), g;
2255
+ const h = Vo(d);
2256
+ return d.length <= 256 && s.size < 4096 && s.set(d, h), h;
2104
2257
  }
2105
- function c(u) {
2106
- if (o += u, o > t.maxBytes) throw t.error("budget", "快照超过字节预算");
2258
+ function c(d) {
2259
+ if (o += d, o > t.maxBytes) throw t.error("budget", "快照超过字节预算");
2107
2260
  }
2108
- function l(u, m) {
2261
+ function l(d, m) {
2109
2262
  if (++n > r || m > 64) throw t.error("budget", "快照节点或深度超过预算");
2110
- if (n % 1024 === 0 && t.check?.(), typeof u == "string")
2111
- return c(i(u)), u;
2112
- if (u === null || typeof u == "boolean" || typeof u == "number" && Number.isFinite(u))
2113
- return c(String(u).length), typeof u == "number" && Object.is(u, -0) ? 0 : u;
2114
- if (!u || typeof u != "object" || a.has(u)) throw t.error("input", "快照应为无循环的有限 JSON 值");
2115
- return d(u, m);
2116
- }
2117
- function d(u, m) {
2118
- const { array: g, keys: b } = yo(u, t.error);
2119
- a.add(u), c(2);
2120
- const y = g ? [] : {};
2263
+ if (n % 1024 === 0 && t.check?.(), typeof d == "string")
2264
+ return c(i(d)), d;
2265
+ if (d === null || typeof d == "boolean" || typeof d == "number" && Number.isFinite(d))
2266
+ return c(String(d).length), typeof d == "number" && Object.is(d, -0) ? 0 : d;
2267
+ if (!d || typeof d != "object" || a.has(d)) throw t.error("input", "快照应为无循环的有限 JSON 值");
2268
+ return u(d, m);
2269
+ }
2270
+ function u(d, m) {
2271
+ const { array: h, keys: y } = Go(d, t.error);
2272
+ a.add(d), c(2);
2273
+ const w = h ? [] : {};
2121
2274
  let p = 0;
2122
- for (const h of b) {
2123
- const S = Object.getOwnPropertyDescriptor(u, h);
2124
- if (S.get || S.set || !S.enumerable || ["__proto__", "constructor", "prototype"].includes(h)) throw t.error("input", "快照不允许访问器或危险键");
2125
- if (S.value === void 0 && !g) continue;
2126
- c((p++ ? 1 : 0) + (g ? 0 : i(h) + 1));
2127
- const T = l(S.value === void 0 ? null : S.value, m + 1);
2128
- h in y ? Object.defineProperty(y, h, { value: T, enumerable: !0, configurable: !0, writable: !0 }) : y[h] = T;
2275
+ for (const g of y) {
2276
+ const S = Object.getOwnPropertyDescriptor(d, g);
2277
+ if (S.get || S.set || !S.enumerable || ["__proto__", "constructor", "prototype"].includes(g)) throw t.error("input", "快照不允许访问器或危险键");
2278
+ if (S.value === void 0 && !h) continue;
2279
+ c((p++ ? 1 : 0) + (h ? 0 : i(g) + 1));
2280
+ const R = l(S.value === void 0 ? null : S.value, m + 1);
2281
+ g in w ? Object.defineProperty(w, g, { value: R, enumerable: !0, configurable: !0, writable: !0 }) : w[g] = R;
2129
2282
  }
2130
- return a.delete(u), y;
2283
+ return a.delete(d), w;
2131
2284
  }
2132
2285
  t.check?.();
2133
2286
  const f = l(e, 0);
2134
2287
  return t.check?.(), f;
2135
2288
  }
2136
2289
  export {
2137
- Sr as A,
2138
- Go as B,
2139
- Do as C,
2140
- Tr as D,
2290
+ Hr as A,
2291
+ ma as B,
2292
+ da as C,
2293
+ zr as D,
2141
2294
  j as E,
2142
- Ho as F,
2143
- Ao as G,
2144
- Ye as H,
2145
- Lt as I,
2146
- zo as J,
2147
- Sn as K,
2148
- Dt as L,
2149
- Ht as M,
2150
- no as N,
2151
- He as O,
2152
- ne as P,
2153
- oo as Q,
2154
- C as R,
2155
- _o as S,
2295
+ ua as F,
2296
+ aa as G,
2297
+ tt as H,
2298
+ Vt as I,
2299
+ pa as J,
2300
+ Hn as K,
2301
+ _t as L,
2302
+ zt as M,
2303
+ Co as N,
2304
+ We as O,
2305
+ re as P,
2306
+ To as Q,
2307
+ T as R,
2308
+ wa as S,
2309
+ ya as T,
2156
2310
  v as a,
2157
- dn as b,
2158
- Ko as c,
2159
- Jo as d,
2160
- Lo as e,
2161
- On as f,
2162
- It as g,
2163
- hn as h,
2164
- $o as i,
2165
- jo as j,
2166
- No as k,
2311
+ Rn as b,
2312
+ ia as c,
2313
+ ba as d,
2314
+ la as e,
2315
+ Xn as f,
2316
+ Kt as g,
2317
+ Fn as h,
2318
+ ra as i,
2319
+ sa as j,
2320
+ ca as k,
2167
2321
  z as l,
2168
- Wo as m,
2169
- Uo as n,
2170
- Fo as o,
2171
- kt as p,
2172
- Vo as q,
2173
- re as r,
2174
- qo as s,
2175
- Le as t,
2176
- Bo as u,
2177
- so as v,
2178
- Nt as w,
2179
- ao as x,
2180
- yt as y,
2181
- Oo as z
2322
+ ha as m,
2323
+ va as n,
2324
+ oa as o,
2325
+ $t as p,
2326
+ ga as q,
2327
+ te as r,
2328
+ Ma as s,
2329
+ Be as t,
2330
+ fa as u,
2331
+ Eo as v,
2332
+ Gt as w,
2333
+ Ro as x,
2334
+ Pt as y,
2335
+ na as z
2182
2336
  };