@agile-team/mach-report 2.12.0 → 2.13.0

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