@agile-team/mach-report 2.25.1 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +14 -8
  2. package/dist/ExcelBindingWizard-B418l44t.js +1578 -0
  3. package/dist/ExcelBindingWizard-C4FGVsY_.cjs +1 -0
  4. package/dist/{ParamEditor-CGfaweYX.cjs → ParamEditor-BemJE8n8.cjs} +1 -1
  5. package/dist/{ParamEditor-B7YVD28E.js → ParamEditor-XvMtf_XQ.js} +2 -2
  6. package/dist/{ReportBatchPanel-BRJt0TXp.cjs → ReportBatchPanel-CbY4fvXD.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-BTKHtLTW.js → ReportBatchPanel-Ds0R_uXn.js} +37 -37
  8. package/dist/{ReportLabelStudio-BvK_WBke.cjs → ReportLabelStudio-DuTwN5er.cjs} +1 -1
  9. package/dist/{ReportLabelStudio-CZwqyO3t.js → ReportLabelStudio-ZFy79eRv.js} +26 -26
  10. package/dist/ReportParamPanel-Chxu4MTx.cjs +1 -0
  11. package/dist/{ReportParamPanel-DGXzBzl2.js → ReportParamPanel-Czm3OPo_.js} +216 -205
  12. package/dist/ReportPreview-C9c0Rp7Y.js +7380 -0
  13. package/dist/ReportPreview-CIMR4ERo.cjs +6 -0
  14. package/dist/{ReportTemplateLibrary-ClwxhnC0.cjs → ReportTemplateLibrary-C6lByc69.cjs} +1 -1
  15. package/dist/{ReportTemplateLibrary-C7sB0Jay.js → ReportTemplateLibrary-XJVoTDIz.js} +1 -1
  16. package/dist/{RuleEditor-CsDGFaWz.js → RuleEditor-CeNFPeOc.js} +5 -5
  17. package/dist/{RuleEditor-D-OdaGdR.cjs → RuleEditor-gggUkEwB.cjs} +1 -1
  18. package/dist/{TemplateOutlinePanel-DAqR9zQi.cjs → TemplateOutlinePanel-B0e-umq2.cjs} +1 -1
  19. package/dist/{TemplateOutlinePanel-CXOT7d1r.js → TemplateOutlinePanel-BWN4Y9iz.js} +2 -2
  20. package/dist/{TemplateReusePanel-Dcfx3Hba.js → TemplateReusePanel-CR-4OHoU.js} +2 -2
  21. package/dist/{TemplateReusePanel-ygIi-Ajz.cjs → TemplateReusePanel-Cthig1S1.cjs} +1 -1
  22. package/dist/{TemplateReviewPanel-COU8FqPq.js → TemplateReviewPanel-BkWzyNL4.js} +2 -2
  23. package/dist/{TemplateReviewPanel-DyGULVxr.cjs → TemplateReviewPanel-D8o2gDaK.cjs} +1 -1
  24. package/dist/analytics.cjs +1 -1
  25. package/dist/analytics.js +5 -5
  26. package/dist/artifact-integrity.json +106 -102
  27. package/dist/{assets-C4MIvzQ4.js → assets-BFTP-0WR.js} +2 -2
  28. package/dist/{assets-BYdpkTIt.cjs → assets-CZiZhTf2.cjs} +1 -1
  29. package/dist/{auto-D7x7QsWD.js → auto-C7udkeAa.js} +89 -88
  30. package/dist/auto-CXd2E2aZ.cjs +1 -0
  31. package/dist/capabilities-D8UU2clQ.cjs +1 -0
  32. package/dist/{capabilities-CN_kSVjO.js → capabilities-g0a2j9Yy.js} +50 -46
  33. package/dist/{charts-Cjw5AYkg.cjs → charts-D-Vg-ak9.cjs} +1 -1
  34. package/dist/{charts-CxJZ0XaY.js → charts-D48XCefN.js} +1 -1
  35. package/dist/computed-BQgBrma-.cjs +1 -0
  36. package/dist/{computed-f3pOqWLX.js → computed-CH3NYPOW.js} +198 -188
  37. package/dist/{data-bar-Bfh54sT4.js → data-bar-DjOgTLqu.js} +1 -1
  38. package/dist/{dataset-DL83majE.js → dataset-B8oTsC6o.js} +69 -66
  39. package/dist/dataset-D3OsyzG1.cjs +1 -0
  40. package/dist/designer-COuSUxZ1.cjs +2 -0
  41. package/dist/designer-CT4mlrr0.js +7997 -0
  42. package/dist/designer.cjs +1 -1
  43. package/dist/designer.d.cts +83 -4
  44. package/dist/designer.d.ts +83 -4
  45. package/dist/designer.js +4 -4
  46. package/dist/{diagnostic-collector-gB07PHy2.js → diagnostic-collector-C-JBA016.js} +2 -2
  47. package/dist/dom-DgWc-DY1.js +452 -0
  48. package/dist/dom-Fk4NF-gN.cjs +1 -0
  49. package/dist/{encoding-Amq3XrtU.js → encoding-D480EM2r.js} +2 -2
  50. package/dist/{encoding-DRVXs5xm.cjs → encoding-tWc2Wn89.cjs} +1 -1
  51. package/dist/execution-result-7sG_mdcD.cjs +1 -0
  52. package/dist/execution-result-Ba65gieT.js +39 -0
  53. package/dist/{font-loader-p_SyTvqt.cjs → font-loader-BIxme_9g.cjs} +1 -1
  54. package/dist/{font-loader-D4NLIKJL.js → font-loader-CHmEwkHl.js} +1 -1
  55. package/dist/{grid-strokes-DkZEZvcI.js → grid-strokes-DsoICRjZ.js} +1 -1
  56. package/dist/import-range-BwT86Z3j.cjs +1 -0
  57. package/dist/import-range-D9p_blcb.js +98 -0
  58. package/dist/index.cjs +1 -1
  59. package/dist/index.d.cts +1 -1
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.js +25 -25
  62. package/dist/{json-snapshot-CBVWZvyC.js → json-snapshot-BZ0CIQln.js} +1142 -951
  63. package/dist/json-snapshot-DGFeI30h.cjs +2 -0
  64. package/dist/{matrix-b6T291xo.js → matrix-CB9TqTEy.js} +1 -1
  65. package/dist/{matrix-DUYPRL7t.cjs → matrix-CcqYOuq_.cjs} +1 -1
  66. package/dist/{pdf-DU8HelKd.js → pdf-DTR7fAIr.js} +3596 -3517
  67. package/dist/{pdf-C060D5UY.cjs → pdf-d9oJ6V0P.cjs} +49 -49
  68. package/dist/pdf.cjs +1 -1
  69. package/dist/pdf.js +2 -2
  70. package/dist/{plugin-DHe8y5pD.cjs → plugin-B7Bi-1te.cjs} +1 -1
  71. package/dist/{plugin-BdCplNe1.js → plugin-OKDFQFS4.js} +1 -1
  72. package/dist/{prefill-Buy4NJ15.js → prefill-C8fF91JB.js} +3 -3
  73. package/dist/{prefill-Cw4ZYGXZ.cjs → prefill-C_Bf_AMo.cjs} +1 -1
  74. package/dist/{prepared-BlNeOjoO.cjs → prepared-BLhV7vdE.cjs} +1 -1
  75. package/dist/{prepared-CBJ7BkK0.js → prepared-DhgQ0d-h.js} +7 -7
  76. package/dist/protocol-CZ-BILne.cjs +1 -0
  77. package/dist/{protocol-CB19KXGr.js → protocol-DHO91-Jt.js} +3 -3
  78. package/dist/{record-bindings-Cv7lFiof.js → record-bindings-DBrCu6zO.js} +3 -3
  79. package/dist/{record-bindings-B7djSjNs.cjs → record-bindings-KEs-DKCS.cjs} +1 -1
  80. package/dist/region-binding-workflow-FSyIZge8.js +882 -0
  81. package/dist/region-binding-workflow-ikpY1Kbw.cjs +3 -0
  82. package/dist/report-encoding-worker.cjs +1 -1
  83. package/dist/report-encoding-worker.js +1 -1
  84. package/dist/rich-text-layout-BYbIc3eJ.cjs +3 -0
  85. package/dist/rich-text-layout-BtygMWZC.js +96 -0
  86. package/dist/runtime-B5HG8poy.cjs +1 -0
  87. package/dist/runtime-BsvAqz4a.js +204 -0
  88. package/dist/sbom.cdx.json +1 -1
  89. package/dist/server-node.cjs +5 -5
  90. package/dist/server-node.js +2323 -2120
  91. package/dist/server.cjs +1 -1
  92. package/dist/server.d.cts +35 -0
  93. package/dist/server.d.ts +35 -0
  94. package/dist/server.js +340 -328
  95. package/dist/style.css +1 -1
  96. package/dist/{template-catalog-CM6U_RlD.js → template-catalog-BbrN9dgu.js} +5 -5
  97. package/dist/{template-catalog-Cj66M84u.cjs → template-catalog-DDH-5J57.cjs} +1 -1
  98. package/dist/{template-fragments-BDxdCuMD.js → template-fragments-CUTE8-_I.js} +3 -3
  99. package/dist/{template-fragments-DbKdxI1z.cjs → template-fragments-cyAQu7aw.cjs} +1 -1
  100. package/dist/{template-registry-B-AK1oam.cjs → template-registry-D24Z8aQf.cjs} +1 -1
  101. package/dist/{template-registry-DeVgwEZj.js → template-registry-PSuLsnyq.js} +4 -4
  102. package/dist/{template-serialization-CqQY4zDg.cjs → template-serialization-BOUidUlh.cjs} +1 -1
  103. package/dist/{template-serialization-CWmHq7lX.js → template-serialization-BgGWYV_1.js} +1 -1
  104. package/dist/{textwrap-BywMBMXM.js → textwrap-Bt_tnI6V.js} +1 -1
  105. package/dist/vue/async.d.cts +46 -3
  106. package/dist/vue/async.d.ts +46 -3
  107. package/dist/vue/index.d.cts +217 -25
  108. package/dist/vue/index.d.ts +217 -25
  109. package/dist/vue-async.cjs +1 -1
  110. package/dist/vue-async.js +3 -3
  111. package/dist/vue.cjs +1 -1
  112. package/dist/vue.js +434 -202
  113. package/dist/workbook-session-BJfZVp4q.cjs +29 -0
  114. package/dist/{workbook-session-B6hRjTyX.js → workbook-session-DRnMjIFK.js} +2377 -2350
  115. package/dist/worker.cjs +1 -1
  116. package/dist/worker.js +4 -4
  117. package/dist/xlsx.cjs +1 -1
  118. package/dist/xlsx.d.cts +27 -2
  119. package/dist/xlsx.d.ts +27 -2
  120. package/dist/xlsx.js +15 -15
  121. package/package.json +1 -1
  122. package/dist/ExcelBindingWizard-bs3F4dD8.js +0 -1486
  123. package/dist/ExcelBindingWizard-jSdjBtWw.cjs +0 -1
  124. package/dist/ReportParamPanel-B27IGJjk.cjs +0 -1
  125. package/dist/ReportPreview-CnxaDTCO.js +0 -7170
  126. package/dist/ReportPreview-DqFBcsJQ.cjs +0 -6
  127. package/dist/auto-mPK9W0y5.cjs +0 -1
  128. package/dist/capabilities-D4nfhcvB.cjs +0 -1
  129. package/dist/computed-DK6BruFz.cjs +0 -1
  130. package/dist/dataset-IrlXbUvh.cjs +0 -1
  131. package/dist/designer-B597ZdC0.js +0 -7595
  132. package/dist/designer-DFIdv_n7.cjs +0 -2
  133. package/dist/dom-CXWMmwh-.cjs +0 -1
  134. package/dist/dom-DxdCMLzs.js +0 -452
  135. package/dist/json-snapshot-DCFEtfFw.cjs +0 -2
  136. package/dist/protocol-BU_4sXP0.cjs +0 -1
  137. package/dist/region-binding-workflow-EYxvUYJ-.js +0 -977
  138. package/dist/region-binding-workflow-NdkMSFCh.cjs +0 -3
  139. package/dist/rich-text-layout-Ch_N0Ubu.js +0 -52
  140. package/dist/rich-text-layout-yJGuThtC.cjs +0 -3
  141. package/dist/runtime-B5d_lQNQ.js +0 -227
  142. package/dist/runtime-BRx8Agqr.cjs +0 -1
  143. package/dist/workbook-session-BclW7KKH.cjs +0 -29
