@agile-team/mach-report 2.25.0 → 2.25.2

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