@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,3 @@
1
+ "use strict";const C=require("./dataset-D3OsyzG1.cjs"),S=require("./template-registry-D24Z8aQf.cjs"),N=require("./diagnostic-collector-wASg6Fzs.cjs"),m=require("./import-range-BwT86Z3j.cjs");function B(e){return JSON.parse(JSON.stringify(e))}function ge(e,t){const o=e.template.pages.slice(t.pageStart,t.pageStart+t.pageCount),r=o[0];if(!r)throw new Error(`工作表 ${t.name} 没有可绑定页面`);const n=new Map;let s=[];for(const i of o)for(const a of i.components){if(a.kind==="list"||!a.grid||a.meta?.xlsxSheet!==t.name)continue;const c=m.parseImportRange(String(a.meta.xlsxRange)),l=a.grid;s=l.colWidthsMm??[],l.cells.forEach((g,p)=>n.set(c.top+p,{cells:B(g),height:l.rowHeightsMm?.[p]??6}))}if(!s.length||!n.size)throw new Error(`工作表 ${t.name} 缺少导入几何元数据`);return{rows:n,widths:[...s],page:r,range:m.parseImportRange(t.range)}}function F(e,t,o){const r=[],n=[];for(let s=t;s<=o;s++){const i=e.rows.get(s);if(!i)throw new Error(`导入模板缺少第 ${s} 行`);for(const a of i.cells)if(a&&s+(a.rowSpan??1)-1>o)throw new Error(`第 ${s} 行合并区域跨越绑定边界,请调整 header/detail 范围`);r.push(B(i.cells)),n.push(i.height)}return{cells:r,rowHeightsMm:n,colWidthsMm:e.widths,paddingMm:.25}}function fe(e,t){const o=m.parseImportRange(e.header),r=e.detail?m.parseImportRange(e.detail):{...t.range,top:o.bottom+1};for(const n of[o,r])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("绑定区域必须位于导入选区内并覆盖其完整列宽");if(r.top!==o.bottom+1)throw new Error("detail 应紧接 header,避免静态内容被隐式删除");if(e.columns.length!==t.widths.length)throw new Error("columns 应逐列映射整个选区;不能自动猜测业务字段");return me(t,[o.top,o.bottom+1,r.bottom+1]),{header:o,detail:r}}function me(e,t){for(const[o,r]of e.rows)for(const n of r.cells){const s=o+(n?.rowSpan??1);if(t.some(i=>o<i&&s>i))throw new Error(`第 ${o} 行合并区域跨越绑定边界,请调整 header/detail 范围`)}}function he(e,t){const o=[];for(const r of N.resolveGridLayout(e,t.reduce((n,s)=>n+s,0),100).cells)for(let n=r.ci;n<Math.min(t.length,r.ci+(r.cell.colSpan??1));n++)o[n]=r.cell;return o}function pe(e,t,o,r){if(t)return t;const n=e?.numberFormat;if(!n||n==="General")return;const s=/^(#,##)?0(?:\.(0+))?(%)?$/.exec(n);if(s){const i=s[2]?.length??0;if(i<=100)return s[3]?{kind:"percent",digits:i}:{kind:"number",digits:i,...s[1]?{thousands:!0}:{}}}r.push(`${o}: Excel 数字格式 ${n} 未自动套用到动态数据,请在 columns 中显式声明 format`)}function de(e,t,o,r,n){const s=he(t,r),i=N.resolveGridLayout(o,r.reduce((g,p)=>g+p,0),20).cells;if(i.some(({cell:g})=>(g.colSpan??1)!==1||(g.rowSpan??1)!==1))throw new Error("动态明细样例行不能包含合并格;合并表头可以保留");const a=new Map(i.map(g=>[g.ci,g.cell])),c=new Set,l=e.columns.map((g,p)=>{const f=typeof g=="string"?{field:g}:g;if(!f||typeof f.field!="string"||!f.field.trim()||c.has(f.field))throw new Error(`columns[${p}] 需要唯一的非空 field`);c.add(f.field);const h=s[p]?.text??f.field,d=a.get(p),u=e.inferSampleFormats===!1?f.format:pe(d,f.format,f.field,n);return{...f,...u?{format:u}:{},header:f.header??h,widthMm:r[p],style:{...d?.style,...f.style},...f.semanticRole&&!f.align?{align:"auto"}:{},...f.editable===void 0&&d?.editable===!1?{editable:!1}:{}}});return we(e,s,l),l}function we(e,t,o){const r=new Map;e.columns.forEach((n,s)=>{const i=t[s];if(!i||typeof n=="string")return;const a=r.get(i)??{style:{}};if(n.header!==void 0){if(a.text!==void 0&&a.text!==n.header)throw new Error("同一合并表头不能配置不同 header");a.text=n.header}ue(a.style,{...n.headerAlign?{align:n.headerAlign}:{},...n.headerStyle}),r.set(i,a)});for(const[n,s]of r)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)=>{i===n&&(s.text!==void 0&&(o[a].header=s.text),s.style.align!==void 0&&(o[a].headerAlign=s.style.align))})}function ue(e,t){for(const o of Object.keys(t))if(t[o]!==void 0){if(e[o]!==void 0&&e[o]!==t[o])throw new Error(`同一合并表头不能配置不同 ${o}`);Object.assign(e,{[o]:t[o]})}}function ye(e,t){const o=e.page,r=t.rowHeightsMm.reduce((n,s)=>n+s,0);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}]}}function Ee(e,t,o,r){const n=ge(e,t),{header:s,detail:i}=fe(o,n),a=F(n,n.range.top,s.bottom),c=F(n,i.top,i.top),l={...n.page,components:[]},g={kind:"list",id:`bound:${t.name}`,dataset:o.dataset??"detail",title:t.name,leftMm:l.marginLeftMm??0,topMm:l.marginTopMm??0,widthMm:n.widths.reduce((p,f)=>p+f,0),layout:l.layout??"page",headerGrid:a,columns:de(o,a,c,n.widths,r),rowHeightMm:c.rowHeightsMm[0],headerEveryPage:!0,align:"auto",paddingMm:.25,...o.rowKey?{rowKey:o.rowKey}:{},...o.revisionField?{revisionField:o.revisionField}:{},...o.sourceTokenField?{sourceTokenField:o.sourceTokenField}:{},...o.groupBy?{groupBy:o.groupBy}:{},...o.grandTotal===void 0?{}:{grandTotal:o.grandTotal}};return l.components.push(g),i.bottom===n.range.bottom?[l]:(r.push(`${t.name}: 明细区域后的静态内容保留为后续独立页面,不推断动态页脚定位`),[l,ye(n,F(n,i.bottom+1,n.range.bottom))])}function P(e,t){const o=S.validateReportTemplate(e.template);if(!o.ok)throw new Error(`导入模板无效:${o.errors[0]?.message}`);if(!t.length)throw new Error("至少需要一个 Excel 业务绑定");const r=new Map;for(const c of t){if(!e.sheets.some(l=>l.name===c.sheet)||r.has(c.sheet))throw new Error(`绑定工作表不存在或重复:${c.sheet}`);r.set(c.sheet,c)}const n=[...e.warnings],s=e.sheets.flatMap(c=>{const l=r.get(c.name);return l?Ee(e,c,l,n):B(e.template.pages.slice(c.pageStart,c.pageStart+c.pageCount))}),i={...B(e.template),pages:s},a=S.validateReportTemplate(i);if(!a.ok)throw new Error(`业务模板无效:${a.errors[0]?.path} ${a.errors[0]?.message}`);return{template:i,warnings:n}}function q(e){const t=e.semanticRole??(e.type==="number"||e.type==="decimal"?"measure":e.type==="date"?"date":"text");return{field:e.field,semanticRole:t,editable:!1,...e.type==="number"&&e.digits!==void 0?{format:{kind:"number",digits:e.digits}}:{},...e.type==="date"?{format:{kind:"date",pattern:"YYYY-MM-DD"}}:{}}}function Re(e){return e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)}function H(e,t=0){if(Re(e))return;if(!e||typeof e!="object"||t>16)throw new Error("绑定会话元数据只允许有限深度的普通 JSON 值");const o=Object.getPrototypeOf(e);if(Array.isArray(e)?o!==Array.prototype:o!==Object.prototype&&o!==null)throw new Error("绑定会话不能包含特殊对象原型");if(Object.getOwnPropertySymbols(e).length)throw new Error("绑定会话不能包含 Symbol");if(Array.isArray(e)&&Object.keys(e).length!==e.length)throw new Error("绑定会话数组不能包含空位或额外属性");for(const[r,n]of Object.entries(Object.getOwnPropertyDescriptors(e)))if(!(Array.isArray(e)&&r==="length")){if(["__proto__","prototype","constructor"].includes(r)||n.get||n.set||!n.enumerable)throw new Error("绑定会话包含不安全元数据");H(n.value,t+1)}}function Me(e,t){return xe(e,t)}function xe(e,t){const o=e.sheets.find(c=>c.name===t.sheet);if(!o)return[];const r=m.parseImportRange(t.regions.header),n=m.parseImportRange(t.regions.detail),s=[r.top,r.bottom+1,n.bottom+1],i=[],a=new Set;for(const c of e.template.pages.slice(o.pageStart,o.pageStart+o.pageCount))for(const l of c.components){if(l.kind==="list"||!l.grid||l.meta?.xlsxSheet!==t.sheet)continue;const g=m.parseImportRange(String(l.meta.xlsxRange));l.grid.cells.forEach((p,f)=>{const h=g.top+f;for(const d of p){const u=s.some(M=>h<M&&h+(d?.rowSpan??1)>M),R=h===n.top&&((d?.rowSpan??1)>1||(d?.colSpan??1)>1);if(!u&&!R)continue;const E=u?"$.recipe.regions":"$.recipe.regions.detail";a.has(E)||(a.add(E),i.push({path:E,code:"region",message:u?`第 ${h} 行合并区域跨越绑定边界,请选择完整合并区域`:"动态明细原型行不能包含合并格"}))}})}return i}function Y(e){return JSON.parse(JSON.stringify(e))}function A(e){return e instanceof Error?e.message:String(e)}function w(e,t,o,r){e.push({path:t,code:o,message:r})}function V(e,t){return{fields:e.fields,...t?{rowKey:t}:{}}}function Se(e,t){const o=new Set;for(const[r,n]of e.entries()){const s=`$.datasets[${r}]`;if(!n||typeof n.id!="string"||!n.id.trim()||o.has(n.id)){w(t,s,"schema","数据集标识应非空且唯一");continue}o.add(n.id);try{C.validateDatasetRows([],V(n,n.rowKey));for(const[i,a]of n.fields.entries())a.digits!==void 0&&(!Number.isInteger(a.digits)||a.digits<0||a.digits>100)&&w(t,`${s}.fields[${i}].digits`,"schema","显示精度应为 0–100 的整数")}catch(i){w(t,s,"schema",A(i))}}}function be(e,t,o){const r=e.sheets.find(a=>a.name===t.sheet);if(!r){w(o,"$.recipe.sheet","source","指定的工作表不存在");return}let n;try{n=m.parseImportRange(r.range)}catch(a){w(o,"$.source.sheets","source",A(a));return}const s=new Map;for(const a of["title","header","detail","footer"]){const c=t.regions?.[a];if(!(!c&&(a==="title"||a==="footer")))try{const l=m.parseImportRange(c??"");if(l.left!==n.left||l.right!==n.right||l.top<n.top||l.bottom>n.bottom)throw new Error("区域必须覆盖选区完整列宽,并位于原始工作表内");s.set(a,l)}catch(l){w(o,`$.recipe.regions.${a}`,"region",A(l))}}const i=[...s.values()];i.length&&(i[0].top!==n.top||i[i.length-1].bottom!==n.bottom)&&w(o,"$.recipe.regions","region","标题、表头、明细、页脚应完整覆盖来源,不能隐式删除静态内容");for(let a=1;a<i.length;a++)i[a].top!==i[a-1].bottom+1&&w(o,"$.recipe.regions","region","各区域应顺序相邻且不重叠")}function $e(e,t,o,r){if(!Array.isArray(e.fields)||e.fields.length!==o)return w(r,"$.recipe.fields","mapping","每个物理 Excel 列必须显式绑定一个业务字段"),0;const n=new Set(t.fields.map(a=>a.field)),s=new Set;let i=0;e.fields.forEach((a,c)=>{typeof a!="string"||!n.has(a)?w(r,`$.recipe.fields[${c}]`,"mapping","请选择契约中已声明的字段"):s.has(a)?w(r,`$.recipe.fields[${c}]`,"mapping","同一业务字段不能重复绑定物理列"):(i++,s.add(a))});try{if(!e.rowKey)throw new Error("请明确选择稳定业务主键,不能使用展示行号");const a=V(t,e.rowKey),c=C.validateDatasetRows(t.samples??[],a,{path:`$.datasets.${t.id}.samples`,maxRows:100,maxCells:2e5,maxIssues:30});for(const l of c.issues)w(r,l.path,l.code==="row-key"?"row-key":"schema",l.message)}catch(a){w(r,"$.recipe.rowKey","row-key",A(a))}return i}function z(e,t){const o=[];return!t||t.version!=="1.0"?[{path:"$.recipe.version",code:"schema",message:"不支持的 Excel 绑定配置版本"}]:(be(e,t,o),o.length||o.push(...Me(e,t)),o)}function Q(e,t,o){const r=[];if(!t||t.version!=="1.0")return{ok:!1,issues:[{path:"$.recipe.version",code:"schema",message:"不支持的 Excel 绑定配置版本"}],mapped:0,total:0};Se(o,r);const n=e.sheets.find(a=>a.name===t.sheet)?.columnCount??0,s=o.find(a=>a.id===t.dataset);let i=0;return s?r.some(a=>a.code==="schema")||(i=$e(t,s,n,r)):w(r,"$.recipe.dataset","schema","请明确选择宿主提供的数据集契约"),{ok:r.length===0,issues:r,mapped:i,total:n}}function U(e,t,o){const r=Q(e,t,o);if(!t||t.version!=="1.0")return r;const n=[...z(e,t),...r.issues];return{...r,ok:n.length===0,issues:n}}function ve(e,t,o,r){const n=U(e,t,o);if(!n.ok)throw new Error(n.issues.map(g=>`${g.path}: ${g.message}`).join(`
2
+ `));const s=e.sheets.find(g=>g.name===t.sheet),i={...e,sheets:[{...s,pageStart:0}],template:{...e.template,pages:e.template.pages.slice(s.pageStart,s.pageStart+s.pageCount)}},a=new Map(o.find(g=>g.id===t.dataset).fields.map(g=>[g.field,g])),c={sheet:t.sheet,dataset:t.dataset,header:t.regions.header,detail:t.regions.detail,rowKey:t.rowKey,inferSampleFormats:!1,columns:t.fields.map(g=>q(a.get(g)))},l=P(i,[c]);return{document:S.defineReportTemplate({...r,template:l.template}),recipe:Y(t),warnings:l.warnings}}function ke(e,t){if(e?.version!=="1.0"||!Array.isArray(e.fields)||e.fields.length>16384||e.fields.some(o=>typeof o!="string"))throw new Error("Excel 绑定配置无效");if(typeof e.dataset!="string"||typeof e.rowKey!="string"||!e.regions||typeof t?.id!="string"||typeof t.name!="string")throw new Error("Excel 绑定参数或标识无效");for(const o of Object.values(e.regions))o!==""&&m.parseImportRange(o)}function Ie(e){for(const t of e.sheets)if(m.parseImportRange(t.range),typeof t.name!="string"||![t.index,t.rowCount,t.columnCount,t.pageCount].every(o=>Number.isInteger(o)&&o>0)||!Number.isInteger(t.pageStart)||t.pageStart<0||t.pageStart+t.pageCount>e.template.pages.length)throw new Error("Excel 绑定工作表几何元数据无效")}function Be(e,t,o){if(H({sheets:e.sheets,warnings:e.warnings,recipe:t,identity:o}),!Array.isArray(e.sheets)||!e.sheets.length||e.sheets.length>32||!Array.isArray(e.warnings)||e.warnings.some(r=>typeof r!="string"))throw new Error("Excel 绑定来源元数据无效");if(ke(t,o),!e.sheets.some(r=>r.name===t.sheet))throw new Error("Excel 绑定工作表不存在");Ie(e)}function X(e,t,o){return Be(e,t,o),S.parseReportTemplate({schemaVersion:"1.0",id:o.id,name:o.name,template:e.template}),Y({version:"1.0",source:e,recipe:t,identity:o})}function Ae(e){if(typeof e=="string"&&e.length>1e7)throw new Error("Excel 绑定会话超过 1000 万字符上限");const t=typeof e=="string"?JSON.parse(e):e;if(!t||t.version!=="1.0"||t.recipe?.version!=="1.0"||!Array.isArray(t.source?.sheets))throw new Error("Excel 绑定会话结构或版本无效");return X(t.source,t.recipe,t.identity)}function Ce(e,t,o,r){const n=e.sheets.find(c=>c.name===t);if(!n)throw new Error("工作表不存在");const s=m.parseImportRange(n.range),i=Math.min(o,r),a=Math.max(o,r);if(!Number.isInteger(i)||!Number.isInteger(a)||i<s.top||a>s.bottom)throw new Error("选中行超出来源区域");return m.rangeName({...s,top:i,bottom:a})}function L(e,t,o){const r=e??t;if(!Number.isInteger(r)||r<1||r>o)throw new Error(`预览窗口大小应为 1–${o} 的整数`);return r}function W(e,t,o){const r=e??t;if(!Number.isInteger(r))throw new Error("预览起点应为整数");return Math.max(t,Math.min(o,r))}function Ne(e,t,o={}){const r=e.sheets.find(f=>f.name===t);if(!r)throw new Error("指定的工作表不存在");const n=m.parseImportRange(r.range),s=W(o.row,n.top,n.bottom),i=W(o.column,n.left,n.right),a=Math.min(n.bottom,s+L(o.rows,24,100)-1),c=Math.min(n.right,i+L(o.columns,12,32)-1),l=Array.from({length:a-s+1},(f,h)=>({row:s+h,cells:[]})),g=new Set;for(const f of e.template.pages.slice(r.pageStart,r.pageStart+r.pageCount))for(const h of f.components){if(h.kind==="list"||!h.grid||h.meta?.xlsxSheet!==t)continue;const d=m.parseImportRange(String(h.meta.xlsxRange));if(d.bottom<s||d.top>a)continue;const u=N.resolveGridLayout(h.grid,h.widthMm,h.heightMm);for(const R of u.cells)p(R.cell,d.top+R.ri,d.left+R.ci)}for(const f of l){for(let h=i;h<=c;h++)g.has(`${f.row}:${h}`)||f.cells.push({address:`${m.columnName(h)}${f.row}`,row:f.row,column:h,text:"",rowSpan:1,colSpan:1,continued:!1});f.cells.sort((h,d)=>h.column-d.column)}return{top:s,bottom:a,left:i,right:c,source:n,rows:l,columns:Array.from({length:c-i+1},(f,h)=>({column:i+h,name:m.columnName(i+h)}))};function p(f,h,d){const u=h+(f.rowSpan??1)-1,R=d+(f.colSpan??1)-1;if(u<s||h>a||R<i||d>c)return;const E=Math.max(s,h),M=Math.max(i,d),G=Math.min(a,u)-E+1,J=Math.min(c,R)-M+1;l[E-s].cells.push({address:`${m.columnName(d)}${h}`,row:E,column:M,text:f.text??f.rawText??String(f.value??""),rowSpan:G,colSpan:J,continued:E!==h||M!==d,style:f.style});for(let O=E;O<E+G;O++)for(let T=M;T<M+J;T++)g.add(`${O}:${T}`)}}function b(e){return JSON.parse(JSON.stringify(e))}function Z(e,t){const o=e.sheets.find(a=>a.name===t);if(!o)throw new Error("指定的工作表不存在");const r=e.template.pages.slice(o.pageStart,o.pageStart+o.pageCount),n=r[0];if(!n)throw new Error("工作表没有可绑定的页面");const s={page:n,range:m.parseImportRange(o.range),widths:[],heights:new Map,cells:[],cellsByRow:new Map,topOffsets:new Map};for(const a of r)for(const c of a.components){if(c.kind==="list"||!c.grid||c.meta?.xlsxSheet!==t)continue;const l=m.parseImportRange(String(c.meta.xlsxRange));s.widths.length||(s.widths=[...c.grid.colWidthsMm??[]]),c.grid.cells.forEach((g,p)=>s.heights.set(l.top+p,c.grid.rowHeightsMm?.[p]??6));for(const g of N.resolveGridLayout(c.grid,c.widthMm,c.heightMm).cells){const p=l.top+g.ri,f=l.left+g.ci;s.cells.push({top:p,left:f,bottom:p+(g.cell.rowSpan??1)-1,right:f+(g.cell.colSpan??1)-1,cell:g.cell})}}if(s.widths.length!==s.range.right-s.range.left+1||s.heights.size!==s.range.bottom-s.range.top+1)throw new Error("来源工作表几何元数据不完整");let i=0;for(let a=s.range.top;a<=s.range.bottom;a++)s.topOffsets.set(a,i),i+=s.heights.get(a);s.topOffsets.set(s.range.bottom+1,i);for(const a of s.cells)for(let c=a.top;c<=a.bottom;c++){const l=s.cellsByRow.get(c)??[];l.push(a),s.cellsByRow.set(c,l)}return s}function ee(e,t){return e.left<=t.right&&t.left<=e.right&&e.top<=t.bottom&&t.top<=e.bottom}function $(e,t){return e.top<=t.top&&e.bottom>=t.bottom&&e.left<=t.left&&e.right>=t.right}function te(e,t){return e.widths.slice(t.left-e.range.left,t.right-e.range.left+1).reduce((o,r)=>o+r,0)}function I(e,t){return(e.topOffsets.get(t.bottom+1)??0)-(e.topOffsets.get(t.top)??0)}function k(e,t){const o=new Set;for(let r=t.top;r<=t.bottom;r++)for(const n of e.cellsByRow.get(r)??[])ee(n,t)&&o.add(n);return[...o]}function oe(e,t){for(const o of k(e,t))if(!$(t,o))throw new Error(`合并区域 ${m.rangeName(o)} 跨越选区 ${m.rangeName(t)}`)}function K(e,t,o=[]){const r=k(e,t);for(const a of r)if(!$(t,a))throw new Error(`合并区域 ${m.rangeName(a)} 跨越选区 ${m.rangeName(t)}`);const n=[],s=new Map,i=new Set;for(const a of r)if(!o.some(c=>$(c,a))){s.set(`${a.top}:${a.left}`,a);for(let c=a.top;c<=a.bottom;c++)for(let l=a.left;l<=a.right;l++)i.add(`${c}:${l}`)}for(let a=t.top;a<=t.bottom;a++){const c=[];for(let l=t.left;l<=t.right;l++){const g=s.get(`${a}:${l}`);g?(c.push(b(g.cell)),l=g.right):i.has(`${a}:${l}`)||c.push(null)}n.push(c)}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:.25}}function v(e){const t=m.parseImportRange(e.range);return e.headerRange?{...t,top:m.parseImportRange(e.headerRange).top}:t}function j(e,t){return(e.page.marginTopMm??0)+(e.topOffsets.get(t)??0)}function re(e,t){return{xlsxFlow:{version:"1.0",columnStart:t.left-e.range.left}}}function ne(e,t,o,r,n=[]){const s=K(e,o,n);for(const i of s.cells)for(const a of i)a&&(a.editable=!1,delete a.source);return{kind:"rect",nid:r,leftMm:e.page.marginLeftMm??0,topMm:j(e,o.top),widthMm:te(e,o),heightMm:I(e,o),grid:s,meta:re(e,o)}}function Oe(e,t,o,r){const n=m.parseImportRange(o.range),s=v(o),i=K(e,n),a=new Map(r.fields.map(g=>[g.field,g])),c=i.colWidthsMm,l=o.fields.map((g,p)=>({...q(a.get(g)),header:a.get(g).label??g,widthMm:c[p],style:b(i.cells[0]?.[p]?.style??{}),align:"auto"}));return{kind:"list",id:`xlsx-region:${o.id}`,dataset:o.dataset,rowKey:o.rowKey,...o.revisionField?{revisionField:o.revisionField}:{},...o.sourceTokenField?{sourceTokenField:o.sourceTokenField}:{},title:`${t.sheet} · ${o.id}`,layout:e.page.layout??"wide",leftMm:(e.page.marginLeftMm??0)+e.widths.slice(0,n.left-e.range.left).reduce((g,p)=>g+p,0),topMm:j(e,s.top),widthMm:te(e,n),rowHeightMm:i.rowHeightsMm[0],header:!!o.headerRange,headerEveryPage:o.mode==="repeat",...o.mode==="record"?{cardinality:"record"}:{},...o.headerRange?{headerGrid:K(e,m.parseImportRange(o.headerRange))}:{},columns:l,paddingMm:i.paddingMm,meta:re(e,n)}}function _(e,t,o,r=0){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)));for(let a=t;a<=o;){const c=a;let l=a,g=0;for(;a<=o;){let p=a;for(let h=a;h<=p;h++)for(const d of e.cellsByRow.get(h)??[])p=Math.max(p,d.bottom);if(p>o)throw new Error("静态合并区域跨越动态绑定边界,请调整区域");const f=I(e,{...e.range,top:a,bottom:p});if(a>c&&(p-c+1>i||g+f>s))break;if(f>s)throw new Error("静态合并区域高度超过单页可用高度,请调整原始模板");g+=f,l=p,a=p+1}n.push({range:{...e.range,top:c,bottom:l},bindings:[]})}return n}function Te(e,t){const o=[...t.regions].sort((a,c)=>v(a).top-v(c).top),r=[];let n=e.range.top;const s=t.footerRange?I(e,m.parseImportRange(t.footerRange)):0;for(const a of o){const c=v(a),l=r[r.length-1];if(l?.bindings.length&&l.range.top===c.top&&l.range.bottom===c.bottom){l.bindings.push(a);continue}n<c.top&&r.push(..._(e,n,c.top-1,s)),r.push({range:{...e.range,top:c.top,bottom:c.bottom},bindings:[a]}),n=c.bottom+1}const i=t.footerRange?m.parseImportRange(t.footerRange).top-1:e.range.bottom;return n<=i&&r.push(..._(e,n,i,s)),r}function Fe(e,t,o,r,n){const s=[],i=o.bindings.map(v),a=o.bindings.some(l=>l.mode==="repeat"),c=k(e,o.range).some(l=>!i.some(g=>$(g,l)));!a&&(!o.bindings.length||c)&&s.push(ne(e,t,o.range,`xlsx-static:${r}`,i));for(const l of o.bindings)s.push(Oe(e,t,l,n.find(g=>g.id===l.dataset)));return{components:s,flow:{componentIds:s.map(l=>l.kind==="list"?l.id:l.nid),topMm:j(e,o.range.top),heightMm:I(e,o.range)}}}function Ke(e,t,o,r){const n=Z(e,t.sheet),s={...b(n.page),components:[]},i=Te(n,t).map((a,c)=>Fe(n,t,a,c,o));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){const a=m.parseImportRange(t.footerRange),c=ne(n,t,a,"xlsx-footer");c.pageAnchor="footer",c.topMm=s.heightMm-(s.marginBottomMm??0)-c.heightMm,s.components.push(c)}return{...b(e.template),pages:[s]}}function x(e){return e instanceof Error?e.message:String(e)}function y(e,t,o,r){e.push({path:t,code:o,message:r})}function D(e,t,o=!1){const r=m.parseImportRange(e);if(!$(t.range,r))throw new Error("绑定范围应完整位于来源工作表内");if(o&&r.top!==r.bottom)throw new Error("每个动态区域应选择一行原型;多个数据行由 repeat 自动扩展");return oe(t,r),r}function He(e){const t=e.cell;return!!t.formula||!!t.children?.length||t.value!==null&&t.value!==void 0&&t.value!==""||!!t.text||!!t.rawText}function je(e,t,o){if(!e.headerRange)return;const r=D(e.headerRange,t);if(r.left!==o.left||r.right!==o.right||r.bottom+1!==o.top)throw new Error("区域表头应与原型等列宽,并紧接原型上方");return r}function De(e,t){const o=D(e.range,t,!0),r=je(e,t,o);if(oe(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("动态原型行不能包含合并格;请保留合并表头并选择其下方数据行");if(e.mode==="repeat"){const s={...t.range,top:r?.top??o.top,bottom:o.bottom};if(k(t,s).some(i=>!$({...o,top:s.top},i)&&He(i)))throw new Error("纵向重复区域的旁列存在静态内容,无法安全拉伸;请扩大区域或将静态内容移至独立行")}return{...o,top:r?.top??o.top}}function se(e){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 个区域")}function ae(e,t){const o=[];try{se(t)}catch(i){return[{path:"$.recipe",code:"schema",message:x(i)}]}let r;try{r=Z(e,t.sheet)}catch(i){return[{path:"$.recipe.sheet",code:"source",message:x(i)}]}const n=new Set,s=[];if(t.regions.forEach((i,a)=>{const c=`$.recipe.regions[${a}]`;try{if(!i||typeof i.id!="string"||!i.id.trim()||n.has(i.id))throw new Error("区域标识应非空且唯一");if(n.add(i.id),!["record","repeat"].includes(i.mode))throw new Error("区域模式应为 record 或 repeat");const l=De(i,r);for(const g of s){if(ee(l,g.range))throw new Error(`区域与 ${g.path} 重叠(含表头)`);if(l.top<=g.range.bottom&&g.range.top<=l.bottom&&(i.mode==="repeat"||g.mode==="repeat"))throw new Error("同一行不能并排放置重复区域;请按纵向顺序排列");if(l.top<=g.range.bottom&&g.range.top<=l.bottom&&(l.top!==g.range.top||l.bottom!==g.range.bottom))throw new Error("并排单记录区域应使用相同的起止行(包括表头),避免不明确的位移")}s.push({range:l,mode:i.mode,path:c})}catch(l){y(o,c,"region",x(l))}}),t.footerRange)try{const i=D(t.footerRange,r);if(i.left!==r.range.left||i.right!==r.range.right||i.bottom!==r.range.bottom)throw new Error("重复页尾应覆盖完整列宽并位于来源最后几行");if(s.some(a=>a.range.bottom>=i.top))throw new Error("页尾与动态区域或区域表头相交");if(I(r,i)>=r.page.heightMm-(r.page.marginTopMm??0)-(r.page.marginBottomMm??0))throw new Error("页尾高度占满单页,不能为报表明细预留空间")}catch(i){y(o,"$.recipe.footerRange","region",x(i))}return o}function Ge(e,t){const o=new Map;for(const[r,n]of e.entries())try{if(!n||typeof n.id!="string"||!n.id.trim()||o.has(n.id))throw new Error("数据集标识应非空且唯一");C.validateDatasetRows([],{fields:n.fields,...n.rowKey?{rowKey:n.rowKey}:{}});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 的整数");o.set(n.id,n)}catch(s){y(t,`$.datasets[${r}]`,"schema",x(s))}return o}function Je(e,t,o,r){const n=m.parseImportRange(e.range),s=n.right-n.left+1;if(!Array.isArray(e.fields)||e.fields.length!==s)return y(r,`${o}.fields`,"mapping","区域每个物理列应显式绑定一个字段"),0;const i=new Set(t.fields.map(l=>l.field)),a=new Set;let c=0;if(e.fields.forEach((l,g)=>{!i.has(l)||a.has(l)?y(r,`${o}.fields[${g}]`,"mapping","请选择契约内已声明且不重复的字段"):(a.add(l),c++)}),!e.rowKey)y(r,`${o}.rowKey`,"row-key","每个区域应声明稳定业务主键");else{const l=C.validateDatasetRows(t.samples??[],{fields:t.fields,rowKey:e.rowKey},{path:`$.datasets.${t.id}.samples`,maxRows:100,maxIssues:30});for(const g of l.issues)y(r,g.path,g.code==="row-key"?"row-key":"schema",g.message)}for(const l of["revisionField","sourceTokenField"])e[l]!==void 0&&!i.has(e[l])&&y(r,`${o}.${l}`,"source","并发字段应引用同一区域数据集契约内的字段");return e.mode==="record"&&(t.samples?.length??0)>1&&y(r,o,"schema","record 区域数据集最多一行;多行请使用 repeat"),c}function ie(e,t){const o=[];try{se(e)}catch(i){return{ok:!1,issues:[{path:"$.recipe",code:"schema",message:x(i)}],mapped:0,total:0}}const r=Ge(t,o);let n=0,s=0;for(const[i,a]of e.regions.entries()){const c=`$.recipe.regions[${i}]`;try{const l=m.parseImportRange(a.range);s+=l.right-l.left+1;const g=r.get(a.dataset);g?n+=Je(a,g,c,o):y(o,`${c}.dataset`,"source","请选择宿主提供的数据集契约")}catch(l){y(o,c,"schema",x(l))}}return{ok:o.length===0,issues:o,mapped:n,total:s}}function le(e,t,o){const r=ie(t,o),n=[...ae(e,t),...r.issues];return{...r,ok:!n.length,issues:n}}function Le(e,t,o,r){const n=le(e,t,o);if(!n.ok)throw new Error(n.issues.map(s=>`${s.path}: ${s.message}`).join(`
3
+ `));return{document:S.defineReportTemplate({...r,template:Ke(e,t,o,r.id)}),recipe:b(t),warnings:[...e.warnings]}}function We(e){if(!e||e.version!=="2.0"||typeof e.sheet!="string"||!Array.isArray(e.regions)||!e.regions.length||e.regions.length>128)throw new Error("多区域绑定会话配置或版本无效");for(const t of e.regions){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("多区域绑定会话的区域结构无效");t.range&&m.parseImportRange(t.range),t.headerRange&&m.parseImportRange(t.headerRange)}e.footerRange&&m.parseImportRange(e.footerRange)}function ce(e,t,o){if(H({sheets:e.sheets,warnings:e.warnings,recipe:t,identity:o}),We(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("多区域绑定会话的来源无效");for(const r of e.sheets)if(m.parseImportRange(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("多区域绑定会话的工作表几何无效");return S.parseReportTemplate({schemaVersion:"1.0",...o,template:e.template}),b({version:"2.0",source:e,recipe:t,identity:o})}function _e(e){if(typeof e=="string"&&e.length>1e7)throw new Error("绑定会话超过 1000 万字符上限");const t=typeof e=="string"?JSON.parse(e):e;if(!t||t.version!=="2.0"||!t.source||!t.recipe||!t.identity)throw new Error("多区域绑定会话结构或版本无效");return ce(t.source,t.recipe,t.identity)}function Pe(e,t,o,r=o){const n=e.sheets.find(a=>a.name===t);if(!n)throw new Error("工作表不存在");const s=m.parseImportRange(n.range);if(![o.row,o.column,r.row,r.column].every(Number.isInteger))throw new Error("单元格坐标应为整数");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)};if(i.top<s.top||i.bottom>s.bottom||i.left<s.left||i.right>s.right)throw new Error("选区超出来源工作表");return m.rangeName(i)}exports.bindExcelTemplate=P;exports.createExcelBindingDocument=ve;exports.createExcelBindingSession=X;exports.createExcelRegionBindingDocument=Le;exports.createExcelRegionBindingSession=ce;exports.excelBindingCellRange=Pe;exports.excelBindingRowRange=Ce;exports.getExcelSheetWindow=Ne;exports.parseExcelBindingSession=Ae;exports.parseExcelRegionBindingSession=_e;exports.validateExcelBindingFields=Q;exports.validateExcelBindingRecipe=U;exports.validateExcelBindingRegions=z;exports.validateExcelRegionBindings=le;exports.validateExcelRegionFields=ie;exports.validateExcelRegionGeometry=ae;
@@ -1 +1 @@
1
- "use strict";const e=require("./encoding-DRVXs5xm.cjs");e.serveReportEncodingWorker();
1
+ "use strict";const e=require("./encoding-tWc2Wn89.cjs");e.serveReportEncodingWorker();
@@ -1,2 +1,2 @@
1
- import { s as r } from "./encoding-Amq3XrtU.js";
1
+ import { s as r } from "./encoding-D480EM2r.js";
2
2
  r();
@@ -0,0 +1,3 @@
1
+ "use strict";const d=require("./diagnostic-collector-wASg6Fzs.cjs"),z=/[\u3000-\u9fff\uff00-\uffef]/;function x(t){const e=Array.from(t),n=/\S\s+\S/.test(t),h=[];let i="";const c=t.trimEnd().length;let f=0;for(let s=0;s<e.length;s++){const o=e[s],a=e[s+1];i+=o,f+=o.length,(n?o===" "&&f<c&&/\S/.test(i):a!==void 0&&(z.test(o)||z.test(a)))&&(h.push(i),i="")}return i&&h.push(i),h}function y(t){const e=d.resolveFontSize(t).fontSizePt;return{runs:[],width:0,height:e*d.resolveLineHeight(t),fontSize:e}}function v(t,e,n,h){const i=t.runs[t.runs.length-1];i?.style===n?(i.text+=e,i.width+=h):t.runs.push({text:e,style:n,width:h});const c=d.resolveFontSize(n).fontSizePt;t.width+=h,t.fontSize=Math.max(t.fontSize,c),t.height=Math.max(t.height,c*d.resolveLineHeight(n))}function M(t,e,n,h,i){const c=t.richParagraphs[e],f=d.mergeComponentStyles(t.style,{...c.lineHeight===void 0?{}:{lineHeight:c.lineHeight}}),s=[y(f)];for(const o of c.segments){const a=d.mergeComponentStyles(f,o.style),u=o.kind==="field"?o.field??"":o.text??"";for(const l of u.replace(/\r\n|\r/g,`
2
+ `)){let r=s[s.length-1];if(l===`
3
+ `){s.push(y(a));continue}const g=i.measure(l,a);r.runs.length&&r.width+g>n-(s.length===1?h:0)&&(r.justify=!0,r=y(a),s.push(r)),v(r,l,a,g)}}return s}function k(t,e,n){const h=t.richParagraphs.map((s,o)=>{const a=(s.indentMm??0)*72/25.4,u=M(t,o,e.width,a,n),l=u.reduce((r,g)=>r+g.height,0)+((s.spaceBeforeMm??0)+(s.spaceAfterMm??0))*72/25.4;return{paragraph:s,indent:a,lines:u,height:l}}),i=h.reduce((s,o)=>s+o.height,0),c=t.style?.verticalAlign;let f=e.yTop-(c==="middle"?(e.height-i)/2:c==="bottom"?e.height-i:0);for(const{paragraph:s,indent:o,lines:a}of h){f-=(s.spaceBeforeMm??0)*72/25.4;const u=Math.max(0,e.width-o);for(const[l,r]of a.entries()){const g=s.align??t.style?.align,m=l===0?o:0,w=l===0?u:e.width;let S=e.x+m+(g==="center"?(w-r.width)/2:g==="right"?w-r.width:0);if(g==="justify"&&r.justify)C(r,n,S,f-r.fontSize,w);else for(const p of r.runs)n.draw(p.text,{...p.style,align:"left"},S,f-r.fontSize,p.width),S+=p.width;f-=r.height}f-=(s.spaceAfterMm??0)*72/25.4}return i>e.height+.01}function C(t,e,n,h,i){t=j(t,e);const c=x(t.runs.map(u=>u.text).join("")),f=c.length>1?Math.max(0,i-t.width)/(c.length-1):0,s=new Set;let o=0;for(const u of c.slice(0,-1))o+=u.length,s.add(o);let a=0;for(const u of t.runs){let l="",r=0;const g=()=>{l&&e.draw(l,{...u.style,align:"left"},n,h,r),n+=r,l="",r=0};for(const m of u.text)l+=m,r+=e.measure(m,u.style),a+=m.length,s.has(a)&&(g(),n+=f);g()}}function j(t,e){const n=t.runs.slice();for(;n.length;){const h=n[n.length-1],i=h.text.trimEnd();if(!i){n.pop();continue}i!==h.text&&(n[n.length-1]={...h,text:i,width:Array.from(i).reduce((c,f)=>c+e.measure(f,h.style),0)});break}return{...t,runs:n,width:n.reduce((h,i)=>h+i.width,0)}}exports.drawRichText=k;exports.justificationChunks=x;
@@ -0,0 +1,96 @@
1
+ import { m as y, a as z, c as M } from "./diagnostic-collector-C-JBA016.js";
2
+ const x = /[\u3000-\u9fff\uff00-\uffef]/;
3
+ function v(t) {
4
+ const e = Array.from(t), n = /\S\s+\S/.test(t), h = [];
5
+ let s = "";
6
+ const f = t.trimEnd().length;
7
+ let c = 0;
8
+ for (let i = 0; i < e.length; i++) {
9
+ const o = e[i], a = e[i + 1];
10
+ s += o, c += o.length, (n ? o === " " && c < f && /\S/.test(s) : a !== void 0 && (x.test(o) || x.test(a))) && (h.push(s), s = "");
11
+ }
12
+ return s && h.push(s), h;
13
+ }
14
+ function S(t) {
15
+ const e = z(t).fontSizePt;
16
+ return { runs: [], width: 0, height: e * M(t), fontSize: e };
17
+ }
18
+ function j(t, e, n, h) {
19
+ const s = t.runs[t.runs.length - 1];
20
+ s?.style === n ? (s.text += e, s.width += h) : t.runs.push({ text: e, style: n, width: h });
21
+ const f = z(n).fontSizePt;
22
+ t.width += h, t.fontSize = Math.max(t.fontSize, f), t.height = Math.max(t.height, f * M(n));
23
+ }
24
+ function k(t, e, n, h, s) {
25
+ const f = t.richParagraphs[e], c = y(t.style, { ...f.lineHeight === void 0 ? {} : { lineHeight: f.lineHeight } }), i = [S(c)];
26
+ for (const o of f.segments) {
27
+ const a = y(c, o.style), u = o.kind === "field" ? o.field ?? "" : o.text ?? "";
28
+ for (const l of u.replace(/\r\n|\r/g, `
29
+ `)) {
30
+ let r = i[i.length - 1];
31
+ if (l === `
32
+ `) {
33
+ i.push(S(a));
34
+ continue;
35
+ }
36
+ const g = s.measure(l, a);
37
+ r.runs.length && r.width + g > n - (i.length === 1 ? h : 0) && (r.justify = !0, r = S(a), i.push(r)), j(r, l, a, g);
38
+ }
39
+ }
40
+ return i;
41
+ }
42
+ function H(t, e, n) {
43
+ const h = t.richParagraphs.map((i, o) => {
44
+ const a = (i.indentMm ?? 0) * 72 / 25.4, u = k(t, o, e.width, a, n), l = u.reduce((r, g) => r + g.height, 0) + ((i.spaceBeforeMm ?? 0) + (i.spaceAfterMm ?? 0)) * 72 / 25.4;
45
+ return { paragraph: i, indent: a, lines: u, height: l };
46
+ }), s = h.reduce((i, o) => i + o.height, 0), f = t.style?.verticalAlign;
47
+ let c = e.yTop - (f === "middle" ? (e.height - s) / 2 : f === "bottom" ? e.height - s : 0);
48
+ for (const { paragraph: i, indent: o, lines: a } of h) {
49
+ c -= (i.spaceBeforeMm ?? 0) * 72 / 25.4;
50
+ const u = Math.max(0, e.width - o);
51
+ for (const [l, r] of a.entries()) {
52
+ const g = i.align ?? t.style?.align, d = l === 0 ? o : 0, p = l === 0 ? u : e.width;
53
+ let w = e.x + d + (g === "center" ? (p - r.width) / 2 : g === "right" ? p - r.width : 0);
54
+ if (g === "justify" && r.justify) A(r, n, w, c - r.fontSize, p);
55
+ else for (const m of r.runs)
56
+ n.draw(m.text, { ...m.style, align: "left" }, w, c - r.fontSize, m.width), w += m.width;
57
+ c -= r.height;
58
+ }
59
+ c -= (i.spaceAfterMm ?? 0) * 72 / 25.4;
60
+ }
61
+ return s > e.height + 0.01;
62
+ }
63
+ function A(t, e, n, h, s) {
64
+ t = L(t, e);
65
+ const f = v(t.runs.map((u) => u.text).join("")), c = f.length > 1 ? Math.max(0, s - t.width) / (f.length - 1) : 0, i = /* @__PURE__ */ new Set();
66
+ let o = 0;
67
+ for (const u of f.slice(0, -1))
68
+ o += u.length, i.add(o);
69
+ let a = 0;
70
+ for (const u of t.runs) {
71
+ let l = "", r = 0;
72
+ const g = () => {
73
+ l && e.draw(l, { ...u.style, align: "left" }, n, h, r), n += r, l = "", r = 0;
74
+ };
75
+ for (const d of u.text)
76
+ l += d, r += e.measure(d, u.style), a += d.length, i.has(a) && (g(), n += c);
77
+ g();
78
+ }
79
+ }
80
+ function L(t, e) {
81
+ const n = t.runs.slice();
82
+ for (; n.length; ) {
83
+ const h = n[n.length - 1], s = h.text.trimEnd();
84
+ if (!s) {
85
+ n.pop();
86
+ continue;
87
+ }
88
+ s !== h.text && (n[n.length - 1] = { ...h, text: s, width: Array.from(s).reduce((f, c) => f + e.measure(c, h.style), 0) });
89
+ break;
90
+ }
91
+ return { ...t, runs: n, width: n.reduce((h, s) => h + s.width, 0) };
92
+ }
93
+ export {
94
+ H as d,
95
+ v as j
96
+ };
@@ -0,0 +1 @@
1
+ "use strict";var W=Object.create;var A=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var K=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of z(t))!H.call(e,s)&&s!==r&&A(e,s,{get:()=>t[s],enumerable:!(n=X(t,s))||n.enumerable});return e};var I=(e,t,r)=>(r=e!=null?W(Q(e)):{},K(t||!e||!e.__esModule?A(r,"default",{value:e,enumerable:!0}):r,e));const B=require("./diagnostic-collector-wASg6Fzs.cjs"),R=require("./prepared-BLhV7vdE.cjs"),p=require("./json-snapshot-DGFeI30h.cjs"),F=require("./report-params-VTg8MoCp.cjs"),C=require("./param-validation-C-8sRJLq.cjs"),i=require("./sha256-DgZAKXqI.cjs"),Y=require("./template-registry-D24Z8aQf.cjs"),Z=require("./template-serialization-BOUidUlh.cjs"),q=require("./assets-CZiZhTf2.cjs"),k=require("./execution-result-7sG_mdcD.cjs"),L=require("./record-bindings-KEs-DKCS.cjs");function ee(e){let t=`$.pages.${e.pageIndex}`;if(e.componentIndex<0)return t;t+=`.components.${e.componentIndex}`;const r=e.componentPath??[];for(let n=0;n+1<r.length;n+=3)t+=`.grid.cells.${r[n]}.${r[n+1]}`,r[n+2]!==void 0&&(t+=`.children.${r[n+2]}`);return t}function S(e=[]){return e.map(t=>({...t,path:ee(t)}))}function te(e,t){const r=B.createDiagnosticCollector(t??(e.diagnosticSummary?B.DEFAULT_DIAGNOSTIC_LIMIT:void 0));return e.diagnosticSummary?r.merge(e.diagnosticSummary):e.diagnostics.forEach(n=>r.push(n)),r}function $(e,t){t.diagnosticSummary?e.merge({...t.diagnosticSummary,entries:S(t.diagnosticSummary.entries)}):S(t.diagnostics).forEach(r=>e.push(r))}function se(e){const t=e.prepared.diagnosticSummary?.counts,r=t?!!(t["asset-render-failed"]||t["asset-budget-exceeded"]):e.prepared.diagnostics.some(n=>n.code==="asset-render-failed"||n.code==="asset-budget-exceeded");if(e.fidelity==="strict"&&r)throw new p.ReportSourceError("validate","严格输出拒绝已有资产渲染降级,请修复组件后重新准备报表。")}async function _(e,t,r=Date.now()){const n=e.prepared;R.assertPreparedOutputBudget(e,t),se(e);const s=te(n,e.diagnosticLimit),a=e.format==="pdf"?await import("@agile-team/mach-report/pdf"):void 0;i.throwIfAborted(e.signal);const l=e.pdf?.customFontFaces??(e.pdf?.customFontBytes?{regular:e.pdf.customFontBytes}:void 0),m=a&&l?a.createFontBytesMeasurer(l):void 0,u=p.createReportTaskReporter(e),c=await u.run("encode",async()=>{let g;const y={fidelity:e.fidelity,diagnosticLimit:e.diagnosticLimit??(n.diagnosticSummary?B.DEFAULT_DIAGNOSTIC_LIMIT:void 0),signal:e.signal,onProgress:(o,w)=>u.progress("encode",o,w)};if(e.format==="pdf"){i.throwIfAborted(e.signal);const o=await a.renderPlanToPdf(n.plan,{...e.pdf,...m?{measurer:m}:{},...y});g=o.bytes,$(s,o),R.mergeDiagnosticMessages(s,"pdf-fidelity",o.fidelityWarnings,"warning",o.fidelityWarningCount),R.mergeDiagnosticMessages(s,"pdf-page",o.pageErrors,"error",o.pageErrorCount),o.unsupportedTextCount&&s.push({code:"pdf-font",message:`${o.unsupportedTextCount} 段文本包含当前字体不支持的字符`,severity:"warning"})}else{const{renderPlanToXlsx:o}=await import("@agile-team/mach-report/xlsx");i.throwIfAborted(e.signal);const w=await o(n.plan,{...e.xlsx,...y});g=new Uint8Array(w.buffer),$(s,w),R.mergeDiagnosticMessages(s,"xlsx-fidelity",w.warnings,"warning",w.warningCount),w.notes?.forEach(P=>s.push({code:"xlsx-snapshot",message:P,severity:"info"}))}return i.throwIfAborted(e.signal),g});i.assertBudget(t,"maxOutputBytes",c.byteLength);const{plan:h,...x}=n;return{...x,diagnostics:s.entries,...e.diagnosticLimit===void 0&&!n.diagnosticSummary?{}:{diagnosticSummary:s.snapshot()},bytes:c,format:e.format,contentType:e.format==="pdf"?"application/pdf":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",stats:{...x.stats,durationMs:Date.now()-r,outputBytes:c.byteLength}}}function j(e){return{...e,reportIds:[...e.reportIds],...e.params?{params:{...e.params}}:{}}}function U(e,t){if(t.length===0)throw new p.ReportSourceError("config","缺少报表 ID");return t.map(r=>{if(!Object.prototype.hasOwnProperty.call(e,r))throw new p.ReportSourceError("config",`未注册报表 ${r}`);return e[r]})}function T(e){return e.grid?.cells.reduce((t,r)=>t+r.reduce((n,s)=>n+(s?1+(s.children?.reduce((a,l)=>a+T(l),0)??0):0),0),0)??0}function N(e,t,r,n){return e.pages.reduce((s,a)=>s+a.components.reduce((l,m)=>m.kind!=="list"?l+(r?0:T(m)):!!m.matrix!==r?l:l+p.estimateListLayoutCells(m,t,n),0),0)}function re(e,t=Object.keys(e)){return U(e,t).map((r,n)=>{const s=t[n],a=F.getReportParamDefs(e,[s]);return{id:s,params:JSON.parse(JSON.stringify(a)),paramsSchema:C.reportParamsJsonSchema(a),datasetsSchema:Object.fromEntries(Object.entries(r.dataSchema??{}).map(([l,m])=>[l,p.templateDatasetJsonSchema(typeof r.template=="function"?void 0:r.template,l,m)])),capabilities:{save:!!r.provider?.save,export:!!r.provider?.export,templates:!!r.provider?.templates}}})}function V(e,t){U(e,t.reportIds);const r=C.validateReportParams(F.getReportParamDefs(e,t.reportIds),t.params),n=t.reportIds.flatMap(a=>C.validateReportParams(F.getReportParamDefs(e,[a]),t.params).issues),s=new Map(n.map(a=>[JSON.stringify(a),a]));return{...r,ok:s.size===0,issues:[...s.values()]}}function O(e,t){const r=Y.validateRenderPlan(e.plan);if(!r.ok)throw new p.ReportSourceError("validate",`执行器返回无效计划:${r.errors[0]?.path}`);const n=e.plan.pages.length,s=e.plan.pages.reduce((a,l)=>a+l.components.reduce((m,u)=>m+T(u),0),0);return i.assertBudget(t,"maxRows",e.stats.rows),i.assertBudget(t,"maxPages",n),i.assertBudget(t,"maxCells",s),{...e,stats:{...e.stats,pages:n,cells:s}}}function J(e,t){const r=V(e.reports,t);if(!r.ok)throw new C.ReportParamValidationError(r.issues)}function ae(e){const t={...i.DEFAULT_REPORT_RUNTIME_BUDGET,...e.budget};i.validateBudget(t);const r=async(s,a)=>{const l=Date.now();let m=0,u=0;const c=B.createDiagnosticCollector(s.diagnosticLimit),h={},x=[],g=Object.fromEntries(Object.entries(e.reports).map(([d,f])=>[d,{...f,pagination:{...e.pagination,...f.pagination,...a?{measurer:a}:{}},dataValidation:{...f.dataValidation,maxRows:Math.min(t.maxRows??1e5,f.dataValidation?.maxRows??1/0),maxCells:Math.min(t.maxCells??2e6,f.dataValidation?.maxCells??1/0)}}])),o=await p.createReportSource(g,p.inspectOwnedSource({maxPages:t.maxPages,maxCells:t.maxCells,maxChartComponents:t.maxChartComponents,onDatasets:(d,f,v)=>{try{m+=p.templateDatasetRowCount(v,f,{maxRows:t.maxRows,signal:s.signal})}catch(b){throw b instanceof Z.TreeRowLimitError?new i.ReportRuntimeError("budget",b.message,"$.budget.maxRows"):b}i.assertBudget(t,"maxRows",m),u+=N(v,f,!1,g[d]?.pagination),i.assertBudget(t,"maxCells",u)}},(d,f,v)=>{u+=N(v,f,!0,g[d]?.pagination),i.assertBudget(t,"maxCells",u)}))({...s,params:s.params??{},onWarning:d=>c.push({code:"layout",message:d,severity:"warning"}),onQueryResult:(d,f,v=0)=>{const b=p.reportOccurrenceScope(v,d);Object.defineProperty(h,d,{value:{revision:f.revision,sourceToken:f.sourceToken},enumerable:!0,writable:!0}),x.push({reportId:d,reportIndex:v,reportScope:b,...f.revision===void 0?{}:{revision:f.revision},...f.sourceToken===void 0?{}:{sourceToken:f.sourceToken}}),(f.diagnostics??[]).forEach(E=>c.push({...E,...E.target?{target:{...E.target,reportScope:b,...E.target.tableId?{tableId:JSON.stringify([v,d,E.target.tableId])}:{}}}:{}}))}}).catch(d=>{throw d instanceof p.ReportSourceError&&d.cause instanceof L.PaginatePageLimitError?new i.ReportRuntimeError("budget",d.cause.message,"$.budget.maxPages"):d instanceof p.ReportSourceError&&d.cause instanceof L.PaginateCellLimitError?new i.ReportRuntimeError("budget",d.cause.message,"$.budget.maxCells"):d instanceof p.ReportSourceError&&d.cause instanceof L.PaginateChartComponentLimitError?new i.ReportRuntimeError("budget",d.cause.message,"$.budget.maxChartComponents"):d});i.throwIfAborted(s.signal);const w=e.assets?await p.createReportTaskReporter(s).run("assets",()=>q.resolvePlanAssets(o,{...e.assets,diagnosticLimit:s.diagnosticLimit,signal:s.signal})):{plan:o,diagnostics:[]},P=w.plan;w.diagnosticSummary?c.merge({...w.diagnosticSummary,entries:S(w.diagnosticSummary.entries)}):S(w.diagnostics).forEach(d=>c.push(d));const M=P.pages.reduce((d,f)=>d+f.components.reduce((v,b)=>v+T(b),0),0);i.assertBudget(t,"maxPages",P.pages.length),i.assertBudget(t,"maxCells",M);const D=R.reportFontFingerprint(s.pdf),G=e.pagination?.measurer||Object.values(e.reports).some(d=>d.pagination?.measurer);return{plan:P,diagnostics:c.entries,...s.diagnosticLimit===void 0?{}:{diagnosticSummary:c.snapshot()},revisions:h,sources:x,layout:{textMetrics:D?"font-bytes":G?"provided":"heuristic",...D?{fontFingerprint:D}:{}},stats:{rows:m,pages:P.pages.length,cells:M,durationMs:Date.now()-l}}},n=async s=>{const a=Date.now();if(s.format!=="pdf"&&s.format!=="xlsx")throw new p.ReportSourceError("config","不支持的报表导出格式");const l=s.format==="pdf"?await import("@agile-team/mach-report/pdf"):void 0;i.throwIfAborted(s.signal);const m=s.pdf?.customFontFaces??(s.pdf?.customFontBytes?{regular:s.pdf.customFontBytes}:void 0),u=l&&m?l.createFontBytesMeasurer(m):void 0,c=await r(s,u);return i.throwIfAborted(s.signal),_({...s,prepared:c},t,a)};return{describe:s=>re(e.reports,s),validate:s=>V(e.reports,s),prepare:s=>i.controlled(s.signal,t.maxDurationMs,async a=>{const{signal:l,onEvent:m,...u}=j(s),c={...u,...u.pdf?{pdf:R.snapshotPdfFonts(u.pdf)}:{},taskId:u.taskId??p.reportTaskId()},h=m?w=>p.notifyReportTaskEvent(m,w,a):void 0,x={...c,signal:a,onEvent:h};p.createReportTaskReporter(x).runSync("validate",()=>J(e,c));let g;const y=c.pdf?.customFontFaces??(c.pdf?.customFontBytes?{regular:c.pdf.customFontBytes}:void 0);if(!e.executor&&y){const w=await import("@agile-team/mach-report/pdf");i.throwIfAborted(a),g=w.createFontBytesMeasurer(y)}const o=e.executor?await e.executor.prepare(c,a,h):await r(x,g);return e.executor&&k.assertReportPreparedMetadata(o),O(o,t)}),exportPrepared:s=>i.controlled(s.signal,t.maxDurationMs,async a=>{const l=Date.now(),{signal:m,onEvent:u,...c}=s,h=O(R.snapshotPreparedReport(s.prepared,t.maxPreparedBytes??64e6,a),t),x={...c,xlsx:R.snapshotXlsxOptions(c.xlsx),prepared:h,...c.pdf?{pdf:R.snapshotPdfFonts(c.pdf)}:{},taskId:c.taskId??p.reportTaskId()};if(x.format!=="pdf"&&x.format!=="xlsx")throw new p.ReportSourceError("config","不支持的报表导出格式");const g=u?o=>p.notifyReportTaskEvent(u,o,a):void 0;if(e.executor){if(!e.executor.exportPrepared)throw new p.ReportSourceError("config","执行器未实现 exportPrepared;请升级执行器或显式使用本地运行时");const o=await e.executor.exportPrepared(x,a,g);return k.assertReportExportResult(o,x.format),i.assertBudget(t,"maxRows",o.stats.rows),i.assertBudget(t,"maxPages",o.stats.pages),i.assertBudget(t,"maxCells",o.stats.cells),i.assertBudget(t,"maxOutputBytes",o.bytes.byteLength),{...o,stats:{...o.stats,outputBytes:o.bytes.byteLength}}}const y={...x,signal:a,onEvent:g};if(p.createReportTaskReporter(y).runSync("validate",()=>R.checkPreparedFont(y)),e.assets){const o=await p.createReportTaskReporter(y).run("assets",()=>q.resolvePlanAssets(h.plan,{...e.assets,diagnosticLimit:s.diagnosticLimit,signal:a}));h.plan=o.plan,R.appendPreparedDiagnostics(h,S(o.diagnostics),o.diagnosticSummary?{...o.diagnosticSummary,entries:S(o.diagnosticSummary.entries)}:void 0,s.diagnosticLimit)}return _(y,t,l)}),export:s=>i.controlled(s.signal,t.maxDurationMs,async a=>{const{signal:l,onEvent:m,...u}=j(s),c={...u,xlsx:R.snapshotXlsxOptions(u.xlsx),...u.pdf?{pdf:R.snapshotPdfFonts(u.pdf)}:{},taskId:u.taskId??p.reportTaskId()},h=m?y=>p.notifyReportTaskEvent(m,y,a):void 0,x={...c,signal:a,onEvent:h};if(p.createReportTaskReporter(x).runSync("validate",()=>J(e,c)),c.format!=="pdf"&&c.format!=="xlsx")throw new p.ReportSourceError("config","不支持的报表导出格式");const g=e.executor?await e.executor.export(c,a,h):await n(x);return e.executor&&k.assertReportExportResult(g,c.format),i.assertBudget(t,"maxRows",g.stats.rows),i.assertBudget(t,"maxPages",g.stats.pages),i.assertBudget(t,"maxCells",g.stats.cells),i.assertBudget(t,"maxOutputBytes",g.bytes.byteLength),{...g,stats:{...g.stats,outputBytes:g.bytes.byteLength}}})}}exports.createReportRuntime=ae;exports.enforcePrepared=O;
@@ -0,0 +1,204 @@
1
+ import { G as Q, x as X } from "./diagnostic-collector-C-JBA016.js";
2
+ import { d as Y, m as O, s as T, a as j, e as Z, f as ee, g as te, r as ae } from "./prepared-DhgQ0d-h.js";
3
+ import { Q as S, R as h, S as se, N as F, H as k, n as re, T as oe, M as ne, J as ie, o as ce } from "./json-snapshot-BZ0CIQln.js";
4
+ import { g as M } from "./report-params-D9tBuM9B.js";
5
+ import { l as _, r as de, R as me } from "./param-validation-CnDEd2l-.js";
6
+ import { t as P, b as x, D as le, v as pe, c as B, R as I } from "./sha256-BDQ1Qk7A.js";
7
+ import { b as ge } from "./template-registry-PSuLsnyq.js";
8
+ import { T as fe } from "./template-serialization-BgGWYV_1.js";
9
+ import { r as A } from "./assets-BFTP-0WR.js";
10
+ import { a as J, b as ue } from "./execution-result-Ba65gieT.js";
11
+ import { f as xe, P as we, e as ye } from "./record-bindings-DBrCu6zO.js";
12
+ function he(e) {
13
+ let t = `$.pages.${e.pageIndex}`;
14
+ if (e.componentIndex < 0) return t;
15
+ t += `.components.${e.componentIndex}`;
16
+ const s = e.componentPath ?? [];
17
+ for (let i = 0; i + 1 < s.length; i += 3)
18
+ t += `.grid.cells.${s[i]}.${s[i + 1]}`, s[i + 2] !== void 0 && (t += `.children.${s[i + 2]}`);
19
+ return t;
20
+ }
21
+ function C(e = []) {
22
+ return e.map((t) => ({ ...t, path: he(t) }));
23
+ }
24
+ function ve(e, t) {
25
+ const s = X(t ?? (e.diagnosticSummary ? Q : void 0));
26
+ return e.diagnosticSummary ? s.merge(e.diagnosticSummary) : e.diagnostics.forEach((i) => s.push(i)), s;
27
+ }
28
+ function N(e, t) {
29
+ t.diagnosticSummary ? e.merge({ ...t.diagnosticSummary, entries: C(t.diagnosticSummary.entries) }) : C(t.diagnostics).forEach((s) => e.push(s));
30
+ }
31
+ function be(e) {
32
+ const t = e.prepared.diagnosticSummary?.counts, s = t ? !!(t["asset-render-failed"] || t["asset-budget-exceeded"]) : e.prepared.diagnostics.some((i) => i.code === "asset-render-failed" || i.code === "asset-budget-exceeded");
33
+ if (e.fidelity === "strict" && s) throw new h("validate", "严格输出拒绝已有资产渲染降级,请修复组件后重新准备报表。");
34
+ }
35
+ async function U(e, t, s = Date.now()) {
36
+ const i = e.prepared;
37
+ Y(e, t), be(e);
38
+ const a = ve(i, e.diagnosticLimit), r = e.format === "pdf" ? await import("@agile-team/mach-report/pdf") : void 0;
39
+ P(e.signal);
40
+ const l = e.pdf?.customFontFaces ?? (e.pdf?.customFontBytes ? { regular: e.pdf.customFontBytes } : void 0), d = r && l ? r.createFontBytesMeasurer(l) : void 0, m = S(e), n = await m.run("encode", async () => {
41
+ let p;
42
+ const y = { fidelity: e.fidelity, diagnosticLimit: e.diagnosticLimit ?? (i.diagnosticSummary ? Q : void 0), signal: e.signal, onProgress: (o, u) => m.progress("encode", o, u) };
43
+ if (e.format === "pdf") {
44
+ P(e.signal);
45
+ const o = await r.renderPlanToPdf(i.plan, { ...e.pdf, ...d ? { measurer: d } : {}, ...y });
46
+ p = o.bytes, N(a, o), O(a, "pdf-fidelity", o.fidelityWarnings, "warning", o.fidelityWarningCount), O(a, "pdf-page", o.pageErrors, "error", o.pageErrorCount), o.unsupportedTextCount && a.push({ code: "pdf-font", message: `${o.unsupportedTextCount} 段文本包含当前字体不支持的字符`, severity: "warning" });
47
+ } else {
48
+ const { renderPlanToXlsx: o } = await import("@agile-team/mach-report/xlsx");
49
+ P(e.signal);
50
+ const u = await o(i.plan, { ...e.xlsx, ...y });
51
+ p = new Uint8Array(u.buffer), N(a, u), O(a, "xlsx-fidelity", u.warnings, "warning", u.warningCount), u.notes?.forEach((R) => a.push({ code: "xlsx-snapshot", message: R, severity: "info" }));
52
+ }
53
+ return P(e.signal), p;
54
+ });
55
+ x(t, "maxOutputBytes", n.byteLength);
56
+ const { plan: w, ...f } = i;
57
+ return {
58
+ ...f,
59
+ diagnostics: a.entries,
60
+ ...e.diagnosticLimit === void 0 && !i.diagnosticSummary ? {} : { diagnosticSummary: a.snapshot() },
61
+ bytes: n,
62
+ format: e.format,
63
+ contentType: e.format === "pdf" ? "application/pdf" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
64
+ stats: { ...f.stats, durationMs: Date.now() - s, outputBytes: n.byteLength }
65
+ };
66
+ }
67
+ function V(e) {
68
+ return { ...e, reportIds: [...e.reportIds], ...e.params ? { params: { ...e.params } } : {} };
69
+ }
70
+ function z(e, t) {
71
+ if (t.length === 0) throw new h("config", "缺少报表 ID");
72
+ return t.map((s) => {
73
+ if (!Object.prototype.hasOwnProperty.call(e, s)) throw new h("config", `未注册报表 ${s}`);
74
+ return e[s];
75
+ });
76
+ }
77
+ function L(e) {
78
+ return e.grid?.cells.reduce((t, s) => t + s.reduce((i, a) => i + (a ? 1 + (a.children?.reduce((r, l) => r + L(l), 0) ?? 0) : 0), 0), 0) ?? 0;
79
+ }
80
+ function q(e, t, s, i) {
81
+ return e.pages.reduce((a, r) => a + r.components.reduce((l, d) => d.kind !== "list" ? l + (s ? 0 : L(d)) : !!d.matrix !== s ? l : l + ce(d, t, i), 0), 0);
82
+ }
83
+ function Pe(e, t = Object.keys(e)) {
84
+ return z(e, t).map((s, i) => {
85
+ const a = t[i], r = M(e, [a]);
86
+ return {
87
+ id: a,
88
+ params: JSON.parse(JSON.stringify(r)),
89
+ paramsSchema: de(r),
90
+ datasetsSchema: Object.fromEntries(Object.entries(s.dataSchema ?? {}).map(([l, d]) => [l, se(typeof s.template == "function" ? void 0 : s.template, l, d)])),
91
+ capabilities: {
92
+ save: !!s.provider?.save,
93
+ export: !!s.provider?.export,
94
+ templates: !!s.provider?.templates
95
+ }
96
+ };
97
+ });
98
+ }
99
+ function H(e, t) {
100
+ z(e, t.reportIds);
101
+ const s = _(M(e, t.reportIds), t.params), i = t.reportIds.flatMap((r) => _(M(e, [r]), t.params).issues), a = new Map(i.map((r) => [JSON.stringify(r), r]));
102
+ return { ...s, ok: a.size === 0, issues: [...a.values()] };
103
+ }
104
+ function G(e, t) {
105
+ const s = ge(e.plan);
106
+ if (!s.ok) throw new h("validate", `执行器返回无效计划:${s.errors[0]?.path}`);
107
+ const i = e.plan.pages.length, a = e.plan.pages.reduce((r, l) => r + l.components.reduce((d, m) => d + L(m), 0), 0);
108
+ return x(t, "maxRows", e.stats.rows), x(t, "maxPages", i), x(t, "maxCells", a), { ...e, stats: { ...e.stats, pages: i, cells: a } };
109
+ }
110
+ function W(e, t) {
111
+ const s = H(e.reports, t);
112
+ if (!s.ok) throw new me(s.issues);
113
+ }
114
+ function Be(e) {
115
+ const t = { ...le, ...e.budget };
116
+ pe(t);
117
+ const s = async (a, r) => {
118
+ const l = Date.now();
119
+ let d = 0, m = 0;
120
+ const n = X(a.diagnosticLimit), w = {}, f = [], p = Object.fromEntries(Object.entries(e.reports).map(([c, g]) => [c, {
121
+ ...g,
122
+ pagination: { ...e.pagination, ...g.pagination, ...r ? { measurer: r } : {} },
123
+ dataValidation: {
124
+ ...g.dataValidation,
125
+ maxRows: Math.min(t.maxRows ?? 1e5, g.dataValidation?.maxRows ?? 1 / 0),
126
+ maxCells: Math.min(t.maxCells ?? 2e6, g.dataValidation?.maxCells ?? 1 / 0)
127
+ }
128
+ }])), o = await re(p, oe({ maxPages: t.maxPages, maxCells: t.maxCells, maxChartComponents: t.maxChartComponents, onDatasets: (c, g, v) => {
129
+ try {
130
+ d += ie(v, g, { maxRows: t.maxRows, signal: a.signal });
131
+ } catch (b) {
132
+ throw b instanceof fe ? new I("budget", b.message, "$.budget.maxRows") : b;
133
+ }
134
+ x(t, "maxRows", d), m += q(v, g, !1, p[c]?.pagination), x(t, "maxCells", m);
135
+ } }, (c, g, v) => {
136
+ m += q(v, g, !0, p[c]?.pagination), x(t, "maxCells", m);
137
+ }))({ ...a, params: a.params ?? {}, onWarning: (c) => n.push({ code: "layout", message: c, severity: "warning" }), onQueryResult: (c, g, v = 0) => {
138
+ const b = ne(v, c);
139
+ Object.defineProperty(w, c, { value: { revision: g.revision, sourceToken: g.sourceToken }, enumerable: !0, writable: !0 }), f.push({ reportId: c, reportIndex: v, reportScope: b, ...g.revision === void 0 ? {} : { revision: g.revision }, ...g.sourceToken === void 0 ? {} : { sourceToken: g.sourceToken } }), (g.diagnostics ?? []).forEach((E) => n.push({ ...E, ...E.target ? { target: {
140
+ ...E.target,
141
+ reportScope: b,
142
+ ...E.target.tableId ? { tableId: JSON.stringify([v, c, E.target.tableId]) } : {}
143
+ } } : {} }));
144
+ } }).catch((c) => {
145
+ throw c instanceof h && c.cause instanceof xe ? new I("budget", c.cause.message, "$.budget.maxPages") : c instanceof h && c.cause instanceof we ? new I("budget", c.cause.message, "$.budget.maxCells") : c instanceof h && c.cause instanceof ye ? new I("budget", c.cause.message, "$.budget.maxChartComponents") : c;
146
+ });
147
+ P(a.signal);
148
+ const u = e.assets ? await S(a).run("assets", () => A(o, { ...e.assets, diagnosticLimit: a.diagnosticLimit, signal: a.signal })) : { plan: o, diagnostics: [] }, R = u.plan;
149
+ u.diagnosticSummary ? n.merge({ ...u.diagnosticSummary, entries: C(u.diagnosticSummary.entries) }) : C(u.diagnostics).forEach((c) => n.push(c));
150
+ const $ = R.pages.reduce((c, g) => c + g.components.reduce((v, b) => v + L(b), 0), 0);
151
+ x(t, "maxPages", R.pages.length), x(t, "maxCells", $);
152
+ const D = ae(a.pdf), K = e.pagination?.measurer || Object.values(e.reports).some((c) => c.pagination?.measurer);
153
+ return { plan: R, diagnostics: n.entries, ...a.diagnosticLimit === void 0 ? {} : { diagnosticSummary: n.snapshot() }, revisions: w, sources: f, layout: { textMetrics: D ? "font-bytes" : K ? "provided" : "heuristic", ...D ? { fontFingerprint: D } : {} }, stats: { rows: d, pages: R.pages.length, cells: $, durationMs: Date.now() - l } };
154
+ }, i = async (a) => {
155
+ const r = Date.now();
156
+ if (a.format !== "pdf" && a.format !== "xlsx") throw new h("config", "不支持的报表导出格式");
157
+ const l = a.format === "pdf" ? await import("@agile-team/mach-report/pdf") : void 0;
158
+ P(a.signal);
159
+ const d = a.pdf?.customFontFaces ?? (a.pdf?.customFontBytes ? { regular: a.pdf.customFontBytes } : void 0), m = l && d ? l.createFontBytesMeasurer(d) : void 0, n = await s(a, m);
160
+ return P(a.signal), U({ ...a, prepared: n }, t, r);
161
+ };
162
+ return {
163
+ describe: (a) => Pe(e.reports, a),
164
+ validate: (a) => H(e.reports, a),
165
+ prepare: (a) => B(a.signal, t.maxDurationMs, async (r) => {
166
+ const { signal: l, onEvent: d, ...m } = V(a), n = { ...m, ...m.pdf ? { pdf: T(m.pdf) } : {}, taskId: m.taskId ?? F() }, w = d ? (u) => k(d, u, r) : void 0, f = { ...n, signal: r, onEvent: w };
167
+ S(f).runSync("validate", () => W(e, n));
168
+ let p;
169
+ const y = n.pdf?.customFontFaces ?? (n.pdf?.customFontBytes ? { regular: n.pdf.customFontBytes } : void 0);
170
+ if (!e.executor && y) {
171
+ const u = await import("@agile-team/mach-report/pdf");
172
+ P(r), p = u.createFontBytesMeasurer(y);
173
+ }
174
+ const o = e.executor ? await e.executor.prepare(n, r, w) : await s(f, p);
175
+ return e.executor && ue(o), G(o, t);
176
+ }),
177
+ exportPrepared: (a) => B(a.signal, t.maxDurationMs, async (r) => {
178
+ const l = Date.now(), { signal: d, onEvent: m, ...n } = a, w = G(Z(a.prepared, t.maxPreparedBytes ?? 64e6, r), t), f = { ...n, xlsx: j(n.xlsx), prepared: w, ...n.pdf ? { pdf: T(n.pdf) } : {}, taskId: n.taskId ?? F() };
179
+ if (f.format !== "pdf" && f.format !== "xlsx") throw new h("config", "不支持的报表导出格式");
180
+ const p = m ? (o) => k(m, o, r) : void 0;
181
+ if (e.executor) {
182
+ if (!e.executor.exportPrepared) throw new h("config", "执行器未实现 exportPrepared;请升级执行器或显式使用本地运行时");
183
+ const o = await e.executor.exportPrepared(f, r, p);
184
+ return J(o, f.format), x(t, "maxRows", o.stats.rows), x(t, "maxPages", o.stats.pages), x(t, "maxCells", o.stats.cells), x(t, "maxOutputBytes", o.bytes.byteLength), { ...o, stats: { ...o.stats, outputBytes: o.bytes.byteLength } };
185
+ }
186
+ const y = { ...f, signal: r, onEvent: p };
187
+ if (S(y).runSync("validate", () => ee(y)), e.assets) {
188
+ const o = await S(y).run("assets", () => A(w.plan, { ...e.assets, diagnosticLimit: a.diagnosticLimit, signal: r }));
189
+ w.plan = o.plan, te(w, C(o.diagnostics), o.diagnosticSummary ? { ...o.diagnosticSummary, entries: C(o.diagnosticSummary.entries) } : void 0, a.diagnosticLimit);
190
+ }
191
+ return U(y, t, l);
192
+ }),
193
+ export: (a) => B(a.signal, t.maxDurationMs, async (r) => {
194
+ const { signal: l, onEvent: d, ...m } = V(a), n = { ...m, xlsx: j(m.xlsx), ...m.pdf ? { pdf: T(m.pdf) } : {}, taskId: m.taskId ?? F() }, w = d ? (y) => k(d, y, r) : void 0, f = { ...n, signal: r, onEvent: w };
195
+ if (S(f).runSync("validate", () => W(e, n)), n.format !== "pdf" && n.format !== "xlsx") throw new h("config", "不支持的报表导出格式");
196
+ const p = e.executor ? await e.executor.export(n, r, w) : await i(f);
197
+ return e.executor && J(p, n.format), x(t, "maxRows", p.stats.rows), x(t, "maxPages", p.stats.pages), x(t, "maxCells", p.stats.cells), x(t, "maxOutputBytes", p.bytes.byteLength), { ...p, stats: { ...p.stats, outputBytes: p.bytes.byteLength } };
198
+ })
199
+ };
200
+ }
201
+ export {
202
+ Be as c,
203
+ G as e
204
+ };
@@ -6,7 +6,7 @@
6
6
  "component": {
7
7
  "type": "library",
8
8
  "name": "@agile-team/mach-report",
9
- "version": "2.25.1"
9
+ "version": "2.26.0"
10
10
  },
11
11
  "properties": [
12
12
  {