@@ -0,0 +1,882 @@
1
+ import { v as O } from "./dataset-B8oTsC6o.js";
2
+ import { v as G, e as V, p as z } from "./template-registry-PSuLsnyq.js";
3
+ import { r as F } from "./diagnostic-collector-C-JBA016.js";
4
+ import { p as d, r as $, c as I } from "./import-range-D9p_blcb.js";
5
+ function B(e) {
6
+ return JSON.parse(JSON.stringify(e));
7
+ }
8
+ function se(e, t) {
9
+ const o = e.template.pages.slice(t.pageStart, t.pageStart + t.pageCount), r = o[0];
10
+ if (!r) throw new Error(`工作表 ${t.name} 没有可绑定页面`);
11
+ const n = /* @__PURE__ */ new Map();
12
+ let s = [];
13
+ for (const i of o)
14
+ for (const a of i.components) {
15
+ if (a.kind === "list" || !a.grid || a.meta?.xlsxSheet !== t.name) continue;
16
+ const c = d(String(a.meta.xlsxRange)), l = a.grid;
17
+ s = l.colWidthsMm ?? [], l.cells.forEach((f, m) => n.set(c.top + m, { cells: B(f), height: l.rowHeightsMm?.[m] ?? 6 }));
18
+ }
19
+ if (!s.length || !n.size) throw new Error(`工作表 ${t.name} 缺少导入几何元数据`);
20
+ return { rows: n, widths: [...s], page: r, range: d(t.range) };
21
+ }
22
+ function K(e, t, o) {
23
+ const r = [], n = [];
24
+ for (let s = t; s <= o; s++) {
25
+ const i = e.rows.get(s);
26
+ if (!i) throw new Error(`导入模板缺少第 ${s} 行`);
27
+ for (const a of i.cells)
28
+ if (a && s + (a.rowSpan ?? 1) - 1 > o) throw new Error(`第 ${s} 行合并区域跨越绑定边界,请调整 header/detail 范围`);
29
+ r.push(B(i.cells)), n.push(i.height);
30
+ }
31
+ return { cells: r, rowHeightsMm: n, colWidthsMm: e.widths, paddingMm: 0.25 };
32
+ }
33
+ function ae(e, t) {
34
+ const o = d(e.header), r = e.detail ? d(e.detail) : { ...t.range, top: o.bottom + 1 };
35
+ for (const n of [o, r])
36
+ if (n.left !== t.range.left || n.right !== t.range.right || n.top < t.range.top || n.bottom > t.range.bottom || n.top > n.bottom) throw new Error("绑定区域必须位于导入选区内并覆盖其完整列宽");
37
+ if (r.top !== o.bottom + 1) throw new Error("detail 应紧接 header,避免静态内容被隐式删除");
38
+ if (e.columns.length !== t.widths.length) throw new Error("columns 应逐列映射整个选区;不能自动猜测业务字段");
39
+ return ie(t, [o.top, o.bottom + 1, r.bottom + 1]), { header: o, detail: r };
40
+ }
41
+ function ie(e, t) {
42
+ for (const [o, r] of e.rows) for (const n of r.cells) {
43
+ const s = o + (n?.rowSpan ?? 1);
44
+ if (t.some((i) => o < i && s > i)) throw new Error(`第 ${o} 行合并区域跨越绑定边界,请调整 header/detail 范围`);
45
+ }
46
+ }
47
+ function le(e, t) {
48
+ const o = [];
49
+ for (const r of F(e, t.reduce((n, s) => n + s, 0), 100).cells)
50
+ for (let n = r.ci; n < Math.min(t.length, r.ci + (r.cell.colSpan ?? 1)); n++) o[n] = r.cell;
51
+ return o;
52
+ }
53
+ function ce(e, t, o, r) {
54
+ if (t) return t;
55
+ const n = e?.numberFormat;
56
+ if (!n || n === "General") return;
57
+ const s = /^(#,##)?0(?:\.(0+))?(%)?$/.exec(n);
58
+ if (s) {
59
+ const i = s[2]?.length ?? 0;
60
+ if (i <= 100) return s[3] ? { kind: "percent", digits: i } : { kind: "number", digits: i, ...s[1] ? { thousands: !0 } : {} };
61
+ }
62
+ r.push(`${o}: Excel 数字格式 ${n} 未自动套用到动态数据,请在 columns 中显式声明 format`);
63
+ }
64
+ function fe(e, t, o, r, n) {
65
+ const s = le(t, r), i = F(o, r.reduce((f, m) => f + m, 0), 20).cells;
66
+ if (i.some(({ cell: f }) => (f.colSpan ?? 1) !== 1 || (f.rowSpan ?? 1) !== 1)) throw new Error("动态明细样例行不能包含合并格;合并表头可以保留");
67
+ const a = new Map(i.map((f) => [f.ci, f.cell])), c = /* @__PURE__ */ new Set(), l = e.columns.map((f, m) => {
68
+ const g = typeof f == "string" ? { field: f } : f;
69
+ if (!g || typeof g.field != "string" || !g.field.trim() || c.has(g.field)) throw new Error(`columns[${m}] 需要唯一的非空 field`);
70
+ c.add(g.field);
71
+ const h = s[m]?.text ?? g.field, p = a.get(m), u = e.inferSampleFormats === !1 ? g.format : ce(p, g.format, g.field, n);
72
+ return { ...g, ...u ? { format: u } : {}, header: g.header ?? h, widthMm: r[m], style: { ...p?.style, ...g.style }, ...g.semanticRole && !g.align ? { align: "auto" } : {}, ...g.editable === void 0 && p?.editable === !1 ? { editable: !1 } : {} };
73
+ });
74
+ return ge(e, s, l), l;
75
+ }
76
+ function ge(e, t, o) {
77
+ const r = /* @__PURE__ */ new Map();
78
+ e.columns.forEach((n, s) => {
79
+ const i = t[s];
80
+ if (!i || typeof n == "string") return;
81
+ const a = r.get(i) ?? { style: {} };
82
+ if (n.header !== void 0) {
83
+ if (a.text !== void 0 && a.text !== n.header) throw new Error("同一合并表头不能配置不同 header");
84
+ a.text = n.header;
85
+ }
86
+ he(a.style, { ...n.headerAlign ? { align: n.headerAlign } : {}, ...n.headerStyle }), r.set(i, a);
87
+ });
88
+ for (const [n, s] of r)
89
+ s.text !== void 0 && Object.assign(n, { text: s.text, rawText: s.text, value: s.text }), n.style = { ...n.style, ...s.style }, t.forEach((i, a) => {
90
+ i === n && (s.text !== void 0 && (o[a].header = s.text), s.style.align !== void 0 && (o[a].headerAlign = s.style.align));
91
+ });
92
+ }
93
+ function he(e, t) {
94
+ for (const o of Object.keys(t))
95
+ if (t[o] !== void 0) {
96
+ if (e[o] !== void 0 && e[o] !== t[o]) throw new Error(`同一合并表头不能配置不同 ${o}`);
97
+ Object.assign(e, { [o]: t[o] });
98
+ }
99
+ }
100
+ function me(e, t) {
101
+ const o = e.page, r = t.rowHeightsMm.reduce((n, s) => n + s, 0);
102
+ return { ...o, heightMm: Math.max(o.heightMm, r + (o.marginTopMm ?? 0) + (o.marginBottomMm ?? 0)), components: [{ kind: "rect", leftMm: o.marginLeftMm ?? 0, topMm: o.marginTopMm ?? 0, widthMm: e.widths.reduce((n, s) => n + s, 0), heightMm: r, grid: t }] };
103
+ }
104
+ function de(e, t, o, r) {
105
+ const n = se(e, t), { header: s, detail: i } = ae(o, n), a = K(n, n.range.top, s.bottom), c = K(n, i.top, i.top), l = { ...n.page, components: [] }, f = {
106
+ kind: "list",
107
+ id: `bound:${t.name}`,
108
+ dataset: o.dataset ?? "detail",
109
+ title: t.name,
110
+ leftMm: l.marginLeftMm ?? 0,
111
+ topMm: l.marginTopMm ?? 0,
112
+ widthMm: n.widths.reduce((m, g) => m + g, 0),
113
+ layout: l.layout ?? "page",
114
+ headerGrid: a,
115
+ columns: fe(o, a, c, n.widths, r),
116
+ rowHeightMm: c.rowHeightsMm[0],
117
+ headerEveryPage: !0,
118
+ align: "auto",
119
+ paddingMm: 0.25,
120
+ ...o.rowKey ? { rowKey: o.rowKey } : {},
121
+ ...o.revisionField ? { revisionField: o.revisionField } : {},
122
+ ...o.sourceTokenField ? { sourceTokenField: o.sourceTokenField } : {},
123
+ ...o.groupBy ? { groupBy: o.groupBy } : {},
124
+ ...o.grandTotal === void 0 ? {} : { grandTotal: o.grandTotal }
125
+ };
126
+ return l.components.push(f), i.bottom === n.range.bottom ? [l] : (r.push(`${t.name}: 明细区域后的静态内容保留为后续独立页面,不推断动态页脚定位`), [l, me(n, K(n, i.bottom + 1, n.range.bottom))]);
127
+ }
128
+ function pe(e, t) {
129
+ const o = G(e.template);
130
+ if (!o.ok) throw new Error(`导入模板无效:${o.errors[0]?.message}`);
131
+ if (!t.length) throw new Error("至少需要一个 Excel 业务绑定");
132
+ const r = /* @__PURE__ */ new Map();
133
+ for (const c of t) {
134
+ if (!e.sheets.some((l) => l.name === c.sheet) || r.has(c.sheet)) throw new Error(`绑定工作表不存在或重复:${c.sheet}`);
135
+ r.set(c.sheet, c);
136
+ }
137
+ const n = [...e.warnings], s = e.sheets.flatMap((c) => {
138
+ const l = r.get(c.name);
139
+ return l ? de(e, c, l, n) : B(e.template.pages.slice(c.pageStart, c.pageStart + c.pageCount));
140
+ }), i = { ...B(e.template), pages: s }, a = G(i);
141
+ if (!a.ok) throw new Error(`业务模板无效:${a.errors[0]?.path} ${a.errors[0]?.message}`);
142
+ return { template: i, warnings: n };
143
+ }
144
+ function q(e) {
145
+ const t = e.semanticRole ?? (e.type === "number" || e.type === "decimal" ? "measure" : e.type === "date" ? "date" : "text");
146
+ return {
147
+ field: e.field,
148
+ semanticRole: t,
149
+ editable: !1,
150
+ ...e.type === "number" && e.digits !== void 0 ? { format: { kind: "number", digits: e.digits } } : {},
151
+ ...e.type === "date" ? { format: { kind: "date", pattern: "YYYY-MM-DD" } } : {}
152
+ };
153
+ }
154
+ function we(e) {
155
+ return e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e);
156
+ }
157
+ function H(e, t = 0) {
158
+ if (we(e)) return;
159
+ if (!e || typeof e != "object" || t > 16)
160
+ throw new Error("绑定会话元数据只允许有限深度的普通 JSON 值");
161
+ const o = Object.getPrototypeOf(e);
162
+ if (Array.isArray(e) ? o !== Array.prototype : o !== Object.prototype && o !== null)
163
+ throw new Error("绑定会话不能包含特殊对象原型");
164
+ if (Object.getOwnPropertySymbols(e).length)
165
+ throw new Error("绑定会话不能包含 Symbol");
166
+ if (Array.isArray(e) && Object.keys(e).length !== e.length)
167
+ throw new Error("绑定会话数组不能包含空位或额外属性");
168
+ for (const [r, n] of Object.entries(
169
+ Object.getOwnPropertyDescriptors(e)
170
+ ))
171
+ if (!(Array.isArray(e) && r === "length")) {
172
+ if (["__proto__", "prototype", "constructor"].includes(r) || n.get || n.set || !n.enumerable)
173
+ throw new Error("绑定会话包含不安全元数据");
174
+ H(n.value, t + 1);
175
+ }
176
+ }
177
+ function ue(e, t) {
178
+ return ye(e, t);
179
+ }
180
+ function ye(e, t) {
181
+ const o = e.sheets.find((c) => c.name === t.sheet);
182
+ if (!o) return [];
183
+ const r = d(t.regions.header), n = d(t.regions.detail), s = [r.top, r.bottom + 1, n.bottom + 1], i = [], a = /* @__PURE__ */ new Set();
184
+ for (const c of e.template.pages.slice(
185
+ o.pageStart,
186
+ o.pageStart + o.pageCount
187
+ ))
188
+ for (const l of c.components) {
189
+ if (l.kind === "list" || !l.grid || l.meta?.xlsxSheet !== t.sheet)
190
+ continue;
191
+ const f = d(String(l.meta.xlsxRange));
192
+ l.grid.cells.forEach((m, g) => {
193
+ const h = f.top + g;
194
+ for (const p of m) {
195
+ const u = s.some(
196
+ (x) => h < x && h + (p?.rowSpan ?? 1) > x
197
+ ), M = h === n.top && ((p?.rowSpan ?? 1) > 1 || (p?.colSpan ?? 1) > 1);
198
+ if (!u && !M) continue;
199
+ const E = u ? "$.recipe.regions" : "$.recipe.regions.detail";
200
+ a.has(E) || (a.add(E), i.push({
201
+ path: E,
202
+ code: "region",
203
+ message: u ? `第 ${h} 行合并区域跨越绑定边界,请选择完整合并区域` : "动态明细原型行不能包含合并格"
204
+ }));
205
+ }
206
+ });
207
+ }
208
+ return i;
209
+ }
210
+ function Q(e) {
211
+ return JSON.parse(JSON.stringify(e));
212
+ }
213
+ function C(e) {
214
+ return e instanceof Error ? e.message : String(e);
215
+ }
216
+ function w(e, t, o, r) {
217
+ e.push({ path: t, code: o, message: r });
218
+ }
219
+ function U(e, t) {
220
+ return { fields: e.fields, ...t ? { rowKey: t } : {} };
221
+ }
222
+ function Ee(e, t) {
223
+ const o = /* @__PURE__ */ new Set();
224
+ for (const [r, n] of e.entries()) {
225
+ const s = `$.datasets[${r}]`;
226
+ if (!n || typeof n.id != "string" || !n.id.trim() || o.has(n.id)) {
227
+ w(t, s, "schema", "数据集标识应非空且唯一");
228
+ continue;
229
+ }
230
+ o.add(n.id);
231
+ try {
232
+ O([], U(n, n.rowKey));
233
+ for (const [i, a] of n.fields.entries())
234
+ a.digits !== void 0 && (!Number.isInteger(a.digits) || a.digits < 0 || a.digits > 100) && w(
235
+ t,
236
+ `${s}.fields[${i}].digits`,
237
+ "schema",
238
+ "显示精度应为 0–100 的整数"
239
+ );
240
+ } catch (i) {
241
+ w(t, s, "schema", C(i));
242
+ }
243
+ }
244
+ }
245
+ function Me(e, t, o) {
246
+ const r = e.sheets.find((a) => a.name === t.sheet);
247
+ if (!r) {
248
+ w(o, "$.recipe.sheet", "source", "指定的工作表不存在");
249
+ return;
250
+ }
251
+ let n;
252
+ try {
253
+ n = d(r.range);
254
+ } catch (a) {
255
+ w(o, "$.source.sheets", "source", C(a));
256
+ return;
257
+ }
258
+ const s = /* @__PURE__ */ new Map();
259
+ for (const a of ["title", "header", "detail", "footer"]) {
260
+ const c = t.regions?.[a];
261
+ if (!(!c && (a === "title" || a === "footer")))
262
+ try {
263
+ const l = d(c ?? "");
264
+ if (l.left !== n.left || l.right !== n.right || l.top < n.top || l.bottom > n.bottom)
265
+ throw new Error("区域必须覆盖选区完整列宽,并位于原始工作表内");
266
+ s.set(a, l);
267
+ } catch (l) {
268
+ w(o, `$.recipe.regions.${a}`, "region", C(l));
269
+ }
270
+ }
271
+ const i = [...s.values()];
272
+ i.length && (i[0].top !== n.top || i[i.length - 1].bottom !== n.bottom) && w(
273
+ o,
274
+ "$.recipe.regions",
275
+ "region",
276
+ "标题、表头、明细、页脚应完整覆盖来源,不能隐式删除静态内容"
277
+ );
278
+ for (let a = 1; a < i.length; a++)
279
+ i[a].top !== i[a - 1].bottom + 1 && w(o, "$.recipe.regions", "region", "各区域应顺序相邻且不重叠");
280
+ }
281
+ function xe(e, t, o, r) {
282
+ if (!Array.isArray(e.fields) || e.fields.length !== o)
283
+ return w(
284
+ r,
285
+ "$.recipe.fields",
286
+ "mapping",
287
+ "每个物理 Excel 列必须显式绑定一个业务字段"
288
+ ), 0;
289
+ const n = new Set(t.fields.map((a) => a.field)), s = /* @__PURE__ */ new Set();
290
+ let i = 0;
291
+ e.fields.forEach((a, c) => {
292
+ typeof a != "string" || !n.has(a) ? w(
293
+ r,
294
+ `$.recipe.fields[${c}]`,
295
+ "mapping",
296
+ "请选择契约中已声明的字段"
297
+ ) : s.has(a) ? w(
298
+ r,
299
+ `$.recipe.fields[${c}]`,
300
+ "mapping",
301
+ "同一业务字段不能重复绑定物理列"
302
+ ) : (i++, s.add(a));
303
+ });
304
+ try {
305
+ if (!e.rowKey)
306
+ throw new Error("请明确选择稳定业务主键,不能使用展示行号");
307
+ const a = U(t, e.rowKey), c = O(t.samples ?? [], a, {
308
+ path: `$.datasets.${t.id}.samples`,
309
+ maxRows: 100,
310
+ maxCells: 2e5,
311
+ maxIssues: 30
312
+ });
313
+ for (const l of c.issues)
314
+ w(
315
+ r,
316
+ l.path,
317
+ l.code === "row-key" ? "row-key" : "schema",
318
+ l.message
319
+ );
320
+ } catch (a) {
321
+ w(r, "$.recipe.rowKey", "row-key", C(a));
322
+ }
323
+ return i;
324
+ }
325
+ function be(e, t) {
326
+ const o = [];
327
+ return !t || t.version !== "1.0" ? [
328
+ {
329
+ path: "$.recipe.version",
330
+ code: "schema",
331
+ message: "不支持的 Excel 绑定配置版本"
332
+ }
333
+ ] : (Me(e, t, o), o.length || o.push(...ue(e, t)), o);
334
+ }
335
+ function $e(e, t, o) {
336
+ const r = [];
337
+ if (!t || t.version !== "1.0")
338
+ return {
339
+ ok: !1,
340
+ issues: [
341
+ {
342
+ path: "$.recipe.version",
343
+ code: "schema",
344
+ message: "不支持的 Excel 绑定配置版本"
345
+ }
346
+ ],
347
+ mapped: 0,
348
+ total: 0
349
+ };
350
+ Ee(o, r);
351
+ const n = e.sheets.find((a) => a.name === t.sheet)?.columnCount ?? 0, s = o.find((a) => a.id === t.dataset);
352
+ let i = 0;
353
+ return s ? r.some((a) => a.code === "schema") || (i = xe(t, s, n, r)) : w(
354
+ r,
355
+ "$.recipe.dataset",
356
+ "schema",
357
+ "请明确选择宿主提供的数据集契约"
358
+ ), { ok: r.length === 0, issues: r, mapped: i, total: n };
359
+ }
360
+ function Se(e, t, o) {
361
+ const r = $e(e, t, o);
362
+ if (!t || t.version !== "1.0") return r;
363
+ const n = [
364
+ ...be(e, t),
365
+ ...r.issues
366
+ ];
367
+ return { ...r, ok: n.length === 0, issues: n };
368
+ }
369
+ function Ve(e, t, o, r) {
370
+ const n = Se(e, t, o);
371
+ if (!n.ok)
372
+ throw new Error(
373
+ n.issues.map((f) => `${f.path}: ${f.message}`).join(`
374
+ `)
375
+ );
376
+ const s = e.sheets.find((f) => f.name === t.sheet), i = {
377
+ ...e,
378
+ sheets: [{ ...s, pageStart: 0 }],
379
+ template: {
380
+ ...e.template,
381
+ pages: e.template.pages.slice(
382
+ s.pageStart,
383
+ s.pageStart + s.pageCount
384
+ )
385
+ }
386
+ }, a = new Map(
387
+ o.find((f) => f.id === t.dataset).fields.map((f) => [f.field, f])
388
+ ), c = {
389
+ sheet: t.sheet,
390
+ dataset: t.dataset,
391
+ header: t.regions.header,
392
+ detail: t.regions.detail,
393
+ rowKey: t.rowKey,
394
+ inferSampleFormats: !1,
395
+ columns: t.fields.map((f) => q(a.get(f)))
396
+ }, l = pe(i, [c]);
397
+ return {
398
+ document: V({ ...r, template: l.template }),
399
+ recipe: Q(t),
400
+ warnings: l.warnings
401
+ };
402
+ }
403
+ function Re(e, t) {
404
+ if (e?.version !== "1.0" || !Array.isArray(e.fields) || e.fields.length > 16384 || e.fields.some((o) => typeof o != "string"))
405
+ throw new Error("Excel 绑定配置无效");
406
+ if (typeof e.dataset != "string" || typeof e.rowKey != "string" || !e.regions || typeof t?.id != "string" || typeof t.name != "string")
407
+ throw new Error("Excel 绑定参数或标识无效");
408
+ for (const o of Object.values(e.regions))
409
+ o !== "" && d(o);
410
+ }
411
+ function ve(e) {
412
+ for (const t of e.sheets)
413
+ if (d(t.range), typeof t.name != "string" || ![t.index, t.rowCount, t.columnCount, t.pageCount].every(
414
+ (o) => Number.isInteger(o) && o > 0
415
+ ) || !Number.isInteger(t.pageStart) || t.pageStart < 0 || t.pageStart + t.pageCount > e.template.pages.length)
416
+ throw new Error("Excel 绑定工作表几何元数据无效");
417
+ }
418
+ function ke(e, t, o) {
419
+ if (H({
420
+ sheets: e.sheets,
421
+ warnings: e.warnings,
422
+ recipe: t,
423
+ identity: o
424
+ }), !Array.isArray(e.sheets) || !e.sheets.length || e.sheets.length > 32 || !Array.isArray(e.warnings) || e.warnings.some((r) => typeof r != "string"))
425
+ throw new Error("Excel 绑定来源元数据无效");
426
+ if (Re(t, o), !e.sheets.some((r) => r.name === t.sheet))
427
+ throw new Error("Excel 绑定工作表不存在");
428
+ ve(e);
429
+ }
430
+ function Ae(e, t, o) {
431
+ return ke(e, t, o), z({
432
+ schemaVersion: "1.0",
433
+ id: o.id,
434
+ name: o.name,
435
+ template: e.template
436
+ }), Q({ version: "1.0", source: e, recipe: t, identity: o });
437
+ }
438
+ function ze(e) {
439
+ if (typeof e == "string" && e.length > 1e7)
440
+ throw new Error("Excel 绑定会话超过 1000 万字符上限");
441
+ const t = typeof e == "string" ? JSON.parse(e) : e;
442
+ if (!t || t.version !== "1.0" || t.recipe?.version !== "1.0" || !Array.isArray(t.source?.sheets))
443
+ throw new Error("Excel 绑定会话结构或版本无效");
444
+ return Ae(
445
+ t.source,
446
+ t.recipe,
447
+ t.identity
448
+ );
449
+ }
450
+ function qe(e, t, o, r) {
451
+ const n = e.sheets.find((c) => c.name === t);
452
+ if (!n) throw new Error("工作表不存在");
453
+ const s = d(n.range), i = Math.min(o, r), a = Math.max(o, r);
454
+ if (!Number.isInteger(i) || !Number.isInteger(a) || i < s.top || a > s.bottom)
455
+ throw new Error("选中行超出来源区域");
456
+ return $({ ...s, top: i, bottom: a });
457
+ }
458
+ function P(e, t, o) {
459
+ const r = e ?? t;
460
+ if (!Number.isInteger(r) || r < 1 || r > o)
461
+ throw new Error(`预览窗口大小应为 1–${o} 的整数`);
462
+ return r;
463
+ }
464
+ function L(e, t, o) {
465
+ const r = e ?? t;
466
+ if (!Number.isInteger(r)) throw new Error("预览起点应为整数");
467
+ return Math.max(t, Math.min(o, r));
468
+ }
469
+ function Qe(e, t, o = {}) {
470
+ const r = e.sheets.find((g) => g.name === t);
471
+ if (!r) throw new Error("指定的工作表不存在");
472
+ const n = d(r.range), s = L(o.row, n.top, n.bottom), i = L(o.column, n.left, n.right), a = Math.min(
473
+ n.bottom,
474
+ s + P(o.rows, 24, 100) - 1
475
+ ), c = Math.min(
476
+ n.right,
477
+ i + P(o.columns, 12, 32) - 1
478
+ ), l = Array.from({ length: a - s + 1 }, (g, h) => ({
479
+ row: s + h,
480
+ cells: []
481
+ })), f = /* @__PURE__ */ new Set();
482
+ for (const g of e.template.pages.slice(
483
+ r.pageStart,
484
+ r.pageStart + r.pageCount
485
+ ))
486
+ for (const h of g.components) {
487
+ if (h.kind === "list" || !h.grid || h.meta?.xlsxSheet !== t)
488
+ continue;
489
+ const p = d(String(h.meta.xlsxRange));
490
+ if (p.bottom < s || p.top > a) continue;
491
+ const u = F(
492
+ h.grid,
493
+ h.widthMm,
494
+ h.heightMm
495
+ );
496
+ for (const M of u.cells)
497
+ m(M.cell, p.top + M.ri, p.left + M.ci);
498
+ }
499
+ for (const g of l) {
500
+ for (let h = i; h <= c; h++)
501
+ f.has(`${g.row}:${h}`) || g.cells.push({
502
+ address: `${I(h)}${g.row}`,
503
+ row: g.row,
504
+ column: h,
505
+ text: "",
506
+ rowSpan: 1,
507
+ colSpan: 1,
508
+ continued: !1
509
+ });
510
+ g.cells.sort((h, p) => h.column - p.column);
511
+ }
512
+ return {
513
+ top: s,
514
+ bottom: a,
515
+ left: i,
516
+ right: c,
517
+ source: n,
518
+ rows: l,
519
+ columns: Array.from({ length: c - i + 1 }, (g, h) => ({
520
+ column: i + h,
521
+ name: I(i + h)
522
+ }))
523
+ };
524
+ function m(g, h, p) {
525
+ const u = h + (g.rowSpan ?? 1) - 1, M = p + (g.colSpan ?? 1) - 1;
526
+ if (u < s || h > a || M < i || p > c)
527
+ return;
528
+ const E = Math.max(s, h), x = Math.max(i, p), _ = Math.min(a, u) - E + 1, D = Math.min(c, M) - x + 1;
529
+ l[E - s].cells.push({
530
+ address: `${I(p)}${h}`,
531
+ row: E,
532
+ column: x,
533
+ text: g.text ?? g.rawText ?? String(g.value ?? ""),
534
+ rowSpan: _,
535
+ colSpan: D,
536
+ continued: E !== h || x !== p,
537
+ style: g.style
538
+ });
539
+ for (let T = E; T < E + _; T++)
540
+ for (let N = x; N < x + D; N++)
541
+ f.add(`${T}:${N}`);
542
+ }
543
+ }
544
+ function S(e) {
545
+ return JSON.parse(JSON.stringify(e));
546
+ }
547
+ function X(e, t) {
548
+ const o = e.sheets.find((a) => a.name === t);
549
+ if (!o) throw new Error("指定的工作表不存在");
550
+ const r = e.template.pages.slice(o.pageStart, o.pageStart + o.pageCount), n = r[0];
551
+ if (!n) throw new Error("工作表没有可绑定的页面");
552
+ const s = { page: n, range: d(o.range), widths: [], heights: /* @__PURE__ */ new Map(), cells: [], cellsByRow: /* @__PURE__ */ new Map(), topOffsets: /* @__PURE__ */ new Map() };
553
+ for (const a of r) for (const c of a.components) {
554
+ if (c.kind === "list" || !c.grid || c.meta?.xlsxSheet !== t) continue;
555
+ const l = d(String(c.meta.xlsxRange));
556
+ s.widths.length || (s.widths = [...c.grid.colWidthsMm ?? []]), c.grid.cells.forEach((f, m) => s.heights.set(l.top + m, c.grid.rowHeightsMm?.[m] ?? 6));
557
+ for (const f of F(c.grid, c.widthMm, c.heightMm).cells) {
558
+ const m = l.top + f.ri, g = l.left + f.ci;
559
+ s.cells.push({ top: m, left: g, bottom: m + (f.cell.rowSpan ?? 1) - 1, right: g + (f.cell.colSpan ?? 1) - 1, cell: f.cell });
560
+ }
561
+ }
562
+ if (s.widths.length !== s.range.right - s.range.left + 1 || s.heights.size !== s.range.bottom - s.range.top + 1)
563
+ throw new Error("来源工作表几何元数据不完整");
564
+ let i = 0;
565
+ for (let a = s.range.top; a <= s.range.bottom; a++)
566
+ s.topOffsets.set(a, i), i += s.heights.get(a);
567
+ s.topOffsets.set(s.range.bottom + 1, i);
568
+ for (const a of s.cells) for (let c = a.top; c <= a.bottom; c++) {
569
+ const l = s.cellsByRow.get(c) ?? [];
570
+ l.push(a), s.cellsByRow.set(c, l);
571
+ }
572
+ return s;
573
+ }
574
+ function Z(e, t) {
575
+ return e.left <= t.right && t.left <= e.right && e.top <= t.bottom && t.top <= e.bottom;
576
+ }
577
+ function R(e, t) {
578
+ return e.top <= t.top && e.bottom >= t.bottom && e.left <= t.left && e.right >= t.right;
579
+ }
580
+ function ee(e, t) {
581
+ return e.widths.slice(t.left - e.range.left, t.right - e.range.left + 1).reduce((o, r) => o + r, 0);
582
+ }
583
+ function A(e, t) {
584
+ return (e.topOffsets.get(t.bottom + 1) ?? 0) - (e.topOffsets.get(t.top) ?? 0);
585
+ }
586
+ function k(e, t) {
587
+ const o = /* @__PURE__ */ new Set();
588
+ for (let r = t.top; r <= t.bottom; r++) for (const n of e.cellsByRow.get(r) ?? []) Z(n, t) && o.add(n);
589
+ return [...o];
590
+ }
591
+ function te(e, t) {
592
+ for (const o of k(e, t)) if (!R(t, o)) throw new Error(`合并区域 ${$(o)} 跨越选区 ${$(t)}`);
593
+ }
594
+ function j(e, t, o = []) {
595
+ const r = k(e, t);
596
+ for (const a of r) if (!R(t, a)) throw new Error(`合并区域 ${$(a)} 跨越选区 ${$(t)}`);
597
+ const n = [], s = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
598
+ for (const a of r)
599
+ if (!o.some((c) => R(c, a))) {
600
+ s.set(`${a.top}:${a.left}`, a);
601
+ for (let c = a.top; c <= a.bottom; c++) for (let l = a.left; l <= a.right; l++) i.add(`${c}:${l}`);
602
+ }
603
+ for (let a = t.top; a <= t.bottom; a++) {
604
+ const c = [];
605
+ for (let l = t.left; l <= t.right; l++) {
606
+ const f = s.get(`${a}:${l}`);
607
+ f ? (c.push(S(f.cell)), l = f.right) : i.has(`${a}:${l}`) || c.push(null);
608
+ }
609
+ n.push(c);
610
+ }
611
+ return { cells: n, colWidthsMm: e.widths.slice(t.left - e.range.left, t.right - e.range.left + 1), rowHeightsMm: Array.from({ length: t.bottom - t.top + 1 }, (a, c) => e.heights.get(t.top + c)), paddingMm: 0.25 };
612
+ }
613
+ function v(e) {
614
+ const t = d(e.range);
615
+ return e.headerRange ? { ...t, top: d(e.headerRange).top } : t;
616
+ }
617
+ function J(e, t) {
618
+ return (e.page.marginTopMm ?? 0) + (e.topOffsets.get(t) ?? 0);
619
+ }
620
+ function oe(e, t) {
621
+ return { xlsxFlow: { version: "1.0", columnStart: t.left - e.range.left } };
622
+ }
623
+ function re(e, t, o, r, n = []) {
624
+ const s = j(e, o, n);
625
+ for (const i of s.cells) for (const a of i) a && (a.editable = !1, delete a.source);
626
+ return { kind: "rect", nid: r, leftMm: e.page.marginLeftMm ?? 0, topMm: J(e, o.top), widthMm: ee(e, o), heightMm: A(e, o), grid: s, meta: oe(e, o) };
627
+ }
628
+ function Be(e, t, o, r) {
629
+ const n = d(o.range), s = v(o), i = j(e, n), a = new Map(r.fields.map((f) => [f.field, f])), c = i.colWidthsMm, l = o.fields.map((f, m) => ({ ...q(a.get(f)), header: a.get(f).label ?? f, widthMm: c[m], style: S(i.cells[0]?.[m]?.style ?? {}), align: "auto" }));
630
+ return {
631
+ kind: "list",
632
+ id: `xlsx-region:${o.id}`,
633
+ dataset: o.dataset,
634
+ rowKey: o.rowKey,
635
+ ...o.revisionField ? { revisionField: o.revisionField } : {},
636
+ ...o.sourceTokenField ? { sourceTokenField: o.sourceTokenField } : {},
637
+ title: `${t.sheet} · ${o.id}`,
638
+ layout: e.page.layout ?? "wide",
639
+ leftMm: (e.page.marginLeftMm ?? 0) + e.widths.slice(0, n.left - e.range.left).reduce((f, m) => f + m, 0),
640
+ topMm: J(e, s.top),
641
+ widthMm: ee(e, n),
642
+ rowHeightMm: i.rowHeightsMm[0],
643
+ header: !!o.headerRange,
644
+ headerEveryPage: o.mode === "repeat",
645
+ ...o.mode === "record" ? { cardinality: "record" } : {},
646
+ ...o.headerRange ? { headerGrid: j(e, d(o.headerRange)) } : {},
647
+ columns: l,
648
+ paddingMm: i.paddingMm,
649
+ meta: oe(e, n)
650
+ };
651
+ }
652
+ function Y(e, t, o, r = 0) {
653
+ const n = [], s = e.page.heightMm - (e.page.marginTopMm ?? 0) - (e.page.marginBottomMm ?? 0) - r, i = Math.max(1, Math.min(100, Math.floor(1e4 / e.widths.length)));
654
+ for (let a = t; a <= o; ) {
655
+ const c = a;
656
+ let l = a, f = 0;
657
+ for (; a <= o; ) {
658
+ let m = a;
659
+ for (let h = a; h <= m; h++) for (const p of e.cellsByRow.get(h) ?? []) m = Math.max(m, p.bottom);
660
+ if (m > o) throw new Error("静态合并区域跨越动态绑定边界,请调整区域");
661
+ const g = A(e, { ...e.range, top: a, bottom: m });
662
+ if (a > c && (m - c + 1 > i || f + g > s)) break;
663
+ if (g > s) throw new Error("静态合并区域高度超过单页可用高度,请调整原始模板");
664
+ f += g, l = m, a = m + 1;
665
+ }
666
+ n.push({ range: { ...e.range, top: c, bottom: l }, bindings: [] });
667
+ }
668
+ return n;
669
+ }
670
+ function Ce(e, t) {
671
+ const o = [...t.regions].sort((a, c) => v(a).top - v(c).top), r = [];
672
+ let n = e.range.top;
673
+ const s = t.footerRange ? A(e, d(t.footerRange)) : 0;
674
+ for (const a of o) {
675
+ const c = v(a), l = r[r.length - 1];
676
+ if (l?.bindings.length && l.range.top === c.top && l.range.bottom === c.bottom) {
677
+ l.bindings.push(a);
678
+ continue;
679
+ }
680
+ n < c.top && r.push(...Y(e, n, c.top - 1, s)), r.push({ range: { ...e.range, top: c.top, bottom: c.bottom }, bindings: [a] }), n = c.bottom + 1;
681
+ }
682
+ const i = t.footerRange ? d(t.footerRange).top - 1 : e.range.bottom;
683
+ return n <= i && r.push(...Y(e, n, i, s)), r;
684
+ }
685
+ function Oe(e, t, o, r, n) {
686
+ const s = [], i = o.bindings.map(v), a = o.bindings.some((l) => l.mode === "repeat"), c = k(e, o.range).some((l) => !i.some((f) => R(f, l)));
687
+ !a && (!o.bindings.length || c) && s.push(re(e, t, o.range, `xlsx-static:${r}`, i));
688
+ for (const l of o.bindings) s.push(Be(e, t, l, n.find((f) => f.id === l.dataset)));
689
+ return { components: s, flow: { componentIds: s.map((l) => l.kind === "list" ? l.id : l.nid), topMm: J(e, o.range.top), heightMm: A(e, o.range) } };
690
+ }
691
+ function Fe(e, t, o, r) {
692
+ const n = X(e, t.sheet), s = { ...S(n.page), components: [] }, i = Ce(n, t).map((a, c) => Oe(n, t, a, c, o));
693
+ if (s.components = i.flatMap((a) => a.components), s.flow = { bands: i.map((a) => a.flow) }, s.meta = { xlsxFlow: { version: "1.0", templateId: r, sheet: t.sheet, fullWidthsMm: n.widths } }, t.footerRange) {
694
+ const a = d(t.footerRange), c = re(n, t, a, "xlsx-footer");
695
+ c.pageAnchor = "footer", c.topMm = s.heightMm - (s.marginBottomMm ?? 0) - c.heightMm, s.components.push(c);
696
+ }
697
+ return { ...S(e.template), pages: [s] };
698
+ }
699
+ function b(e) {
700
+ return e instanceof Error ? e.message : String(e);
701
+ }
702
+ function y(e, t, o, r) {
703
+ e.push({ path: t, code: o, message: r });
704
+ }
705
+ function W(e, t, o = !1) {
706
+ const r = d(e);
707
+ if (!R(t.range, r)) throw new Error("绑定范围应完整位于来源工作表内");
708
+ if (o && r.top !== r.bottom) throw new Error("每个动态区域应选择一行原型;多个数据行由 repeat 自动扩展");
709
+ return te(t, r), r;
710
+ }
711
+ function Te(e) {
712
+ const t = e.cell;
713
+ return !!t.formula || !!t.children?.length || t.value !== null && t.value !== void 0 && t.value !== "" || !!t.text || !!t.rawText;
714
+ }
715
+ function Ne(e, t, o) {
716
+ if (!e.headerRange) return;
717
+ const r = W(e.headerRange, t);
718
+ if (r.left !== o.left || r.right !== o.right || r.bottom + 1 !== o.top) throw new Error("区域表头应与原型等列宽,并紧接原型上方");
719
+ return r;
720
+ }
721
+ function Ie(e, t) {
722
+ const o = W(e.range, t, !0), r = Ne(e, t, o);
723
+ if (te(t, { ...t.range, top: r?.top ?? o.top, bottom: o.bottom }), k(t, o).some((s) => s.bottom !== s.top || s.left !== s.right)) throw new Error("动态原型行不能包含合并格;请保留合并表头并选择其下方数据行");
724
+ if (e.mode === "repeat") {
725
+ const s = { ...t.range, top: r?.top ?? o.top, bottom: o.bottom };
726
+ if (k(t, s).some((i) => !R({ ...o, top: s.top }, i) && Te(i))) throw new Error("纵向重复区域的旁列存在静态内容,无法安全拉伸;请扩大区域或将静态内容移至独立行");
727
+ }
728
+ return { ...o, top: r?.top ?? o.top };
729
+ }
730
+ function ne(e) {
731
+ if (!e || e.version !== "2.0" || typeof e.sheet != "string" || !Array.isArray(e.regions) || !e.regions.length || e.regions.length > 128) throw new Error("多区域绑定应为 version 2.0,并包含 1–128 个区域");
732
+ }
733
+ function Ke(e, t) {
734
+ const o = [];
735
+ try {
736
+ ne(t);
737
+ } catch (i) {
738
+ return [{ path: "$.recipe", code: "schema", message: b(i) }];
739
+ }
740
+ let r;
741
+ try {
742
+ r = X(e, t.sheet);
743
+ } catch (i) {
744
+ return [{ path: "$.recipe.sheet", code: "source", message: b(i) }];
745
+ }
746
+ const n = /* @__PURE__ */ new Set(), s = [];
747
+ if (t.regions.forEach((i, a) => {
748
+ const c = `$.recipe.regions[${a}]`;
749
+ try {
750
+ if (!i || typeof i.id != "string" || !i.id.trim() || n.has(i.id)) throw new Error("区域标识应非空且唯一");
751
+ if (n.add(i.id), !["record", "repeat"].includes(i.mode)) throw new Error("区域模式应为 record 或 repeat");
752
+ const l = Ie(i, r);
753
+ for (const f of s) {
754
+ if (Z(l, f.range)) throw new Error(`区域与 ${f.path} 重叠(含表头)`);
755
+ if (l.top <= f.range.bottom && f.range.top <= l.bottom && (i.mode === "repeat" || f.mode === "repeat")) throw new Error("同一行不能并排放置重复区域;请按纵向顺序排列");
756
+ if (l.top <= f.range.bottom && f.range.top <= l.bottom && (l.top !== f.range.top || l.bottom !== f.range.bottom)) throw new Error("并排单记录区域应使用相同的起止行(包括表头),避免不明确的位移");
757
+ }
758
+ s.push({ range: l, mode: i.mode, path: c });
759
+ } catch (l) {
760
+ y(o, c, "region", b(l));
761
+ }
762
+ }), t.footerRange) try {
763
+ const i = W(t.footerRange, r);
764
+ if (i.left !== r.range.left || i.right !== r.range.right || i.bottom !== r.range.bottom) throw new Error("重复页尾应覆盖完整列宽并位于来源最后几行");
765
+ if (s.some((a) => a.range.bottom >= i.top)) throw new Error("页尾与动态区域或区域表头相交");
766
+ if (A(r, i) >= r.page.heightMm - (r.page.marginTopMm ?? 0) - (r.page.marginBottomMm ?? 0)) throw new Error("页尾高度占满单页,不能为报表明细预留空间");
767
+ } catch (i) {
768
+ y(o, "$.recipe.footerRange", "region", b(i));
769
+ }
770
+ return o;
771
+ }
772
+ function je(e, t) {
773
+ const o = /* @__PURE__ */ new Map();
774
+ for (const [r, n] of e.entries()) try {
775
+ if (!n || typeof n.id != "string" || !n.id.trim() || o.has(n.id)) throw new Error("数据集标识应非空且唯一");
776
+ O([], { fields: n.fields, ...n.rowKey ? { rowKey: n.rowKey } : {} });
777
+ for (const s of n.fields) if (s.digits !== void 0 && (!Number.isInteger(s.digits) || s.digits < 0 || s.digits > 100)) throw new Error("显示精度应为 0–100 的整数");
778
+ o.set(n.id, n);
779
+ } catch (s) {
780
+ y(t, `$.datasets[${r}]`, "schema", b(s));
781
+ }
782
+ return o;
783
+ }
784
+ function He(e, t, o, r) {
785
+ const n = d(e.range), s = n.right - n.left + 1;
786
+ if (!Array.isArray(e.fields) || e.fields.length !== s)
787
+ return y(r, `${o}.fields`, "mapping", "区域每个物理列应显式绑定一个字段"), 0;
788
+ const i = new Set(t.fields.map((l) => l.field)), a = /* @__PURE__ */ new Set();
789
+ let c = 0;
790
+ if (e.fields.forEach((l, f) => {
791
+ !i.has(l) || a.has(l) ? y(r, `${o}.fields[${f}]`, "mapping", "请选择契约内已声明且不重复的字段") : (a.add(l), c++);
792
+ }), !e.rowKey) y(r, `${o}.rowKey`, "row-key", "每个区域应声明稳定业务主键");
793
+ else {
794
+ const l = O(t.samples ?? [], { fields: t.fields, rowKey: e.rowKey }, { path: `$.datasets.${t.id}.samples`, maxRows: 100, maxIssues: 30 });
795
+ for (const f of l.issues) y(r, f.path, f.code === "row-key" ? "row-key" : "schema", f.message);
796
+ }
797
+ for (const l of ["revisionField", "sourceTokenField"]) e[l] !== void 0 && !i.has(e[l]) && y(r, `${o}.${l}`, "source", "并发字段应引用同一区域数据集契约内的字段");
798
+ return e.mode === "record" && (t.samples?.length ?? 0) > 1 && y(r, o, "schema", "record 区域数据集最多一行;多行请使用 repeat"), c;
799
+ }
800
+ function Je(e, t) {
801
+ const o = [];
802
+ try {
803
+ ne(e);
804
+ } catch (i) {
805
+ return { ok: !1, issues: [{ path: "$.recipe", code: "schema", message: b(i) }], mapped: 0, total: 0 };
806
+ }
807
+ const r = je(t, o);
808
+ let n = 0, s = 0;
809
+ for (const [i, a] of e.regions.entries()) {
810
+ const c = `$.recipe.regions[${i}]`;
811
+ try {
812
+ const l = d(a.range);
813
+ s += l.right - l.left + 1;
814
+ const f = r.get(a.dataset);
815
+ f ? n += He(a, f, c, o) : y(o, `${c}.dataset`, "source", "请选择宿主提供的数据集契约");
816
+ } catch (l) {
817
+ y(o, c, "schema", b(l));
818
+ }
819
+ }
820
+ return { ok: o.length === 0, issues: o, mapped: n, total: s };
821
+ }
822
+ function We(e, t, o) {
823
+ const r = Je(t, o), n = [...Ke(e, t), ...r.issues];
824
+ return { ...r, ok: !n.length, issues: n };
825
+ }
826
+ function Ue(e, t, o, r) {
827
+ const n = We(e, t, o);
828
+ if (!n.ok) throw new Error(n.issues.map((s) => `${s.path}: ${s.message}`).join(`
829
+ `));
830
+ return {
831
+ document: V({ ...r, template: Fe(e, t, o, r.id) }),
832
+ recipe: S(t),
833
+ warnings: [...e.warnings]
834
+ };
835
+ }
836
+ function _e(e) {
837
+ if (!e || e.version !== "2.0" || typeof e.sheet != "string" || !Array.isArray(e.regions) || !e.regions.length || e.regions.length > 128) throw new Error("多区域绑定会话配置或版本无效");
838
+ for (const t of e.regions) {
839
+ if (!t || typeof t.id != "string" || typeof t.dataset != "string" || typeof t.rowKey != "string" || !["record", "repeat"].includes(t.mode) || !Array.isArray(t.fields) || t.fields.length > 2048 || t.fields.some((o) => typeof o != "string")) throw new Error("多区域绑定会话的区域结构无效");
840
+ t.range && d(t.range), t.headerRange && d(t.headerRange);
841
+ }
842
+ e.footerRange && d(e.footerRange);
843
+ }
844
+ function De(e, t, o) {
845
+ if (H({ sheets: e.sheets, warnings: e.warnings, recipe: t, identity: o }), _e(t), !Array.isArray(e.sheets) || !e.sheets.length || !Array.isArray(e.warnings) || e.warnings.some((r) => typeof r != "string") || !e.sheets.some((r) => r.name === t.sheet)) throw new Error("多区域绑定会话的来源无效");
846
+ for (const r of e.sheets)
847
+ if (d(r.range), ![r.index, r.rowCount, r.columnCount, r.pageCount].every((n) => Number.isInteger(n) && n > 0) || !Number.isInteger(r.pageStart) || r.pageStart < 0 || r.pageStart + r.pageCount > e.template.pages.length) throw new Error("多区域绑定会话的工作表几何无效");
848
+ return z({ schemaVersion: "1.0", ...o, template: e.template }), S({ version: "2.0", source: e, recipe: t, identity: o });
849
+ }
850
+ function Xe(e) {
851
+ if (typeof e == "string" && e.length > 1e7) throw new Error("绑定会话超过 1000 万字符上限");
852
+ const t = typeof e == "string" ? JSON.parse(e) : e;
853
+ if (!t || t.version !== "2.0" || !t.source || !t.recipe || !t.identity) throw new Error("多区域绑定会话结构或版本无效");
854
+ return De(t.source, t.recipe, t.identity);
855
+ }
856
+ function Ze(e, t, o, r = o) {
857
+ const n = e.sheets.find((a) => a.name === t);
858
+ if (!n) throw new Error("工作表不存在");
859
+ const s = d(n.range);
860
+ if (![o.row, o.column, r.row, r.column].every(Number.isInteger)) throw new Error("单元格坐标应为整数");
861
+ const i = { top: Math.min(o.row, r.row), bottom: Math.max(o.row, r.row), left: Math.min(o.column, r.column), right: Math.max(o.column, r.column) };
862
+ if (i.top < s.top || i.bottom > s.bottom || i.left < s.left || i.right > s.right) throw new Error("选区超出来源工作表");
863
+ return $(i);
864
+ }
865
+ export {
866
+ Ae as a,
867
+ pe as b,
868
+ Ve as c,
869
+ Ue as d,
870
+ De as e,
871
+ Ze as f,
872
+ qe as g,
873
+ Qe as h,
874
+ Xe as i,
875
+ Se as j,
876
+ be as k,
877
+ We as l,
878
+ Je as m,
879
+ Ke as n,
880
+ ze as p,
881
+ $e as v
882
+ };