@agile-team/mach-report 2.24.0 → 2.25.1

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 (136) hide show
  1. package/README.md +6 -4
  2. package/dist/{ExcelBindingWizard-Cy_lPjWV.js → ExcelBindingWizard-bs3F4dD8.js} +3 -3
  3. package/dist/{ExcelBindingWizard-BV12hGiK.cjs → ExcelBindingWizard-jSdjBtWw.cjs} +1 -1
  4. package/dist/{ParamEditor-PyOqHzzw.js → ParamEditor-B7YVD28E.js} +2 -2
  5. package/dist/{ParamEditor-DenKjvKu.cjs → ParamEditor-CGfaweYX.cjs} +1 -1
  6. package/dist/{ReportBatchPanel-pQ6d0yqJ.cjs → ReportBatchPanel-BRJt0TXp.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-8EFtMrKk.js → ReportBatchPanel-BTKHtLTW.js} +2 -2
  8. package/dist/{ReportLabelStudio-B_KF3Zc_.cjs → ReportLabelStudio-BvK_WBke.cjs} +1 -1
  9. package/dist/{ReportLabelStudio-HUeo2TsU.js → ReportLabelStudio-CZwqyO3t.js} +3 -3
  10. package/dist/{ReportParamPanel-8xR85nz-.cjs → ReportParamPanel-B27IGJjk.cjs} +1 -1
  11. package/dist/{ReportParamPanel-DA-YpkvC.js → ReportParamPanel-DGXzBzl2.js} +1 -1
  12. package/dist/{ReportPreview-_wTJnsG1.js → ReportPreview-CnxaDTCO.js} +2392 -2342
  13. package/dist/ReportPreview-DqFBcsJQ.cjs +6 -0
  14. package/dist/{ReportTemplateLibrary-DH8jl9IF.js → ReportTemplateLibrary-C7sB0Jay.js} +1 -1
  15. package/dist/{ReportTemplateLibrary-CjArKxRG.cjs → ReportTemplateLibrary-ClwxhnC0.cjs} +1 -1
  16. package/dist/{RuleEditor-GDydlEHz.js → RuleEditor-CsDGFaWz.js} +3 -4
  17. package/dist/{RuleEditor-Bmj98oC4.cjs → RuleEditor-D-OdaGdR.cjs} +1 -1
  18. package/dist/{TemplateOutlinePanel-DjPqzU9h.js → TemplateOutlinePanel-CXOT7d1r.js} +2 -2
  19. package/dist/{TemplateOutlinePanel-B554_qk1.cjs → TemplateOutlinePanel-DAqR9zQi.cjs} +1 -1
  20. package/dist/{TemplateReusePanel-DtYbCN7U.js → TemplateReusePanel-Dcfx3Hba.js} +2 -2
  21. package/dist/{TemplateReusePanel-D0628OYc.cjs → TemplateReusePanel-ygIi-Ajz.cjs} +1 -1
  22. package/dist/{TemplateReviewPanel-D_FR4ISq.js → TemplateReviewPanel-COU8FqPq.js} +1 -1
  23. package/dist/{TemplateReviewPanel-CSwvCz3f.cjs → TemplateReviewPanel-DyGULVxr.cjs} +1 -1
  24. package/dist/analytics.cjs +1 -1
  25. package/dist/analytics.d.cts +1 -1
  26. package/dist/analytics.d.ts +1 -1
  27. package/dist/analytics.js +2 -2
  28. package/dist/artifact-integrity.json +102 -102
  29. package/dist/{assets-B4AJIOTB.cjs → assets-BYdpkTIt.cjs} +1 -1
  30. package/dist/{assets-D0FbszhB.js → assets-C4MIvzQ4.js} +2 -2
  31. package/dist/{auto-BksreoKc.js → auto-D7x7QsWD.js} +10 -10
  32. package/dist/{auto-C3mGqzJ8.cjs → auto-mPK9W0y5.cjs} +1 -1
  33. package/dist/{capabilities-lqDEZSq5.js → capabilities-CN_kSVjO.js} +7 -7
  34. package/dist/{capabilities-CTwlcl8q.cjs → capabilities-D4nfhcvB.cjs} +1 -1
  35. package/dist/cell-style-B6Qffrx8.js +37 -0
  36. package/dist/cell-style-y_uh1pZp.cjs +1 -0
  37. package/dist/{data-bar-BnGtnJ82.js → data-bar-Bfh54sT4.js} +1 -1
  38. package/dist/{data-bar-2NLRzOCQ.cjs → data-bar-DzceAVeR.cjs} +1 -1
  39. package/dist/{designer-BNf7NWd6.js → designer-B597ZdC0.js} +2254 -2248
  40. package/dist/designer-DFIdv_n7.cjs +2 -0
  41. package/dist/designer.cjs +1 -1
  42. package/dist/designer.d.cts +6 -6
  43. package/dist/designer.d.ts +6 -6
  44. package/dist/designer.js +1 -1
  45. package/dist/diagnostic-collector-gB07PHy2.js +392 -0
  46. package/dist/diagnostic-collector-wASg6Fzs.cjs +1 -0
  47. package/dist/dom-CXWMmwh-.cjs +1 -0
  48. package/dist/{dom-C90cTM6Y.js → dom-DxdCMLzs.js} +185 -185
  49. package/dist/{encoding-DSc9zv2F.js → encoding-Amq3XrtU.js} +2 -2
  50. package/dist/{encoding-CkziAnZI.cjs → encoding-DRVXs5xm.cjs} +1 -1
  51. package/dist/{font-loader-i7lZbqH_.js → font-loader-D4NLIKJL.js} +1 -1
  52. package/dist/{font-loader-D-znWNWS.cjs → font-loader-p_SyTvqt.cjs} +1 -1
  53. package/dist/{grid-strokes-BPiV1WHe.js → grid-strokes-DkZEZvcI.js} +1 -1
  54. package/dist/{grid-strokes-DYf-6DMl.cjs → grid-strokes-RFMR91jn.cjs} +1 -1
  55. package/dist/index.cjs +2 -2
  56. package/dist/index.d.cts +2 -2
  57. package/dist/index.d.ts +2 -2
  58. package/dist/index.js +137 -137
  59. package/dist/{json-snapshot-BJWZNryO.js → json-snapshot-CBVWZvyC.js} +662 -615
  60. package/dist/json-snapshot-DCFEtfFw.cjs +2 -0
  61. package/dist/matrix-DUYPRL7t.cjs +1 -0
  62. package/dist/{matrix-C6e_r_vp.js → matrix-b6T291xo.js} +120 -104
  63. package/dist/{pdf-DWuq6uxx.cjs → pdf-C060D5UY.cjs} +2 -2
  64. package/dist/{pdf-0_5XiTCx.js → pdf-DU8HelKd.js} +17 -17
  65. package/dist/pdf.cjs +1 -1
  66. package/dist/pdf.js +2 -2
  67. package/dist/{plugin-B1ydqEmS.js → plugin-BdCplNe1.js} +1 -1
  68. package/dist/{plugin-BQBz2vLG.cjs → plugin-DHe8y5pD.cjs} +1 -1
  69. package/dist/{prefill-Cuzh1wxf.js → prefill-Buy4NJ15.js} +2 -2
  70. package/dist/{prefill-2p9wrpn9.cjs → prefill-Cw4ZYGXZ.cjs} +1 -1
  71. package/dist/{prepared-DAwe8Il2.cjs → prepared-BlNeOjoO.cjs} +1 -1
  72. package/dist/{prepared-CVbgO9KR.js → prepared-CBJ7BkK0.js} +2 -2
  73. package/dist/protocol-BU_4sXP0.cjs +1 -0
  74. package/dist/protocol-CB19KXGr.js +96 -0
  75. package/dist/record-bindings-B7djSjNs.cjs +1 -0
  76. package/dist/{record-bindings-fhav-NLG.js → record-bindings-Cv7lFiof.js} +47 -47
  77. package/dist/{region-binding-workflow-Cm4mqhih.js → region-binding-workflow-EYxvUYJ-.js} +2 -2
  78. package/dist/{region-binding-workflow-DWCUgjZl.cjs → region-binding-workflow-NdkMSFCh.cjs} +1 -1
  79. package/dist/report-encoding-worker.cjs +1 -1
  80. package/dist/report-encoding-worker.js +1 -1
  81. package/dist/{rich-text-layout-YJHtCWQI.js → rich-text-layout-Ch_N0Ubu.js} +1 -1
  82. package/dist/{rich-text-layout-X9YOz1JD.cjs → rich-text-layout-yJGuThtC.cjs} +1 -1
  83. package/dist/runtime-B5d_lQNQ.js +227 -0
  84. package/dist/runtime-BRx8Agqr.cjs +1 -0
  85. package/dist/sbom.cdx.json +1 -1
  86. package/dist/server-node.cjs +5 -5
  87. package/dist/server-node.js +1891 -1793
  88. package/dist/server.cjs +1 -1
  89. package/dist/server.d.cts +4 -4
  90. package/dist/server.d.ts +4 -4
  91. package/dist/server.js +8 -8
  92. package/dist/style.css +1 -1
  93. package/dist/{template-catalog-Bu7s7ReF.js → template-catalog-CM6U_RlD.js} +3 -3
  94. package/dist/{template-catalog--yBX169M.cjs → template-catalog-Cj66M84u.cjs} +1 -1
  95. package/dist/{template-fragments-Di2vDFnx.js → template-fragments-BDxdCuMD.js} +2 -2
  96. package/dist/{template-fragments-5EzVn7bm.cjs → template-fragments-DbKdxI1z.cjs} +1 -1
  97. package/dist/template-registry-B-AK1oam.cjs +1 -0
  98. package/dist/{template-registry-BCBF2b8j.js → template-registry-DeVgwEZj.js} +145 -144
  99. package/dist/{textwrap-CmVkhMhx.js → textwrap-BywMBMXM.js} +1 -1
  100. package/dist/{textwrap-BPFxhpOw.cjs → textwrap-LhJkHWb1.cjs} +1 -1
  101. package/dist/vue/async.d.cts +4 -4
  102. package/dist/vue/async.d.ts +4 -4
  103. package/dist/vue/index.d.cts +6 -6
  104. package/dist/vue/index.d.ts +6 -6
  105. package/dist/vue-async.cjs +1 -1
  106. package/dist/vue-async.js +3 -3
  107. package/dist/vue.cjs +1 -1
  108. package/dist/vue.js +7 -7
  109. package/dist/{workbook-session-B6P_-5a4.js → workbook-session-B6hRjTyX.js} +106 -107
  110. package/dist/{workbook-session-BnPK3T58.cjs → workbook-session-BclW7KKH.cjs} +3 -3
  111. package/dist/worker.cjs +1 -1
  112. package/dist/worker.js +4 -4
  113. package/dist/xlsx/node.d.cts +30 -1
  114. package/dist/xlsx/node.d.ts +30 -1
  115. package/dist/xlsx-node.cjs +42 -42
  116. package/dist/xlsx-node.js +3908 -3889
  117. package/dist/xlsx.cjs +2 -2
  118. package/dist/xlsx.d.cts +2 -2
  119. package/dist/xlsx.d.ts +2 -2
  120. package/dist/xlsx.js +151 -151
  121. package/package.json +1 -1
  122. package/dist/ReportPreview-CyUXJSVX.cjs +0 -6
  123. package/dist/designer-DWnZZ_ej.cjs +0 -2
  124. package/dist/diagnostic-collector-1sqd7DQP.js +0 -355
  125. package/dist/diagnostic-collector-D3rlvxm3.cjs +0 -1
  126. package/dist/dom-CxOkm_Sy.cjs +0 -1
  127. package/dist/json-snapshot-C7QZrRBf.cjs +0 -2
  128. package/dist/matrix-B8QWbsGM.cjs +0 -1
  129. package/dist/progress-BXzlVbIp.js +0 -29
  130. package/dist/progress-DJBd9Rb9.cjs +0 -1
  131. package/dist/protocol-BOri9qJL.js +0 -105
  132. package/dist/protocol-DD5dHSz-.cjs +0 -1
  133. package/dist/record-bindings-CAyM5tGg.cjs +0 -1
  134. package/dist/runtime-BpSAgOw1.js +0 -201
  135. package/dist/runtime-Cd2UTnwe.cjs +0 -1
  136. package/dist/template-registry-Bnh5aEYf.cjs +0 -1
@@ -0,0 +1,2 @@
1
+ "use strict";const C=require("./diagnostic-collector-wASg6Fzs.cjs"),A=require("./textwrap-LhJkHWb1.cjs"),k=require("./computed-DK6BruFz.cjs"),S=require("./record-bindings-B7djSjNs.cjs"),We=require("./matrix-DUYPRL7t.cjs"),_=require("./template-serialization-CqQY4zDg.cjs"),B=require("./template-registry-B-AK1oam.cjs"),jt=require("./report-params-VTg8MoCp.cjs"),je=require("./param-validation-C-8sRJLq.cjs"),ze=require("./number-format-CZ2T_5kF.cjs"),Me=require("./dataset-IrlXbUvh.cjs"),Kt=4096,Ke=128*1024;function Dt(e){const t=new Map;let r=0;return{measureMm(n,o){const a=JSON.stringify([n,o.fontSizePt,o.fontFamily,o.bold,o.italic,o.letterSpacingPt]),s=t.get(a);if(s!==void 0)return t.delete(a),t.set(a,s),s;const i=e.measureMm(n,o);if(Number.isFinite(i)&&a.length<=Ke){for(;t.size>=Kt||r+a.length>Ke;){const c=t.keys().next().value;r-=c.length,t.delete(c)}t.set(a,i),r+=a.length}return i}}}function Ht(e,t){return{member:"body",subtotal:"subtotal",total:"grand-total"}[e?.rows.get(t)?.kind??"member"]}function Bt(e){const t=e.matrix;if(!t.hierarchy)return t;const r=new Map(e.columns.map(o=>[o.field,o.header])),n={sum:"求和",count:"计数",avg:"平均",min:"最小",max:"最大",weightedAvg:"加权平均"};return{...t,hierarchy:{...t.hierarchy,row:{...t.hierarchy.row,labels:t.hierarchy.row?.labels??t.rowFields.map(o=>r.get(o)??o)},column:{...t.hierarchy.column,labels:t.hierarchy.column?.labels??t.columnFields.map(o=>r.get(o)??o)}},measures:t.measures.map(o=>{const a=r.get(o.field)??r.get(o.valueField??o.field);return o.label===void 0&&a?{...o,label:`${a}(${n[o.op]})`}:o})}}function Gt(e,t){if(!e.matrix)return{list:e,rows:t};if(e.detail||e.groupBy||e.groups?.length||e.grandTotal)throw new Error("矩阵不能同时配置普通分组、总计或主从明细");const r=We.createMatrixTable(t,Bt(e)),n=r.columns.map(i=>({...i,widthMm:i.semanticRole==="dimension"?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:e.align??"auto"})),o={...e,columns:n,headerGrid:r.headerGrid,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};e.layout==="wide"&&(o.widthMm=n.reduce((i,c)=>i+c.widthMm,0));const a=r.metadata,s=a?{rows:new WeakMap(r.rows.map((i,c)=>[i,a.rows[c]])),header:{columns:a.columns,rowFields:a.rowFields,rowLabels:a.rowLabels,columnFields:a.columnFields,columnLabels:a.columnLabels}}:void 0;return{list:o,rows:r.rows,...s?{matrix:s}:{}}}function Vt(e,t){if(!e.matrix?.hierarchy||!e.headerGrid)return e.headerGrid;const r=e.paddingMm??1,n=e.headerGrid.cells.map(()=>e.rowHeightMm??0),o=e.columns.map(c=>c.widthMm),a=C.resolveGridLayout({...e.headerGrid,colWidthsMm:o},o.reduce((c,l)=>c+l,0),n.length),s=new WeakMap;for(const{cell:c,ci:l,ri:d,widthMm:f}of a.cells){const u={...S.resolveListHeaderStyle(e,e.columns[l]),...c.style},m=C.resolveFontSize(u).fontSizePt,b=(A.wrapText(c.text??"",Math.max(1,f-r*2),{fontSizePt:m,fontFamily:u.fontFamily,bold:u.bold,italic:u.italic,letterSpacingPt:u.letterSpacing},t).length*m*(u.lineHeight??C.LINE_HEIGHT)*25.4/72+r*2)/(c.rowSpan??1);for(let y=d;y<d+(c.rowSpan??1);y++)n[y]=Math.max(n[y]??0,b);s.set(c,u)}const i=e.headerGrid.cells.map(c=>c.map(l=>l?{...l,style:s.get(l)}:null));return{...e.headerGrid,cells:i,rowHeightsMm:n}}function _t(e,t,r){const n=new Set,o=e.cells.map((a,s)=>{const i=[];let c=0;for(const l of a){for(;n.has(`${s}:${c}`);)c++;const d=l?.colSpan??1,f=l?.rowSpan??1;let u=0;for(let m=c;m<c+d;m++){t.has(m)&&u++;for(let g=s+1;g<s+f;g++)n.add(`${g}:${m}`)}u&&i.push(l?{...l,colSpan:u}:null),c+=d}return i});return{...e,cells:o,colWidthsMm:r}}function Je(e){if(!e.columns.some(n=>n.hidden))return e;const t=new Set,r=e.columns.filter((n,o)=>n.hidden?!1:(t.add(o),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:_t(e.headerGrid,t,r.map(n=>n.widthMm))}:{}}}function*Wt(e){const{page:t}=e;B.validateReportPageFlow(t.components,t.flow);let r=0,n=0;for(const o of B.reportFlowGroups(t.components,t.flow)){e.active();const a=o.band,s=o.components.some(d=>d.kind==="list"&&d.cardinality!=="record"),i=s?0:o.components.reduce((d,f)=>Math.max(d,f.topMm-a.topMm+(f.kind==="list"?e.height(f):f.heightMm)),a.heightMm);let c=Math.max(e.top(),n+a.topMm-r);if(!s&&i>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);!s&&c+i>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let l=c+i;for(const d of o.components){const f=c+d.topMm-a.topMm;d.kind==="list"?(yield*e.list(d,f,u=>{l=s?u:Math.max(l,u)}),e.active()):e.append({...d,topMm:f})}n=l,r=a.topMm+a.heightMm}}function zt(e){return!!(e.computed?.length||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen||e.matrix||e.tree||e.detail||e.columns.some(t=>t.rules?.length||t.visibleWhen||t.visual))}function Se(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"?zt(r):!!r.chartBinding))}const Jt=512,De=256*1024;function qt(){const e=new Map;let t=0,r;return(n,o,a,s)=>{s!==r&&(e.clear(),t=0,r=s);const i=JSON.stringify([n,o,a.fontSizePt,a.fontFamily,a.bold,a.italic,a.letterSpacingPt]),c=e.get(i);if(c)return e.delete(i),e.set(i,c),c.lines.slice();const l=A.wrapText(n,o,a,s),d=i.length+l.reduce((f,u)=>f+u.length,0);if(d<=De){for(;e.size>=Jt||t+d>De;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(i,{lines:l.slice(),units:d}),t+=d}return l}}const qe=1e4,He=25e4;function xe(e){if(e?.aborted)throw e.reason??new DOMException("标签生成已取消","AbortError")}function Ue(e,t,r){const n=typeof e.copies=="object"?S.readRecordScalar(t,e.copies.field,r):e.copies??1;if(typeof n!="number"||!Number.isSafeInteger(n)||n<1||n>1e3)throw new S.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}]`,"每条记录复制数必须是 1..1000 的数值型整数",r.rowIndex,typeof e.copies=="object"?e.copies.field:void 0);return n}function Xe(e,t,r){if(e.rowKey===void 0)return;const n=S.readRecordScalar(t,e.rowKey,r);if(typeof n=="string"&&n.trim()||typeof n=="number"&&Number.isFinite(n))return n;throw new S.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`,"业务主键必须是非空字符串或有限数字",r.rowIndex,e.rowKey)}function Ut(e){const t=r=>1+(r.grid?.cells.reduce((n,o)=>n+1+o.length+o.reduce((a,s)=>a+(s?.children?.reduce((i,c)=>i+t(c),0)??0),0),0)??0);return e.pages.reduce((r,n)=>r+n.components.reduce((o,a)=>o+t(a),0),0)}function Xt(e,t,r){const n=e.repeat,o=Object.prototype.hasOwnProperty.call(t,n.dataset)?t[n.dataset]:void 0;if(!Array.isArray(o))throw new S.ReportBindingError(`$.datasets.${n.dataset}`,"逐记录标签数据集缺失,应提供对象数组(允许空数组)");const a=new Set,s=r.maxPages??qe,i=Ut(e);let c=0,l=0;for(const[d,f]of o.entries()){if(xe(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new S.ReportBindingError(`$.datasets.${n.dataset}[${d}]`,"标签记录应为对象",d);const u={rowIndex:d,dataset:n.dataset},m=Xe(n,f,u);if(m!==void 0){const b=JSON.stringify([typeof m,m]);if(a.has(b))throw new S.ReportBindingError(`$.datasets.${n.dataset}[${d}].${n.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",d,n.rowKey);a.add(b)}const g=Ue(n,f,u);if(c+=g*e.pages.length,l+=g*i,c>s)throw new S.PaginatePageLimitError(s,c);if(l>He)throw new S.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${He},请分批生成`,d)}return o}function Yt(e,t,r){if(!e.binding)return e;const{binding:n,...o}=e,a=S.resolveComponentBinding(n,t.row,t);if(e.kind==="image"){if(!a)return;if(!S.isLabelImageData(a))throw new S.ReportBindingError(`${r}.binding`,"图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换",t.rowIndex,n.field);return{...o,imageData:a}}return e.kind==="barcode"||e.kind==="qrcode"?(delete o.imageData,{...o,code:{...o.code,value:a},fallbackText:a}):(delete o.lines,delete o.richParagraphs,{...o,text:a})}function Qt(e,t,r){if(e.kind!=="text"||e.grid||e.richParagraphs?.length)return e;const n=e.style??{},o=C.resolveFontSize(n).fontSizePt,a=e.text??e.lines?.join(`
2
+ `)??"";if(a.length>16384)throw new S.ReportBindingError(r,"标签文本超过 16384 字符预算,请缩小字段内容",t.rowIndex);const s=t.wrapText(a,e.widthMm,{fontSizePt:o,bold:n.bold,italic:n.italic,fontFamily:n.fontFamily,letterSpacingPt:n.letterSpacing},t.options.measurer??A.heuristicMeasurer),i=s.length*o*C.resolveLineHeight(n)*25.4/72;if(i>e.heightMm+.05)throw new S.ReportBindingError(r,`标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`,t.rowIndex,e.binding?.field);return{...e,lines:s}}function Ye(e,t,r){xe(t.options.signal);const n=Yt(e,t,r);if(!n)return;let o=n.grid;return o&&(o={...o,cells:o.cells.map((a,s)=>a.map((i,c)=>i?.children?.length?{...i,children:i.children.flatMap((l,d)=>{const f=Ye(l,t,`${r}.grid.cells.${s}.${c}.children.${d}`);return f?[f]:[]})}:i))}),Qt(o===n.grid?n:{...n,grid:o},t,r)}function Zt(e,t,r,n,o,a){return{...e,components:e.components.flatMap((s,i)=>{const c=Ye(s,r,`$.pages.${t}.components.${i}`);return c?[{...c,meta:{...c.meta,labelSource:{pageIndex:t,componentIndex:i}}}]:[]}),meta:{...e.meta,record:{dataset:r.dataset,rowIndex:r.rowIndex,...a===void 0?{}:{rowKey:a},copyIndex:n,copyCount:o,templatePageIndex:t}}}}function*er(e,t,r){const n=[];if(B.validateTemplateRepeat(e,n),n.length)throw new S.ReportBindingError(n[0].path,n[0].message);if(!e.repeat){for(const[i,c]of e.pages.entries())yield{page:c,pageIndex:i};return}const o=e.repeat,a=Xt(e,t,r),s=qt();for(const[i,c]of a.entries()){const l={row:c,rowIndex:i,dataset:o.dataset,options:r,wrapText:s},d=Ue(o,c,l),f=Xe(o,c,l);for(let u=0;u<d;u++)for(const[m,g]of e.pages.entries())xe(r.signal),yield{page:Zt(g,m,l,u,d,f),pageIndex:m}}}const tr=Object.freeze({}),rr=16;function nr(e){if(e===void 0)return tr;try{const t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null||Object.getOwnPropertySymbols(e).length)return;const r=Object.create(null);for(const n of Object.getOwnPropertyNames(e)){const o=Object.getOwnPropertyDescriptor(e,n);if(!o?.enumerable||o.get||o.set)return;const a=o.value;if(a!==null&&(typeof a=="object"||typeof a=="function"))return;r[n]=a}return r}catch{return}}function or(e,t){const r=Object.keys(t);return r.length===Object.keys(e).length&&r.every(n=>Object.prototype.hasOwnProperty.call(e,n)&&Object.is(e[n],t[n]))}function ar(e){const t=[];return(r,n,o,a)=>{if(!Number.isInteger(r)||r<0||r>=rr)return e(o,a);const s=nr(a);if(!s)return e(o,a);const i=t[r];if(i?.firstRow===n&&i.label===o&&or(i.style,s))return i.row;const c=e(o,a);return t[r]={firstRow:n,label:o,style:s,row:c},c}}function sr(e){return{widthMm:e.widthMm,heightMm:e.heightMm,marginTopMm:e.marginTopMm??0,marginBottomMm:e.marginBottomMm??0,marginLeftMm:e.marginLeftMm??0,marginRightMm:e.marginRightMm??0,components:[]}}function Z(e,t){const r=t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm);return e.components.reduce((n,o)=>o.kind!=="list"&&o.pageAnchor==="footer"?Math.min(n,o.topMm):n,r)}function X(e){return e.components.reduce((t,r)=>r.kind!=="list"&&r.pageAnchor==="header"?Math.max(t,r.topMm+r.heightMm):t,0)}function Qe(e,t){let r=e.textMetrics.get(t);if(!r){const n=C.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:n,fontFamily:t.fontFamily??C.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:n*(t.lineHeight??C.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function ir(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function Re(e,t,r=[],n){const o=e.fontSizePt??C.DEFAULT_FONT_PT,a=e.paddingMm??1,s=e.columns.map(w=>w.align??w.style?.align??e.align??"auto"),i=e.columns.map((w,h)=>({...C.mergeComponentStyles({fontSize:o,verticalAlign:"middle"},w.style),align:s[h]==="auto"?"left":s[h]})),c=i.map((w,h)=>s[h]==="auto"?{left:w,center:{...w,align:"center"},right:{...w,align:"right"}}:void 0),l=e.columns.map((w,h)=>w.rules?.map(x=>{const T=c[h];if(T)return{left:C.mergeComponentStyles(T.left,x.style),center:C.mergeComponentStyles(T.center,x.style),right:C.mergeComponentStyles(T.right,x.style)};const I=C.mergeComponentStyles(i[h],x.style);return{left:I,center:I,right:I}})),d=e.columns.map(w=>S.resolveListHeaderStyle(e,w)),f=e.columns.map(w=>w.header);let u=e.rowHeightMm??0;for(let w=0;w<f.length;w++){const h=d[w],x=C.resolveFontSize(h).fontSizePt,T=A.wrapText(f[w],e.columns[w].widthMm-a*2,{fontSizePt:x,fontFamily:h.fontFamily??C.DEFAULT_FONT_FAMILY,italic:h.italic,bold:h.bold,letterSpacingPt:h.letterSpacing},t),I=x*(h.lineHeight??C.LINE_HEIGHT)*25.4/72;u=Math.max(u,Math.max(T.length,1)*I+a*2)}const m=f.map((w,h)=>({text:w,style:d[h]})),g=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},b=e.columns.map(w=>w.widthMm),y=cr(Vt(e,t),b,{cells:[m],colWidthsMm:b,rowHeightsMm:[u],paddingMm:a});return{fontSizePt:o,paddingMm:a,visuals:_.createColumnVisualResolvers(e.columns,r,n),visibility:e.columns.map(w=>w.visibleWhen?k.compileReportPredicate(w.visibleWhen):void 0),ruleReaders:e.columns.map(w=>w.rules?.map(h=>k.compileReportPredicate(h.when))),cellStyles:i,autoStyles:c,ruleStyles:l,textMetrics:new WeakMap,numberFormats:e.columns.map(w=>S.toExcelNumberFormat(w.format)),derivedFields:new Set(e.computed?.map(w=>w.field)),borderStyle:g,headerHeightMm:y.rowHeightsMm.reduce((w,h)=>w+h,0),headerGrid:y,colWidthsMm:b,columns:e.columns}}function cr(e,t,r){if(!e)return r;if(!e.cells.length)throw new Error("自定义列表表头至少需要一行");const n=e.rowHeightsMm??e.cells.map(()=>r.rowHeightsMm[0]);if(n.length!==e.cells.length||n.some(o=>!Number.isFinite(o)||o<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:n}}function lr(e,t,r){const n=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:n&&(e.valueType="number"),t.editable!==void 0&&(e.editable=t.editable),(typeof e.value=="number"||e.value==null)&&r!==void 0&&(e.numberFormat=r)}function Y(e,t,r){const n=e.columns,o=e.tree?.rows.get(t);let a=e.rowHeightFloorMm;const s=new Array(n.length);for(let i=0;i<n.length;i++){const c=n[i],l=e.visibility[i]?.(t)!==!1,d=l?t[c.field]:null,f=e.autoStyles[i]?S.resolveListAutoAlignment(d,c.format,c.semanticRole,c.valueType):"left";let u=e.autoStyles[i]?.[f]??e.cellStyles[i];if(c.rules){for(let x=0;x<c.rules.length;x++)if(e.ruleReaders[i][x](t)){u=e.ruleStyles[i][x][f];break}}const m=c.format?S.formatValue(d,c.format):S.listCellText(d),g=dr(e,c,o);u=ur(e,c,u,o);const b=Qe(e,u),y=A.wrapText(m,Math.max(1,c.widthMm-e.paddingMm*2-g),b.measureOptions,r);a=Math.max(a,y.length*b.lineMm+e.paddingMm*2);const w=ir(d),h={text:m,style:u};d!=null&&e.visuals[i]?.apply(h,t),w!==void 0&&(h.value=w),lr(h,c,e.numberFormats[i]),fr(h,c,e,o,g),e.derivedFields.has(c.field)&&(h.derived=!0,h.editable=!1),l||(h.editable=!1),s[i]=h}return{grid:{cells:[s],colWidthsMm:e.colWidthsMm,rowHeightsMm:[a],paddingMm:e.paddingMm},heightMm:a,...e.matrix?{meta:{matrix:{row:e.matrix.rows.get(t)}}}:{}}}function dr(e,t,r){return!r||t.field!==e.tree.list.tree.labelField?0:S.listTreeIndent(e.tree.list,t,r,e.paddingMm)}function ur(e,t,r,n){return!n||t.field!==e.tree.list.tree.labelField||r.align==="left"?r:{...r,align:"left"}}function fr(e,t,r,n,o=0){n&&(o&&(e.indentMm=o),S.applyListTreeMetadata(e,t,n,r.tree.list))}function Ze(e){if(e!=null&&typeof e!="string"&&typeof e!="boolean"&&!(typeof e=="number"&&Number.isFinite(e)))throw new Error("分组字段应为有限 JSON 标量");return JSON.stringify([typeof e,e??null])}function*et(e,t,r=0){const n=t[r];if(!n){for(const a of e)yield{kind:"row",row:a};return}const o=new Map;for(const a of e){const s=Ze(a[n.field]),i=o.get(s);i?i.push(a):o.set(s,[a])}for(const a of o.values())yield{kind:"groupHeader",label:(n.headerTemplate??"{value}").replace(/\{value\}/g,S.listCellText(a[0][n.field])),firstRow:a[0],group:n,depth:r,rows:a},yield*et(a,t,r+1),(n.subtotal?.length||n.aggregates?.length)&&(yield{kind:"subtotal",label:n.subtotalLabel??"小计",rows:a,group:n,depth:r}),yield{kind:"groupEnd",depth:r}}function tt(e,t,r,n=[]){const o=[...r.filter(a=>!n.some(s=>s.field===a)).map(a=>({field:a,op:"sum"})),...n];return new Map(o.map(a=>{const s=e.find(c=>c.field===a.field)?.format??{kind:"number",thousands:!0},i=k.aggregateRows(t,{...a,field:a.valueField??a.field});return[a.field,{text:S.formatValue(i,s),...i===null?{}:{value:i},...typeof i=="number"?{numberFormat:S.toExcelNumberFormat(s)}:{}}]}))}function rt(e,t){const r=e.findIndex(n=>t.includes(n.field));return r<0?1:r}function ee(e,t,r,n,o,a){const s=[],i=Math.max(0,Math.min(a,e.columns.length)),c=C.mergeComponentStyles({fontSize:e.fontSizePt},o);i&&s.push({text:r,colSpan:i,style:{bold:!0,...c}});for(let u=i;u<e.columns.length;u++){const m=e.columns[u],g=n.get(m.field),b=e.autoStyles[u]?.[S.resolveListAutoAlignment(g?.value,m.format,m.semanticRole,m.valueType)]??e.cellStyles[u];s.push({...g,text:g?.text??"",style:C.mergeComponentStyles(b,o)})}const l={text:r,colSpan:e.columns.length,style:{bold:!0,...c}},d=i?[s]:[[l],s],f=d.map(u=>mr(e,u,t));return{grid:{cells:d,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((u,m)=>u+m,0)}}function mr(e,t,r){let n=e.rowHeightFloorMm,o=0;for(const a of t){let s=0;const i=o+(a.colSpan??1);for(;o<i;o++)s+=e.colWidthsMm[o]??0;const c=Qe(e,a.style),l=A.wrapText(a.text??"",s-e.paddingMm*2,c.measureOptions,r);n=Math.max(n,l.length*c.lineMm+e.paddingMm*2)}return n}function gr(e,t,r){const{templatePage:n,current:o,warnings:a,nextId:s,pushCurrent:i}=r,c=()=>Z(n,o),l=Math.max(o.marginTopMm,X(n)),d=n.layout==="wide"?X(n):l,f={id:r.tableId,columnKeys:e.columns.map(p=>p.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}},u=new Map,m=new Map,g={kind:"rect",leftMm:e.leftMm,topMm:0,widthMm:e.widthMm,heightMm:t.headerHeightMm,grid:t.headerGrid,nid:s("listh"),table:{...f,role:"header",rowIndex:-1},style:t.borderStyle,...e.meta||t.matrix?{meta:{...e.meta,...t.matrix?{matrix:t.matrix.header}:{}}}:{}},b=p=>o.components.push({...g,topMm:p});if(r.flow&&e.header!==!1&&t.headerHeightMm>c()-l+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的表头高度超出单页可用范围`);let y=Math.max(r.startTop??e.topMm,l);e.header!==!1&&(b(y),y+=t.headerHeightMm+r.mmPerRow);function w(){const p=Math.max(r.flow||n.layout==="wide"?0:e.topMm,d);return(e.header!==!1&&e.headerEveryPage!==!1?p+t.headerHeightMm:d)+[...m.values()].reduce((R,$)=>R+$.heightMm,0)}function h(){const p=n.layout==="wide"?0:o.marginBottomMm;return Math.min(n.heightMm-p,Z(n,o))-w()}function x(p){if(y+p<=c())return;i(),o.components=[],o.heightMm=n.heightMm,n.layout==="wide"&&(o.marginTopMm=0,o.marginBottomMm=0);const E=Math.max(r.flow||n.layout==="wide"?0:e.topMm,d);e.header!==!1&&e.headerEveryPage!==!1?(b(E),y=E+t.headerHeightMm):y=d;for(const R of m.values())I(R,"listgr","group-header")}function T(p,E,R,$){const v=h();if(r.flow&&p.heightMm>v+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的单行高度超出单页可用范围`);p.heightMm>v&&a.push(`列表 ${e.id??e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${v.toFixed(2)}mm,预览与打印可能截断内容`),x(p.heightMm),I(p,E,R,$)}function I(p,E,R,$){const v=p.table?.id??f.id,F=R==="header"?-1:u.get(v)??0;R!=="header"&&u.set(v,F+p.grid.cells.length),o.components.push({kind:"rect",leftMm:e.leftMm,topMm:y,widthMm:e.widthMm,heightMm:p.heightMm,grid:p.grid,nid:s(E),table:{...f,...p.table,role:R,rowIndex:F,...$?{source:$}:{}},style:t.borderStyle,...e.meta||p.meta?{meta:{...e.meta,...p.meta}}:{}}),y+=p.heightMm}function L(p){p<=h()&&x(p)}return{keepTogether:L,placeGridRow:T,setGroupHeader:(p,E)=>{E?m.set(p,E):m.delete(p)},bottom:()=>y}}function hr(e,t){if(!e.rowKey)return;const r=t[e.rowKey];if((typeof r!="string"||!r.trim())&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);const n=e.revisionField?t[e.revisionField]:void 0,o=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(n!==void 0&&typeof n!="string"&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("业务修订号应为字符串或有限数字");if(o!==void 0&&typeof o!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...n===void 0?{}:{revision:n},...o===void 0?{}:{sourceToken:o}}}function oe(e,t){const r=new Map;if(!e.rowKey)return r;const n=new Set;for(const o of t){const a=hr(e,o),s=JSON.stringify(a.rowKey);if(n.has(s))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);n.add(s),r.set(o,a)}return r}function pr(e,t,r,n,o){if(!e.grandTotal)return;const a=typeof e.grandTotal=="object"?e.grandTotal:void 0,s=ae(e)[0],i=a?.fields??s?.subtotal??[],c=a?.aggregates??s?.aggregates??[];if(i.length===0&&c.length===0){n.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const l=ee(r,n.measurer,a?.label??"合计",tt(e.columns,t,i,c),a?.style??{},rt(e.columns,[...i,...c.map(d=>d.field)]));o.placeGridRow(l,"listgt","grand-total")}function H(e){if(e?.aborted){const t=new Error("报表排版已取消");throw t.name="AbortError",t}}function ae(e){const t=e.groups??(e.groupBy?[e.groupBy]:[]);if(t.length>16)throw new Error("列表最多支持 16 级分组");return t}function Ee(e){const t=Je(e),r=t.columns.reduce((o,a)=>o+a.widthMm,0),n=r>t.widthMm?t.widthMm/r:1;return n===1?t:{...t,columns:t.columns.map(o=>({...o,widthMm:o.widthMm*n}))}}function wr(e,t,r){const n=e.detail;if(!n)return;const o=new Set;for(const l of t){const d=ge(l[n.parentKey]);if(o.has(d))throw new Error("主从明细的主表关联键重复");o.add(d)}const a=r.datasets[n.dataset]??[],s=new Map,i=[];for(const l of a){const d=l[n.foreignKey];if(!nt(d)&&n.unmatched==="ignore")continue;const f=ge(d);if(!o.has(f)){if(n.unmatched!=="ignore")throw new Error(`明细数据集 ${n.dataset} 存在未关联的业务键`);continue}const u=s.get(f);u?u.push(l):s.set(f,[l]),i.push(l)}const c=Ee({...e,id:`${e.id??e.dataset}:detail`,dataset:n.dataset,rowKey:n.rowKey,revisionField:n.revisionField,sourceTokenField:n.sourceTokenField,computed:void 0,columns:n.columns,headerGrid:void 0,rowHeightMm:n.rowHeightMm??e.rowHeightMm,detail:void 0});return{list:c,inter:{...Re(c,r.measurer,i,r.signal),rowHeightFloorMm:c.rowHeightMm??0},rows:s,sources:oe(c,i)}}function nt(e){return typeof e=="string"&&!!e.trim()||typeof e=="number"&&Number.isFinite(e)}function ge(e){if(!nt(e))throw new Error("主从关联键必须是非空字符串或有限数字");return Ze(e)}function*yr(e,t,r,n,o){if(!r)return;const a=r.rows.get(ge(t[e.detail.parentKey]))??[];if(!a.length)return;const s={id:`${n.tableId}:detail`,columnKeys:r.list.columns.map(i=>i.field),title:e.detail.label};e.detail.label&&o.placeGridRow({...ee(r.inter,n.measurer,e.detail.label,new Map,{},r.list.columns.length),table:s},"listdl","group-header"),e.detail.header!==!1&&o.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:s},"listdh","header"),yield*n.takePages();for(const i of a)H(n.signal),o.placeGridRow({...Y(r.inter,i,n.measurer),table:s},"listdr","body",r.sources.get(i)),yield*n.takePages()}function ot(e){if(e.matrix||e.detail||e.groups?.length||e.groupBy||e.rowVisibleWhen)throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");if(e.rowKey&&e.rowKey!==e.tree.idField)throw new Error("树形布局的 rowKey 应与 idField 一致");if(!e.columns.some(t=>t.field===e.tree.labelField&&!t.hidden))throw new Error("树形布局需要可见的标签列");_.validateTreeComputed(e.tree,e.computed)}function br(e,t,r){ot(e);const n=_.createTreeTable(t,e.tree,{signal:r.signal,computed:e.computed?.length?{fields:e.computed,formula:r.formula}:void 0}),o={...e,rowKey:e.tree.idField},a=oe(o,n.entries.map(c=>c.original)),s=new Map,i=new WeakMap;for(const c of n.entries)s.set(c.row,a.get(c.original)),i.set(c.row,c);return{list:o,rows:n.rows,sources:s,treeRows:i,totalRows:n.leaves}}function vr(e,t){if(e.cardinality==="record"){if(t.length>1)throw new Error(`单记录区域 ${e.id??e.dataset} 仅允许 0 或 1 行数据`);if(e.tree||e.matrix||e.detail||e.groups?.length||e.groupBy||e.grandTotal||e.rowVisibleWhen)throw new Error("单记录区域不能配置树、矩阵、主从、分组、总计或行过滤");if(!t.length)return{list:{...e,columns:e.columns.map(r=>({...r,editable:!1}))},rows:[{}],sources:new Map}}}function at(e,t,r){const n=r.prepared.get(e);if(n)return n;const o=vr(e,t);if(o)return r.prepared.set(e,o),o;if(e.tree){const c=br(e,t,r);return r.prepared.set(e,c),c}let a=e.computed?.length?k.computeDataset(t,{fields:e.computed,signal:r.signal,formula:r.formula}).rows:t;const s=a===t?void 0:new Map(a.map((c,l)=>[c,t[l]]));e.rowVisibleWhen&&(a=a.filter(k.compileReportPredicate(e.rowVisibleWhen)));const i=Gt(e,a);if(!e.matrix){const c=oe(e,s?a.map(l=>s.get(l)):a);i.sources=s?new Map(a.map(l=>[l,c.get(s.get(l))])):c}return r.prepared.set(e,i),i}function Mr(e,t,r,n){if(!n.flow)return;const{current:o,templatePage:a}=n,s=Math.max(o.marginTopMm,X(a)),i=Math.max(n.startTop??e.topMm,s),c=(e.header===!1?0:t.headerHeightMm)+(r[0]?Y(t,r[0],n.measurer).heightMm:0);i+c<=Z(a,o)+.001||i<=s+.001||(n.pushCurrent(),o.components=[],o.heightMm=a.heightMm,a.layout==="wide"&&(o.marginTopMm=0,o.marginBottomMm=0),n.startTop=Math.max(o.marginTopMm,X(a)))}function*Sr(e,t,r){const n=at(e,t,r),o=n.rows;e=n.list,e.layout==="wide"&&(r.current.widthMm=Math.max(r.current.widthMm,e.leftMm+e.widthMm+r.current.marginRightMm));const a=n.sources??oe(e,o),s=Ee(e),i=ae(s),c={...Re(s,r.measurer,o,r.signal),rowHeightFloorMm:s.rowHeightMm??0,matrix:n.matrix,...n.treeRows?{tree:{list:s,rows:n.treeRows}}:{}};Mr(s,c,o,r);const l=gr(s,c,r),d=wr(s,o,r),f=ar((m,g)=>ee(c,r.measurer,m,new Map,g??{},s.columns.length));let u;for(const m of et(o,i)){if(H(r.signal),m.kind==="row")l.placeGridRow(u??Y(c,m.row,r.measurer),"listr",Ht(n.matrix,m.row),a.get(m.row)),u=void 0,yield*r.takePages(),yield*yr(s,m.row,d,r,l);else if(m.kind==="groupHeader"){const g=f(m.depth,m.firstRow,m.label,m.group.headerStyle);if(m.group.keepWithNext!==!1){u??=Y(c,m.firstRow,r.measurer);let b=0;for(let y=m.depth+1;y<i.length;y++){const w=i[y],h=(w.headerTemplate??"{value}").replace(/\{value\}/g,S.listCellText(m.firstRow[w.field]));b+=f(y,m.firstRow,h,w.headerStyle).heightMm}l.keepTogether(g.heightMm+b+u.heightMm)}l.placeGridRow(g,"listg","group-header"),m.group.repeatHeader&&l.setGroupHeader(m.depth,g)}else if(m.kind==="subtotal"){const g=m.group.subtotal??[],b=m.group.aggregates??[],y=ee(c,r.measurer,m.label,tt(s.columns,m.rows,g,b),m.group.subtotalStyle??{},rt(s.columns,[...g,...b.map(w=>w.field)]));l.placeGridRow(y,"listst","subtotal")}else l.setGroupHeader(m.depth);yield*r.takePages()}pr(s,n.totalRows??o,c,r,l),r.finished?.(l.bottom()),yield*r.takePages()}function se(e){return e.kind!=="list"&&(e.pageAnchor!==void 0||e.kind==="text"&&typeof e.text=="string"&&(e.text.includes("{page}")||e.text.includes("{totalPages}")))}function ie(e,t){return{...e,...e.text===void 0?{}:{text:t(e.text)},...e.lines?{lines:e.lines.map(t)}:{},...e.richParagraphs?{richParagraphs:e.richParagraphs.map(r=>({...r,segments:r.segments.map(n=>({...n,...n.text===void 0?{}:{text:t(n.text)}}))}))}:{},...e.grid?{grid:{...e.grid,cells:e.grid.cells.map(r=>r.map(n=>n?{...n,...n.text===void 0?{}:{text:t(n.text)},...n.children?{children:n.children.map(o=>ie(o,t))}:{}}:null))}}:{}}}function xr(e){let t=!1;for(const r of e.pages)for(const n of r.components)se(n)&&ie(n,o=>(o.includes("{totalPages}")&&(t=!0),o));return t}function Rr(e,t,r,n,o,a){const s={pageWidthMm:t.widthMm,pageHeightMm:t.heightMm,...e.layout===void 0?{}:{layout:e.layout},marginTopMm:t.marginTopMm,marginBottomMm:t.marginBottomMm,marginLeftMm:t.marginLeftMm,marginRightMm:t.marginRightMm,components:t.components,...e.meta?{meta:e.meta}:{}},i=c=>{const l=c.replace(/\{page\}/g,String(n));return a===void 0?l:l.replace(/\{totalPages\}/g,String(a))};for(const c of r)s.components.push(ie(c,i));if(e.layout==="wide"){const c=s.components.reduce((l,d)=>Math.max(l,d.topMm+d.heightMm),0);s.marginBottomMm=o?e.marginBottomMm??0:0,s.pageHeightMm=Math.max(1,c+s.marginBottomMm)}return s}function Ce(e){return e.cells.reduce((t,r)=>t+r.reduce((n,o)=>n+(o?1+(o.children?.reduce((a,s)=>a+st(s),0)??0):0),0),0)}function st(e){return e.grid?Ce(e.grid):0}function ce(e){for(const t of["maxPages","maxCells","knownTotalPages"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<1))throw new RangeError(`${t} 应为正安全整数`);S.validateChartComponentLimit(e.maxChartComponents)}function Er(e,t){const r=at(e,t.datasets[e.dataset]??[],t),n=Ee(r.list),o={...Re(n,t.measurer,r.rows,t.signal),rowHeightFloorMm:n.rowHeightMm??0};return(n.header===!1?0:o.headerHeightMm)+r.rows.reduce((a,s)=>a+Y(o,s,t.measurer).heightMm,0)}function*Cr(e){const{templatePage:t,current:r}=e,n=new Map(t.components.map((a,s)=>[a,s])),o=(a,s,i)=>{const c=e.datasets[a.dataset];return Array.isArray(c)||e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id??""} 输出为空`),Sr(a,Array.isArray(c)?c:[],{...e,tableId:`${e.tableId}:${n.get(a)}`,startTop:s,finished:i,flow:!!t.flow})};if(t.flow){yield*Wt({page:t,active:()=>H(e.signal),top:()=>Math.max(r.marginTopMm,X(t)),bottom:()=>Z(t,r),append:a=>{r.components.push(...e.resolveChart(a))},nextPage:()=>{e.pushCurrent(),r.components=[],r.heightMm=t.heightMm,t.layout==="wide"&&(r.marginTopMm=0,r.marginBottomMm=0)},takePages:e.takePages,height:a=>Er(a,e),list:o});return}for(const a of t.components)se(a)||(a.kind==="list"?yield*o(a):r.components.push(...e.resolveChart(a)))}function*Q(e,t,r,n,o,a=new WeakMap,s){let i=0,c=0,l=0;const d=Dt(r.measurer??A.heuristicMeasurer),f=S.createChartResolver(t,r.signal,r.maxChartComponents),u=m=>`${m}_${(++i).toString(36)}`;for(const{pageIndex:m,page:g}of er(e,t,r)){H(r.signal);const b=sr(g),y=g.components.filter(se);let w=[];const h=(T=!1)=>{if(H(r.signal),r.maxPages!==void 0&&c>=r.maxPages)throw new S.PaginatePageLimitError(r.maxPages,c+1);if(r.maxCells!==void 0&&(l+=[...b.components,...y].reduce((I,L)=>I+st(L),0),l>r.maxCells))throw new S.PaginateCellLimitError(r.maxCells,l);w.push(Rr(g,b,y,++c,T,o))},x=()=>{const T=w;return w=[],T};yield*Cr({templatePage:g,current:b,warnings:n,nextId:u,pushCurrent:h,takePages:x,datasets:t,resolveChart:f,signal:r.signal,formula:r.formula,prepared:a,measurer:d,mmPerRow:r.mmPerRow??0,tableId:`table:${m}`}),h(!0),yield*x()}s&&(s.chartComponents=f.used())}function Pr(e,t,r={}){ce(r);let n=0;for(const o of Q(e,t,{...r,onWarning:void 0},[]))n++;return n}function*Tr(e,t,r={}){yield*kr(e,t,r)}function*kr(e,t,r,n){ce(r);const o=xr(e),a=new WeakMap;let s=r.knownTotalPages;if(o&&s===void 0){s=0;for(const l of Q(e,t,r,[],void 0,a))s++}const i=[];let c=0;for(const l of Q(e,t,r,i,s,a,n)){for(;c<i.length;c++)r.onWarning?.(i[c]);yield l}}function Pe(e,t,r={}){const n=typeof r=="number"?{mmPerRow:r}:r;ce(n);const o=[],a={chartComponents:0},s=[...Q(e,t,n,o,n.knownTotalPages,void 0,a)];return ct(e,n,s,o,a)}async function it(e,t,r={}){ce(r),H(r.signal);const n=[],o=[],a={chartComponents:0};let s=performance.now(),i=0;for(const c of Q(e,t,r,n,r.knownTotalPages,void 0,a))o.push(c),(++i>=8||performance.now()-s>=8)&&(await new Promise(l=>setTimeout(l,0)),H(r.signal),s=performance.now(),i=0);return H(r.signal),ct(e,r,o,n,a)}function ct(e,t,r,n,o){for(const a of r)a.components=a.components.map(s=>se(s)?ie(s,i=>i.replace(/\{totalPages\}/g,String(r.length))):s);return n.forEach(a=>t.onWarning?.(a)),{plan:{schemaVersion:C.RENDER_PLAN_SCHEMA_VERSION,...Se(e)?{requiresRecalculation:!0}:{},pages:r},warnings:n,...o}}function Ir(e){const t=e.columns.find(a=>!a.hidden)?.field;if(!t)return{groups:0,total:0};const r=ae(e),n=(a=[],s=[])=>a.includes(t)||s.some(i=>i.field===t),o=typeof e.grandTotal=="object"?e.grandTotal:void 0;return{groups:r.filter(a=>n(a.subtotal,a.aggregates)).length,total:Number(n(o?.fields??r[0]?.subtotal,o?.aggregates??r[0]?.aggregates))}}function Fr(e,t,r){ot(e);const n=_.flattenTreeInput(t[e.dataset]??[],e.tree,r),o=e.columns.filter(s=>!s.hidden).length,a=e.header===!1?0:e.headerGrid?Ce(e.headerGrid):o;return n.length*o+a+ +!!e.grandTotal*2*o}function $r(e,t,r={}){if(e.tree)return Fr(e,t,r.signal);if(e.matrix){let c=t[e.dataset]??[];e.computed?.length&&(c=k.computeDataset(c,{fields:e.computed,...r}).rows),e.rowVisibleWhen&&(c=c.filter(k.compileReportPredicate(e.rowVisibleWhen)));const l=We.estimateMatrixTable(c,e.matrix);return l.cells+(e.header===!1?0:l.columnCount*(e.matrix.hierarchy?e.matrix.columnFields.length+1:1))}const n=t[e.dataset]?.length??0,o=e.columns.filter(c=>!c.hidden).length,a=ae(e).length,s=Ir(e);let i=(n*(1+2*a+s.groups)+ +!!e.grandTotal*(1+s.total))*o;if(i+=e.header===!1?0:e.headerGrid?Ce(e.headerGrid):o,e.cardinality==="record"&&n===0&&(i+=o),e.detail){const c=t[e.detail.dataset]?.length??0,l=e.detail.columns.filter(d=>!d.hidden).length;i+=(c+n*(+(e.detail.header!==!1)+ +!!e.detail.label))*l}if(!Number.isSafeInteger(i))throw new RangeError("报表单元格估算超出安全整数预算");return i}class lt extends Error{constructor(t){super(t.map(r=>r.message).join(";")),this.issues=t,this.name="ReportValidationError"}}function Be(e,t,r){if(!Number.isSafeInteger(e)||e<1||e>r)throw new Error(`校验 ${t} 超出预算`);return e}function Or(e){if(e.aggregates&&e.scope!=="dataset")throw new Error("仅数据集规则允许汇总");if(e.aggregates&&(!Array.isArray(e.aggregates)||e.aggregates.length>64))throw new Error("校验汇总最多 64 项");const t=new Set;for(const r of e.aggregates??[]){if(k.computationFieldName(r.field),t.has(r.field))throw new Error("校验汇总字段重复");t.add(r.field),r.valueField!==void 0&&k.computationFieldName(r.valueField),r.weightField!==void 0&&k.computationFieldName(r.weightField),k.aggregateRows([],{...r,field:r.valueField??r.field})}}function dt(e){if(!Array.isArray(e)||e.length>256||Object.keys(e).length!==e.length)throw new Error("校验规则最多 256 条且不允许空位");const t=new Set;return e.map(r=>{if(!r||typeof r!="object")throw new Error("校验规则应为声明式对象");if(k.computationFieldName(r.id),t.has(r.id))throw new Error("校验规则 id 重复");if(t.add(r.id),r.field!==void 0&&k.computationFieldName(r.field),r.dataset!==void 0&&k.computationFieldName(r.dataset),typeof r.message!="string"||!r.message.trim()||r.message.length>2048)throw new Error("校验规则需要有界提示文案");if(r.severity!==void 0&&!["error","warning"].includes(r.severity))throw new Error("未知校验严重程度");if(r.scope!==void 0&&!["row","dataset"].includes(r.scope))throw new Error("未知校验范围");Or(r);const n={nodes:0},o=k.compileReportPredicate(r.assert,n),a=r.when?k.compileReportPredicate(r.when,n):void 0;return{rule:r,assert:o,when:a,checks:n.nodes}})}function Ge(e){if(e?.aborted){const t=new Error("报表校验已取消");throw t.name="AbortError",t}}function Ar(e,t,r,n){const o=n&&Object.prototype.hasOwnProperty.call(t,n)?t[n]:void 0;if(o!==void 0&&typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o)))throw new Error("校验定位需要稳定的文本或数值业务键");return{ruleId:e.id,rowIndex:r,...o===void 0?{}:{rowKey:o},field:e.field,severity:e.severity??"error",message:e.message}}function Nr(e,t){const r=t.computed?.length?{fields:t.computed,formula:t.formula,signal:t.signal}:void 0;if(t.tree){const o=_.createTreeTable(e,t.tree,{signal:t.signal,computed:r});if(o.rows.length>1e5)throw new Error("校验展开后数据最多 100000 行");return{rows:o.rows,summaryRows:o.leaves,rowKey:t.tree.idField}}const n=r?k.computeDataset(e,r).rows:e;return{rows:n,summaryRows:n,rowKey:t.rowKey}}function Lr(e,t){const r=new Set;e.forEach(n=>{if(!n||typeof n!="object"||Array.isArray(n))throw new Error("校验数据行应为对象");if(!t)return;const o=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0;if(!(typeof o=="string"&&o.trim())&&!(typeof o=="number"&&Number.isFinite(o)))throw new Error("校验定位需要稳定业务键");if(r.has(o))throw new Error("校验业务键重复");r.add(o)})}function jr(e,t){return ut(e,t,{checks:0})}function ut(e,t,r){if(!Array.isArray(e)||e.length>1e5)throw new Error("校验数据最多 100000 行");Ge(t.signal);const n=Be(t.maxChecks??2e6,"maxChecks",1e7),o=Be(t.maxIssues??1e3,"maxIssues",1e4);t.rowKey!==void 0&&k.computationFieldName(t.rowKey);const a=Nr(e,t),{rows:s,summaryRows:i,rowKey:c}=a;Lr(s,c);const l=dt(t.rules),d=l.reduce((u,m)=>u+(m.rule.scope==="dataset"?m.checks+i.length*(m.rule.aggregates?.length??0):s.length*m.checks),0);if(r.checks+=d,r.checks>n)throw new Error("整批校验超出 maxChecks 预算");const f=[];for(const u of l)(u.rule.scope==="dataset"?[Object.fromEntries((u.rule.aggregates??[]).map(g=>[g.field,k.aggregateRows(i,{...g,field:g.valueField??g.field})]))]:s).forEach((g,b)=>{if(Ge(t.signal),!g||typeof g!="object"||Array.isArray(g))throw new Error("校验数据行应为对象");if(!(u.when&&!u.when(g)||u.assert(g))){if(f.length>=o)throw new Error("校验问题超出 maxIssues 预算,请缩小范围");f.push(Ar(u.rule,g,u.rule.scope==="dataset"?void 0:b,u.rule.scope==="dataset"?void 0:c))}});return f}function ft(e,t="allow"){if(!["allow","block"].includes(t))throw new Error("未知校验警告策略");if(!Array.isArray(e)||e.length>1e4||e.some(r=>!r||!["error","warning"].includes(r.severity)||typeof r.ruleId!="string"||!r.ruleId.trim()||typeof r.message!="string"||!r.message.trim()))throw new Error("校验问题结构无效");if(e.some(r=>r.severity==="error"||t==="block"))throw new lt(e)}function Ve(e,t,r){const n=e.get(t);if(n&&JSON.stringify(n)!==JSON.stringify(r))throw new Error("同一数据集的校验计算/业务键存在歧义,请统一绑定");e.set(t,r)}function Kr(e,t,r,n=[]){dt(t.rules);const o=[],a={checks:0};for(const[i,c]of e.entries()){const l=new Map;for(const d of c.template.pages)for(const f of d.components)f.kind==="list"&&(Ve(l,f.dataset,{rowKey:f.tree?.idField??f.rowKey,computed:f.computed,tree:f.tree}),f.detail&&Ve(l,f.detail.dataset,{rowKey:f.detail.rowKey}));for(const[d,f]of l){const u=t.rules.filter(m=>!m.dataset||m.dataset===d);if(u.length&&(o.push(...ut(c.datasets[d]??[],{...t,rules:u,...f,formula:n[i],signal:r},a).map(m=>({...m,dataset:d,sourceScope:c.sourceScope}))),o.length>(t.maxIssues??1e3)))throw new Error("整批候选校验问题超出 maxIssues 预算")}}const s=new Set(e.flatMap(i=>i.template.pages.flatMap(c=>c.components.flatMap(l=>l.kind==="list"?[l.dataset,...l.detail?[l.detail.dataset]:[]]:[]))));if(t.rules.some(i=>i.dataset&&!s.has(i.dataset)))throw new Error("校验目标数据集不存在");return o}function mt(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function gt(e,t,r){const n=e.grid;if(!n)return null;const o=n.cells[t];if(!o)return null;const s=C.resolveGridLayout(n,e.widthMm,e.heightMm).cells.filter(c=>c.ri===t).findIndex(c=>c.ci===r),i=o[s];return i?{cell:i,sourceColumnIndex:s}:null}function Dr(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function Hr(e,t){return e.valueType?e.valueType:typeof t=="number"?"number":typeof t=="boolean"?"boolean":t===null&&e.numberFormat&&/[0#?]/.test(e.numberFormat)?"number":"text"}function Br(e,t){if(e.derived)return"derived";if(e.editable===!1)return"cell";if(e.formula!==void 0)return"formula";if(e.children?.length||e.richParagraphs?.length)return"complex";if(t.table&&t.table.role!=="body"&&e.editable!==!0)return"structure"}function Gr(e,t){const r=e.table;if(r)return{id:r.id,rowIndex:r.rowIndex+t.rowIndex,role:r.role,columnKey:r.columnKeys[t.columnIndex]}}function Vr(e,t,r){if(e.derived)return;if(e.source)return{...e.source};const n=t.table?.source,o=t.table?.columnKeys[r.columnIndex];if(!(!n||n.rowKey===void 0||o===void 0))return{...n,rowKey:n.rowKey,field:o}}function he(e,t,r){const n=Dr(r),o=Br(r,e);return{address:{...t},cell:r,component:e,value:n,valueType:Hr(r,n),table:Gr(e,t),source:Vr(r,e,t),editable:o===void 0,readOnlyReason:o}}function le(e,t){if(!mt(t))return null;const r=e.pages[t.pageIndex]?.components[t.componentIndex];if(!r)return null;const n=gt(r,t.rowIndex,t.columnIndex);return n?he(r,t,n.cell):null}function ht(e,t=!0){const r=new Map;function n(i){if(!i.grid)return;let c=r.get(i);if(!c){const l=C.resolveGridLayout(i.grid,i.widthMm,i.heightMm),d=new Map,f=new Map;for(const u of l.cells){const m=d.get(u.ri)??0;d.set(u.ri,m+1);const g=i.grid.cells[u.ri]?.[m];g&&f.set(`${u.ri}:${u.ci}`,g)}c={layout:t?l:void 0,cells:f},r.set(i,c)}return c}function o(i){if(!mt(i))return null;const c=e.pages[i.pageIndex]?.components[i.componentIndex];if(!c)return null;const l=n(c)?.cells.get(`${i.rowIndex}:${i.columnIndex}`);return l?he(c,i,l):null}function*a(i,c){const l=e.pages[i]?.components[c],d=l&&n(l);if(d)for(const f of s(l).cells){const u=d.cells.get(`${f.ri}:${f.ci}`);u&&(yield he(l,{pageIndex:i,componentIndex:c,rowIndex:f.ri,columnIndex:f.ci},u))}}function s(i){const c=n(i);return c&&(c.layout??C.resolveGridLayout(i.grid,i.widthMm,i.heightMm))}return{resolve:o,entries:a,layout:s}}function V(e){return ht(e,!1).resolve}class M extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function _r(e,t){let r=e.trim();const n=t&&r.endsWith("%");if(n&&(r=r.slice(0,-1).trim()),/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?(?:[eE][+-]?\d+)?$/.test(r)&&(r=r.replace(/,/g,"")),!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(r))throw new M("number");return Number(r)/(n?100:1)}function Wr(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new M("number");const r=typeof e=="number"?e:_r(e,ze.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new M("number");return r}function zr(e){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e=="boolean")return e;const t=String(e).trim().toLowerCase();if(["true","yes","是","1"].includes(t))return!0;if(["false","no","否","0"].includes(t))return!1;throw new M("boolean")}function Te(e,t){return e.valueType==="number"?Wr(t,e):e.valueType==="boolean"?zr(t):t===null?null:String(t)}function Jr(e,t){const r=t.cell.text,o=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(a=>a.includes(r??""));return o?o[e?0:1]:String(e)}function W(e,t){return t===null?"":typeof t=="boolean"?Jr(t,e):typeof t=="number"?ze.formatExcelNumber(t,e.cell.numberFormat):String(t)}function qr(e,t,r){const n=le(e,t);if(!n)throw new M("missing");return z(n,r)}function z(e,t){if(!e.editable)throw new M("readonly");const r=Te(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:r,text:W(e,r)}}function Ur(e,t){const r=e.table,n=t.table;return!r||!n||r.columnKey===void 0?!1:r.id===n.id&&r.rowIndex===n.rowIndex&&r.role===n.role&&r.columnKey===n.columnKey}function pt(e,t,r){const n=e.grid,{rowIndex:o,columnIndex:a}=t.address,s=gt(e,o,a),i=[...n.cells],c=[...i[o]],l=W(t,r.value),d={...s.cell,value:r.value,text:l,rawText:l};return c[s.sourceColumnIndex]=d,i[o]=c,{...e,grid:{...n,cells:i}}}function Xr(e,t){const r=e.table?.columnKeys,n=t.table?.columnKey;return r&&n!==void 0?r.flatMap((o,a)=>o===n?[a]:[]):[]}function Yr(e,t,r,n,o,a){const s=t.table,i=o.table;if(!s||!i||s.id!==i.id||s.role!==i.role||!t.grid)return t;const c=i.rowIndex-s.rowIndex;if(c<0||c>=t.grid.cells.length)return t;let l=t;for(const d of Xr(t,o)){const f=le(e,{pageIndex:r,componentIndex:n,rowIndex:c,columnIndex:d});f?.editable&&Ur(o,f)&&(l=pt(l,f,a))}return l}function Qr(e,t,r,n,o,a){const s=o.address;return o.table?.columnKey!==void 0?Yr(e,t,r,n,o,a):s.pageIndex===r&&s.componentIndex===n?pt(t,o,a):t}function de(e,t){const r=t.source;if(!r)return!1;const n=e.source;return!n||["sourceScope","datasetId","rowKey","field","revision","sourceToken"].some(o=>!Object.is(n[o],r[o]))}function Zr(e,t){const r=le(e,t.address);if(!r)throw new M("missing");if(!r.editable)throw new M("readonly");if(de(r,t))throw new M("conflict");if(!Object.is(r.value,t.previousValue)||(r.cell.text??"")!==t.previousText)throw new M("conflict");const n=Te(r,t.value),o={...t,value:n,text:W(r,n)};if(Object.is(n,r.value)&&o.text===r.cell.text)return e;const a=e.pages.map((s,i)=>{const c=s.components.map((l,d)=>Qr(e,l,i,d,r,o));return c.every((l,d)=>l===s.components[d])?s:{...s,components:c}});return{...e,pages:a}}function wt(e){const t=[];for(const r of e.template.pages)for(const n of r.components)n.kind==="list"&&(t.push(n.tree?{...n,rowKey:n.tree.idField}:n),n.detail&&t.push({...n.detail,relation:{detail:n.detail,parentRows:e.datasets[n.dataset]??[]}}));return t}function J(e){return JSON.stringify([e.sourceScope,e.datasetId])}function te(e){return JSON.stringify([e.sourceScope,e.datasetId,e.rowKey])}function yt(e){const t=new Map,r=new Set;return e.forEach((n,o)=>{for(const a of wt(n)){if(!a.rowKey)continue;const s=a.relation,i=s?new Set(s.parentRows.map(c=>JSON.stringify(c[s.detail.parentKey]))):void 0;(n.datasets[a.dataset]??[]).forEach((c,l)=>{if(s&&!i.has(JSON.stringify(c[s.detail.foreignKey])))return;const d=c[a.rowKey];if(typeof d!="string"&&typeof d!="number")return;const f=`${o}:${a.dataset}:${l}:${a.rowKey}`;if(r.has(f))return;r.add(f);const u=te({sourceScope:n.sourceScope,datasetId:a.dataset,rowKey:d}),m=t.get(u)??[];m.push({partIndex:o,dataset:a.dataset,rowIndex:l,row:c,binding:a}),t.set(u,m)})}}),n=>{const o=t.get(te(n));if(!o?.length)throw new M("missing");if(new Set(o.map(a=>`${a.partIndex}:${a.dataset}`)).size!==o.length)throw new M("conflict");return o}}function bt(e,t){const r=e.map(o=>({...o,datasets:{...o.datasets}})),n=new Map;for(const{row:o,field:a,value:s}of t){const i=r[o.partIndex],c=JSON.stringify([o.partIndex,o.dataset]);let l=n.get(c);l||(i.datasets[o.dataset]=[...i.datasets[o.dataset]],n.set(c,l=new Set));const d=i.datasets[o.dataset];l.has(o.rowIndex)||(d[o.rowIndex]={...d[o.rowIndex]},l.add(o.rowIndex));const f=d[o.rowIndex];Object.prototype.hasOwnProperty.call(f,a)?f[a]=s:Object.defineProperty(f,a,{value:s,enumerable:!0,writable:!0,configurable:!0})}for(const o of n.keys()){const[a,s]=JSON.parse(o);k.forkComputedDataset(e[a].datasets[s],r[a].datasets[s])}return r}function en(e,t,r){const n=[],o=new Set;return e.forEach((a,s)=>{for(const i of wt(a))t.has(J({sourceScope:a.sourceScope,datasetId:i.dataset}))&&(a.datasets[i.dataset]??[]).forEach((c,l)=>{const d={partIndex:s,dataset:i.dataset,rowIndex:l,row:c,binding:i};for(const[f,u]of[[i.revisionField,r.revision],[i.sourceTokenField,r.sourceToken]]){if(!f||u===void 0)continue;const m=`${s}:${i.dataset}:${l}:${f}`;o.has(m)||(o.add(m),n.push({row:d,field:f,value:u}))}})}),n}function vt(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const n=new Set(t.edits.flatMap(o=>o.source?[J(o.source)]:[]));return ke(e,new Map([...n].map(o=>[o,r])))}function ke(e,t){if(!t.size)return e;function r(a){const s=a.datasetId&&t.get(J({...a,datasetId:a.datasetId}));return!s||(s.revision===void 0||Object.is(s.revision,a.revision))&&(s.sourceToken===void 0||s.sourceToken===a.sourceToken)?a:{...a,...s.revision!==void 0?{revision:s.revision}:{},...s.sourceToken!==void 0?{sourceToken:s.sourceToken}:{}}}function n(a){const s=a.map(i=>{const c=i.table?.source?r(i.table.source):void 0,l=i.table&&c!==i.table.source?{...i.table,source:c}:i.table,d=i.grid?.cells.map(u=>{const m=u.map(g=>{if(!g)return g;const b=g.source?r(g.source):void 0,y=g.children?n(g.children):void 0;return b===g.source&&y===g.children?g:{...g,source:b,children:y}});return m.some((g,b)=>g!==u[b])?m:u}),f=i.grid&&d?.some((u,m)=>u!==i.grid.cells[m])?{...i.grid,cells:d}:i.grid;return l!==i.table||f!==i.grid?{...i,table:l,grid:f}:i});return s.some((i,c)=>i!==a[c])?s:a}const o=e.pages.map(a=>{const s=n(a.components);return s!==a.components?{...a,components:s}:a});return o.some((a,s)=>a!==e.pages[s])?{...e,pages:o}:e}function tn(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function _e(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):tn(e.address)}function rn(e,t){if(!t.length)return e;const r=new Map(t.map(c=>[_e(c),c])),n=new Set(t.flatMap(c=>c.table?[c.table.id]:[])),o=new Set(t.map(c=>`${c.address.pageIndex}:${c.address.componentIndex}`)),a=V(e);function s(c,l,d){const f=c.grid;if(!f||!o.has(`${l}:${d}`)&&!n.has(c.table?.id??""))return c;const u=new Map,m=new Map;for(const g of C.resolveGridLayout(f,c.widthMm,c.heightMm).cells){const b=m.get(g.ri)??0;m.set(g.ri,b+1);const y=a({pageIndex:l,componentIndex:d,rowIndex:g.ri,columnIndex:g.ci}),w=y&&r.get(_e(y));if(!w||!y.editable)continue;const h=u.get(g.ri)??[...f.cells[g.ri]],x=W(y,w.value);Object.is(y.value,w.value)&&x===y.cell.text||(h[b]={...g.cell,value:w.value,text:x,rawText:x},u.set(g.ri,h))}return u.size?{...c,grid:{...f,cells:f.cells.map((g,b)=>u.get(b)??g)}}:c}const i=e.pages.map((c,l)=>{const d=c.components.map((f,u)=>s(f,l,u));return d.every((f,u)=>f===c.components[u])?c:{...c,components:d}});return i.every((c,l)=>c===e.pages[l])?e:{...e,pages:i}}function N(e){const t=e.source;if(t)return JSON.stringify([t.sourceScope,t.datasetId,t.rowKey,t.field]);const r=e.table;if(r?.columnKey!==void 0)return JSON.stringify([r.id,r.role,r.rowIndex,r.columnKey]);const n=e.address;return JSON.stringify([n.pageIndex,n.componentIndex,n.rowIndex,n.columnIndex])}function nn(e,t,r){if(typeof r!="string"||!r.trim()||!Array.isArray(t))throw new M("missing");if(t.length>1e4)throw new M("limit");const n=new Set,o=V(e),a=t.map(({address:s,value:i})=>{const c=o(s);if(!c)throw new M("missing");const l=z(c,i),d=N(l);if(n.has(d))throw new M("duplicate");return n.add(d),l});return{requestId:r,edits:a}}function on(e,t){if(t.edits.length>1e4)throw new M("limit");const r=V(e),n=new Set,o=t.edits.map(a=>{const s=r(a.address);if(!s)throw new M("missing");const i=N(a);if(n.has(i))throw new M("duplicate");if(n.add(i),de(s,a)||!Object.is(s.value,a.previousValue)||(s.cell.text??"")!==a.previousText)throw new M("conflict");return z(s,a.value)});return rn(e,o)}function an(e){const t=new Map;for(const r of e){const n=N(r),o=t.get(n),a=o?{...r,previousValue:o.previousValue,previousText:o.previousText}:{...r};Object.is(a.previousValue,a.value)?t.delete(n):t.set(n,a)}return[...t.values()]}function Mt(e){const t=new Map,r=V(e);return e.pages.forEach((n,o)=>n.components.forEach((a,s)=>{if(!(!a.grid||a.table?.role!=="body"))for(let i=0;i<a.grid.cells.length;i++)for(let c=0;c<a.table.columnKeys.length;c++){const l=r({pageIndex:o,componentIndex:s,rowIndex:i,columnIndex:c});l?.source&&l.editable&&t.set(N(l),l)}})),t}function sn(e,t,r){const n=Mt(e),o=V(e);return t.map(a=>{const s=a.source?n.get(N(a)):o(a.address);if(!s||N(s)!==N(a))throw new M("missing");return{address:{...s.address},value:a[r]}})}function St(e,t){if(++e.nodes>1e6||t>128)throw new M("limit")}function re(e,t){const r=Object.getOwnPropertyDescriptor(e,t);if(!r||r.get||r.set)throw new M("conflict");return r.value}function Ie(e){if(Object.getOwnPropertyDescriptor(e,"toJSON"))throw new M("conflict");const t=Object.getPrototypeOf(e);if(Array.isArray(e)&&(t!==Array.prototype||Object.keys(e).length!==e.length))throw new M("conflict");if(!(e instanceof Date)&&!Array.isArray(e)&&t!==Object.prototype&&t!==null)throw new M("conflict");for(const r of Reflect.ownKeys(e))if(!(Array.isArray(e)&&r==="length")){if(typeof r=="symbol"||!Object.getOwnPropertyDescriptor(e,r)?.enumerable)throw new M("conflict");if(e instanceof Date||Array.isArray(e)&&!/^(0|[1-9]\d*)$/.test(r))throw new M("conflict")}}function xt(e,t,r,n,o,a){if(St(n,o),typeof e=="function"||typeof e=="symbol")throw new M("conflict");if(e===null||typeof e!="object")return;if(Ie(e),r.has(e))throw new M("conflict");if(a?.has(e))return;a?.add(e),r.add(e);const s=Object.keys(e),i=s.map(c=>re(e,c));t.push({object:e,prototype:Object.getPrototypeOf(e),keys:s,values:i,...e instanceof Date?{date:Date.prototype.getTime.call(e)}:{},...Array.isArray(e)?{length:e.length}:{}});for(const c of i)xt(c,t,r,n,o+1,a);r.delete(e)}function cn(e){const{object:t,keys:r,values:n}=e;if(Ie(t),Object.getPrototypeOf(t)!==e.prototype||Object.getOwnPropertyDescriptor(t,"toJSON")||e.date!==void 0&&!Object.is(Date.prototype.getTime.call(t),e.date)||e.length!==void 0&&t.length!==e.length)return!1;const o=Object.keys(t);return o.length===r.length&&r.every((a,s)=>o[s]===a&&Object.is(re(t,a),n[s]))}function ln(e){return Rt(e)}function dn(e){return Rt(e,new Set)}function Rt(e,t){const r=[];return xt(e,r,new Set,{nodes:0},0,t),()=>{try{return r.every(cn)}catch{return!1}}}function ne(e,t,r,n=!1){if(St(t,r),n){if(typeof e=="function"||typeof e=="symbol")throw new M("conflict");e!==null&&typeof e=="object"&&Ie(e)}if(e===null||typeof e!="object")return e;if(e instanceof Date)return new Date(Date.prototype.getTime.call(e));if(Array.isArray(e)){const o=[];for(let a=0;a<e.length;a++)o[a]=ne(re(e,String(a)),t,r+1,n);return o}return Object.fromEntries(Object.keys(e).map(o=>[o,ne(re(e,o),t,r+1,n)]))}function un(e){return ne(e,{nodes:0},0,!0)}function fn(e){const t=ne(e,{nodes:0},0);for(const r of t)for(const n of Object.values(r.datasets))k.registerComputedDataset(n);return t}async function mn(e,t,r={}){return(await Et(e,t,r)).plan}async function Et(e,t,r={}){return it(e,t,{...r,knownTotalPages:void 0})}function gn(e){return e.computed||e.groupBy||e.groups||e.grandTotal||e.tree||e.matrix||e.detail||e.rowVisibleWhen||e.headerGrid?!1:e.columns.every(t=>!t.format&&!t.rules&&!t.visibleWhen&&!t.visual)}function hn(e,t){return e.length!==t.length||t.some(r=>r?.measurer||r?.formula||r?.mmPerRow||r?.knownTotalPages!==void 0)?!1:e.every(r=>!r.template.repeat&&r.template.pages.every(n=>!n.flow&&n.components.every(o=>o.kind==="list"?gn(o):!o.binding&&!o.chartBinding&&!o.grid&&!o.table&&!o.richParagraphs)))}function pn(e){const t=new Map;for(const r of e){if(!r.source||typeof r.value!="string"||typeof r.previousValue!="string"||r.previousText!==r.previousValue||![r.previousValue,r.value].every(a=>a.trim().length&&a.length<=16384&&!/[\r\n]/.test(a)))return null;const n=te(r.source),o=t.get(n)??new Map;o.set(r.source.field,r),t.set(n,o)}return t}function Fe(e){return!e.source&&!e.formula&&!e.derived&&!e.richParagraphs&&!e.children&&!e.dataBar&&!e.numberFormat&&!e.colSpan&&!e.rowSpan&&!e.indentMm&&!e.style?.rotateDeg}function wn(e){return e.pages.every(t=>t.components.every(r=>!r.grid||r.grid.cells.every(n=>n.every(o=>!!o&&Fe(o)))))}function yn(e,t,r,n){if(!Fe(e)||e.value!==t.previousValue||e.text!==t.previousText)return!1;const o=r-n*2,a=e.style,s=C.resolveFontSize(a).fontSizePt;if(!Number.isFinite(o)||o<1||!Number.isFinite(s)||s<=0)return!1;const i={fontSizePt:s,fontFamily:a?.fontFamily??C.DEFAULT_FONT_FAMILY,italic:a?.italic,bold:a?.bold,letterSpacingPt:a?.letterSpacing};return A.wrapText(t.previousText,o,i,A.heuristicMeasurer).length===A.wrapText(t.value,o,i,A.heuristicMeasurer).length}function bn(e,t){const r=e.colWidthsMm;if(!r||r.length!==e.cells[0].length||r.length!==t.table.columnKeys.length)return!1;const n=r.reduce((o,a)=>o+a,0);return Number.isFinite(n)&&Math.abs(n-t.widthMm)<=Math.max(1e-7,n*1e-10)}function vn(e,t,r){const n=e.table?.source;if(e.table?.role!=="body"||n?.rowKey===void 0)return e;const o=t.get(te({...n,rowKey:n.rowKey}));if(!o)return e;const a=e.grid;if(!a||a.cells.length!==1||!bn(a,e)||e.style?.rotateDeg)return null;const s=a.cells[0],i=[...s];for(let c=0;c<s.length;c++){const l=s[c];if(!l||!Fe(l))return null;const d=o.get(e.table.columnKeys[c]);if(d){if(!yn(l,d,a.colWidthsMm[c],a.paddingMm??.5))return null;i[c]={...l,value:d.value,text:d.value},r.add(d)}}return i.some((c,l)=>c!==s[l])?{...e,grid:{...a,cells:[i]}}:e}async function Mn(e,t,r){const n=pn(t);if(!n||!t.length)return null;const o=new Set,a=[];let s=0;for(const c of e.pages){const l=[];for(const d of c.components){if(r?.aborted)return null;const f=vn(d,n,o);if(!f)return null;l.push(f),++s%128===0&&await new Promise(u=>setTimeout(u,0))}a.push(l.some((d,f)=>d!==c.components[f])?{...c,components:l}:c)}if(o.size!==t.length)return null;const i={...e,pages:a};return B.validateRenderPlan(i).ok?i:null}function Sn(e,t,r){let n=hn(t,r),o=e,a;function s(c){if(o=c,a=void 0,!!n){if(!wn(c)){n=!1;return}try{a=dn(c)}catch{n=!1}}}s(e);async function i(c,l,d){if(!n||c!==o||!a?.())return null;const f=a,u=await Mn(c,l,d);return u&&f()?{plan:u,unchanged:f}:null}return{candidate:i,publish:s}}const pe=new WeakMap;function xn(e){return pe.get(e)}function U(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function Ct(e,t){return e[t]===void 0?"":e[t]}function Rn(e,t){if(t.edits.length>1e4)throw new M("limit");const r=V(e),n=new Set,o=[],a=t.edits.map(s=>{const i=r(s.address);if(!i?.source)throw new M("missing");const c=N(s);if(n.has(c))throw new M("duplicate");if(n.add(c),de(i,s)||!Object.is(i.value,s.previousValue)||(i.cell.text??"")!==s.previousText)throw new M("conflict");return o.push(i),z(i,s.value)});return{batch:{requestId:t.requestId,edits:a},contexts:o}}function En(e,t){const r=yt(e);return t.flatMap(n=>{if(!n.source)throw new M("missing");return r(n.source).map(o=>{if(!Object.is(Ct(o.row,n.source.field),n.previousValue))throw new M("conflict");if(o.binding.rowKey===n.source.field)throw new M("readonly");return{row:o,field:n.source.field,value:n.value}})})}function fe(e,t,r){const n={...e,value:t,source:{...e.source,...r?.revision===void 0?{}:{revision:r.revision},...r?.sourceToken===void 0?{}:{sourceToken:r.sourceToken}}};return n.cell={...e.cell,value:n.value,text:W(n,n.value)},n}function Cn(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return[...e];const n=new Set(t.edits.flatMap(o=>o.source?[J(o.source)]:[]));return bt(e,en(e,n,r))}function Pn(e,t,r){const n=new Set(t.edits.map(o=>J(o.source)));for(const o of n)e.set(o,{...e.get(o),...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}});return n}function Tn(e,t){return $e(e,t)}function $e(e,t,r){let n=t.parts;const o=t.rebuild,a=[...t.validationFormulas??[]],s=r?Sn(e,n,r):void 0;let i=ln(n),c=e,l;const d=new Map,f=new Map;function u(b){if(b!==c)throw new M("conflict");if(l)return l;if(!i?.())throw new M("conflict");return fn(n)}async function m(b,y,w,h={}){U(h.signal),y={requestId:y.requestId,edits:y.edits.map(v=>({...v,address:{...v.address},source:v.source?{...v.source}:void 0,table:v.table?{...v.table}:void 0}))},w=w.map(v=>({...v,address:{...v.address},source:v.source?{...v.source}:void 0,table:v.table?{...v.table}:void 0,cell:{...v.cell}})),await new Promise(v=>setTimeout(v,0)),U(h.signal);const x=u(b),T=bt(x,En(x,y.edits)),I=await s?.candidate(b,y.edits,h.signal);U(h.signal);const L=ke(I?.plan??await o(T,h.signal),f);U(h.signal);let D=!1,p=[],E="allow",R=!1;function $(v){return R=!0,p=Object.freeze(Kr(T,v,h.signal,a).map(F=>Object.freeze({...F}))),R=!1,E=v.warningPolicy??"allow",p}return h.validation&&$(h.validation),{plan:L,get validationIssues(){return p},validate:$,commit(v){if(U(h.signal),D||c!==b)throw new M("conflict");if(I&&!I.unchanged())throw new M("conflict");if(v?.conflicts?.length)throw new M("conflict");if(R)throw new Error("候选规则校验未完成,不能提交");ft(p,E);const F=Cn(T,y,v),j=vt(L,y,v);if(v){const K=Pn(f,y,v);for(const[q,G]of d)K.has(J(G.source))&&d.set(q,fe(G,G.value,v))}return w.forEach((K,q)=>d.set(N(K),fe(K,y.edits[q].value,v))),D=!0,l=F,n=void 0,i=void 0,c=j,s?.publish(c),pe.set(c,g),c}}}const g={get plan(){return c},async prepare(b,y,w){const h=Rn(b,y);return m(b,h.batch,h.contexts,w)},async prepareHistory(b,y,w,h,x){if(!h.trim()||y.length>1e4)throw new M("limit");const T=u(b),I=yt(T),L=Mt(b),D=new Set,E=y.map(v=>{if(!v.source)throw new M("missing");const F=N(v);if(D.has(F))throw new M("duplicate");D.add(F);const j=L.get(F)??d.get(F);if(!j?.source)throw new M("missing");const K=I(j.source)[0];return fe(j,Ct(K.row,j.source.field))}).map((v,F)=>({context:v,edit:z(v,y[F][w])})).filter(({edit:v})=>!Object.is(v.previousValue,v.value)),R={requestId:h,edits:E.map(({edit:v})=>v)},$=E.map(({context:v})=>v);return{batch:R,contexts:$,prepared:await m(b,R,$,x)}}};return pe.set(e,g),g}function kn(e){const t=Pe(e.template,e.datasets,e.pagination).plan;return $e(t,{validationFormulas:[e.pagination?.formula],parts:[{template:e.template,datasets:e.datasets}],rebuild:(r,n)=>mn(r[0].template,r[0].datasets,{...e.pagination,signal:n})},[e.pagination])}let In=0;function Pt(){return`report-${Date.now()}-${++In}`}function we(e,t,r){if(!r?.aborted)try{const n=e?.({...t});n&&typeof n.then=="function"&&Promise.resolve(n).catch(()=>{})}catch{}}function Tt(e){const t=e.taskId??Pt(),r=(n,o,a)=>{we(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:n,status:o,...a===void 0?{}:{reportId:a}},e.signal)};return{taskId:t,progress(n,o,a){we(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:n,status:"started",completed:o,total:a},e.signal)},async run(n,o,a){r(n,"started",a);try{const s=await o();return r(n,"completed",a),s}catch(s){throw r(n,"failed",a),s}},runSync(n,o,a){r(n,"started",a);try{const s=o();return r(n,"completed",a),s}catch(s){throw r(n,"failed",a),s}}}}function Oe(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e,r=n=>typeof n=="string"&&n.trim().length>0&&n.length<=256;return!r(t.datasetId)||!r(t.field)||t.tableId!==void 0&&!r(t.tableId)||t.reportScope!==void 0&&(typeof t.reportScope!="string"||!t.reportScope.trim()||t.reportScope.length>4096)?!1:t.rowKey===void 0?!0:typeof t.rowKey=="string"?t.rowKey.trim().length>0&&t.rowKey.length<=1024:typeof t.rowKey=="number"&&Number.isFinite(t.rowKey)}function kt(e){return e==="missing-source"||e==="not-applicable"||e==="not-calculable"}function It(e){return e.target!==void 0&&!Oe(e.target)?!1:e.valueState===void 0||kt(e.valueState)&&e.target!==void 0}function Fn(e,t){if(Me.validateDatasetRows([],e),!Oe(t))throw new Error("数据说明目标无效");const r=e.fields.find(o=>o.field===t.field);if(!r)throw new Error("数据说明字段未在契约中声明");const n=[];return r.description&&n.push({code:"field-definition",severity:"info",message:r.description,target:{...t}}),r.calculation&&n.push({code:"field-calculation",severity:"info",message:r.calculation.description,target:{...t}}),n}function Ae(e,t,r={}){const n=new Map;for(const a of e.pages)for(const s of a.components){if(s.kind!=="list"||s.tree?.input!=="nested")continue;const i=n.get(s.dataset);if(i&&(i.childrenField??"children")!==(s.tree.childrenField??"children"))throw new Error("同一数据集的嵌套树应使用相同 childrenField");n.set(s.dataset,s.tree)}if(!n.size)return t;const o={...t};for(const[a,s]of n){const i=Math.min(s.maxRows??1e5,r.maxRows??1/0);o[a]=_.flattenTreeInput(t[a]??[],{...s,maxRows:i},r.signal)}return o}function $n(e,t,r={}){return Object.values(Ae(e,t,r)).reduce((n,o)=>n+o.length,0)}function On(e,t,r){const n=Me.datasetJsonSchema(r),o=e?.pages.flatMap(i=>i.components).find(i=>i.kind==="list"&&i.dataset===t&&i.tree?.input==="nested");if(!o||o.kind!=="list"||!o.tree)return n;const a=n.items,s=o.tree.childrenField??"children";return{...n,items:{$ref:"#/$defs/treeNode"},$defs:{treeNode:{...a,properties:{...a.properties,[s]:{anyOf:[{type:"null"},{type:"array",items:{$ref:"#/$defs/treeNode"}}]}}}}}}function Ne(e,t){return JSON.stringify([e,t])}function Le(e,t,r){return r===void 0?Ne(e,t):JSON.stringify(["shared",r])}function Ft(e,t,r){return e.map(n=>{const o=n.table?{...n.table,id:r(n.table.id),...n.table.source?{source:{...n.table.source,sourceScope:t}}:{}}:void 0,a=n.grid?.cells.map(s=>s.map(i=>!i||!i.source&&!i.children?i:{...i,...i.source?{source:{...i.source,sourceScope:t}}:{},...i.children?{children:Ft(i.children,t,r)}:{}}));return o||a?{...n,...o?{table:o}:{},...a?{grid:{...n.grid,cells:a}}:{}}:n})}function ye(e){return S.validateChartComponentLimit(e.maxChartComponents),{maxPages:e.maxPages,maxCells:e.maxCells,maxChartComponents:e.maxChartComponents??S.DEFAULT_CHART_COMPONENT_LIMIT,usedPages:0,usedCells:0,usedChartComponents:0}}function An(e,t){if(!e.repeat)return!1;const r=Object.prototype.hasOwnProperty.call(t,e.repeat.dataset)?t[e.repeat.dataset]:void 0;return Array.isArray(r)&&r.length===0}function Nn(e){const t=r=>r.grid?.cells.reduce((n,o)=>n+o.reduce((a,s)=>a+(s?1+(s.children?.reduce((i,c)=>i+t(c),0)??0):0),0),0)??0;return e.pages.reduce((r,n)=>r+n.components.reduce((o,a)=>o+t(a),0),0)}function be(e,t){return e===void 0?void 0:e-t}function me(e,t){return e===void 0?t:Math.max(1,Math.min(e,t??e))}function $t(e,t,r,n,o){S.validateChartComponentLimit(e?.maxChartComponents);const a=be(t.maxPages,t.usedPages),s=t.maxChartComponents-t.usedChartComponents;if(a!==void 0&&a<1&&r.pages.length&&!An(r,n))throw new S.PaginatePageLimitError(0,1);if(s<1&&r.pages.some(i=>i.components.some(c=>c.kind!=="list"&&c.chartBinding)))throw new S.PaginateChartComponentLimitError(s,1);return{...e,signal:o??e?.signal,maxPages:me(a,e?.maxPages),maxCells:me(be(t.maxCells,t.usedCells),e?.maxCells),maxChartComponents:me(s,e?.maxChartComponents)}}function Ot(e,t){const r=Nn(t.plan),n=be(e.maxCells,e.usedCells);if(n!==void 0&&r>n)throw new S.PaginateCellLimitError(n,r);e.usedPages+=t.plan.pages.length,e.usedCells+=r,e.usedChartComponents+=t.chartComponents}function At(e,t){return e instanceof S.PaginatePageLimitError&&t.maxPages!==void 0&&(e.limit===t.maxPages-t.usedPages||e.limit===0)?new S.PaginatePageLimitError(t.maxPages,t.usedPages+e.actual):e instanceof S.PaginateCellLimitError&&t.maxCells!==void 0?new S.PaginateCellLimitError(t.maxCells,t.usedCells+e.actual):e instanceof S.PaginateChartComponentLimitError&&e.limit===t.maxChartComponents-t.usedChartComponents?new S.PaginateChartComponentLimitError(t.maxChartComponents,t.usedChartComponents+e.estimated):e}function Ln(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...n}=e;return{...n,load:async o=>{const a=await t(o);O(o.signal);try{return r(a,o)}catch(s){throw new P("validate",`报表 ${o.reportId} 数据映射失败`,s)}}}}class P extends Error{constructor(t,r,n){super(r),this.name="ReportSourceError",this.code=t,this.cause=n}}function ue(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function O(e){if(e?.aborted)throw ue(e)}function ve(e,t){return t?new Promise((r,n)=>{const o=()=>t.removeEventListener("abort",a),a=()=>{o(),n(ue(t))};t.addEventListener("abort",a,{once:!0}),t.aborted&&a(),Promise.resolve(e).then(s=>{o(),r(s)},s=>{o(),n(s)})}):Promise.resolve(e)}function jn(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new P("validate",`报表 ${t} 的数据集应为对象`);for(const[r,n]of Object.entries(e))if(!Array.isArray(n)||n.some(o=>!o||typeof o!="object"||Array.isArray(o)))throw new P("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function Kn(e,t,r){const{reportId:n,signal:o}=t;try{const a=await ve(e(t),o);O(o);const s=B.validateReportTemplate(a);if(!s.ok)throw new P("validate",`报表 ${n} 模板校验失败:${s.errors.slice(0,3).map(i=>`${i.path}: ${i.message}`).join("; ")}`);return r.push(...s.warnings.map(i=>`${n}: ${i.path}: ${i.message}`)),a}catch(a){throw o?.aborted?ue(o):a instanceof P?a:a instanceof B.ReportTemplateError?new P("validate",`报表 ${n} 模板校验失败:${a.message}`,a):new P("fetch",`报表 ${n} 模板加载失败:${a instanceof Error?a.message:String(a)}`,a)}}async function Dn(e,t,r,n){const o=t.signal;let a;try{if(e.load)a=await ve(e.load(t),o);else if(e.provider){const s=await ve(e.provider.query(t),o);O(o),Hn(s,r),a=s.datasets,n?.(r,s)}else a=e.datasets??{}}catch(s){throw o?.aborted?ue(o):s instanceof P?s:new P("fetch",`报表 ${r} 取数失败:${s instanceof Error?s.message:String(s)}`,s)}return O(o),a}function Hn(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new P("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new P("validate",`报表 ${t} Provider ${r} 应为字符串`);if(e.diagnostics!==void 0&&(!Array.isArray(e.diagnostics)||e.diagnostics.some(r=>!r||typeof r.code!="string"||typeof r.message!="string"||!["info","warning","error"].includes(r.severity))))throw new P("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`);if(e.diagnostics?.some(r=>!It(r)))throw new P("validate",`报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`)}function Bn(e,t,r,n,o){try{t=Ae(n,t,{maxRows:e.dataValidation?.maxRows,signal:o})}catch(a){throw new P("validate",`报表 ${r} 树形数据无效:${a instanceof Error?a.message:String(a)}`,a)}for(const[a,s]of Object.entries(e.dataSchema??{})){let i;try{i=Me.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0,s,{...e.dataValidation,path:`$.datasets.${a}`})}catch(c){throw new P("config",`报表 ${r} 数据集 ${a} 字段契约配置无效`,c)}if(!i.ok)throw new P("validate",`报表 ${r} 数据集 ${a} 不符合字段契约:${i.issues[0]?.message}`,{issues:i.issues})}}async function Gn(e,t,r,n,o){try{let a;try{a=un(e)}catch{}const s=a??e,i=$t(t.pagination,n,s.template,s.datasets,o),c=a?await it(s.template,s.datasets,i):Pe(s.template,s.datasets,i);return Ot(n,c),{result:c,part:s}}catch(a){O(o);const s=At(a,n);throw new P("validate",`报表 ${r} 排版失败:${s instanceof Error?s.message:String(s)}`,s)}}function Nt(e,t,r,n,o){const a=new Map,s=i=>{let c=a.get(i);return c===void 0&&(c=JSON.stringify([r,n,i]),a.set(i,c)),c};for(const i of t.pages)e.push({...i,meta:{...i.meta,reportScope:Ne(r,n)},components:Ft(i.components,o??Le(r,n),s)})}async function Vn(e,t,r,n,o){const a=[],s=ye(n);for(const[l,d]of e.entries()){O(o);try{const f=await Et(d.template,d.datasets,$t(t[l]?.pagination,s,d.template,d.datasets,o));Ot(s,f),Nt(a,f.plan,l,r[l],d.sourceScope)}catch(f){throw At(f,s)}}const i={schemaVersion:C.RENDER_PLAN_SCHEMA_VERSION,...e.some(l=>Se(l.template))?{requiresRecalculation:!0}:{},pages:a},c=B.validateRenderPlan(i);if(!c.ok)throw new P("validate",`重算渲染计划校验失败:${c.errors[0]?.message}`);return i}function _n(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new P("config","maxPages 应为正安全整数");if(t.maxCells!==void 0&&(!Number.isSafeInteger(t.maxCells)||t.maxCells<1))throw new P("config","maxCells 应为正安全整数");try{ye(t)}catch(o){throw new P("config","maxChartComponents 应为 1..1000000 的安全整数",o)}function r(o){const a=Object.prototype.hasOwnProperty.call(e,o)?e[o]:void 0;if(!a)throw new P("config",`未注册报表 ${o}`);if(a.sourceScope!==void 0&&(typeof a.sourceScope!="string"||!a.sourceScope.trim()||a.sourceScope.length>512))throw new P("config","sourceScope 应为不超过 512 字符的非空字符串");return a}return Object.assign(async({reportIds:o,params:a,signal:s,onWarning:i,onQueryResult:c,...l})=>{O(s);const d=Tt({...l,signal:s}),f=[...o],u={...a};if(f.length===0)throw new P("config","缺少报表 ID");const m=f.map(r),g=d.runSync("validate",()=>m.map(p=>je.assertReportParams(p.params??(typeof p.template=="function"?[]:p.template.params)??[],u))),b=[],y=[],w=ye(t),h=[];for(const[p,E]of m.entries()){O(s);const R=f[p],$={reportId:R,params:g[p],signal:s},v=typeof E.template=="function"?await d.run("query",()=>Kn(E.template,$,h),R):E.template;$.params=d.runSync("validate",()=>je.assertReportParams(E.params??v.params??[],$.params),R);const F=await d.run("query",()=>Dn(E,$,R,(G,Lt)=>c?.(G,Lt,p)),R);d.runSync("validate",()=>{jn(F,R),t.onDatasets?.(R,F,v),Bn(E,F,R,v,s)},R),O(s);const j=Le(p,R,E.sourceScope),{result:K,part:q}=await d.run("layout",()=>Gn({template:v,datasets:F,sourceScope:j},E,R,w,s),R);y.push(q),Nt(b,K.plan,p,R,j),h.push(...K.warnings.map(G=>`${R}: ${G}`))}O(s);const x={schemaVersion:C.RENDER_PLAN_SCHEMA_VERSION,...y.some(p=>Se(p.template))?{requiresRecalculation:!0}:{},pages:b},T=d.runSync("validate",()=>{const p=B.validateRenderPlan(x);if(!p.ok)throw new P("validate",`渲染计划校验失败:${p.errors.slice(0,3).map(E=>`${E.path}: ${E.message}`).join("; ")}`);return p});h.push(...T.warnings.map(p=>`${p.path}: ${p.message}`));const I=m.map(p=>({...p,pagination:{...p.pagination}})),L={maxPages:t.maxPages,maxCells:t.maxCells,maxChartComponents:t.maxChartComponents};try{$e(x,{parts:y,validationFormulas:I.map(p=>p.pagination?.formula),rebuild:(p,E)=>Vn(p,I,f,L,E)},I.map(p=>p.pagination))}catch{h.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const D=i??t.onWarning??(p=>console.warn("[mach-report]",p));for(const p of h)O(s),D(p);return O(s),x},{getParamDefs:o=>jt.getReportParamDefs(e,o)})}const Wn=new Set([8,9,10,12,13]);function zn(e,t){const r=Array.isArray(e),n=Object.getPrototypeOf(e);if(n!==(r?Array.prototype:Object.prototype)&&!(n===null&&!r)||Object.getOwnPropertySymbols(e).length)throw t("input","快照应为普通 JSON 对象");const o=Object.getOwnPropertyNames(e).filter(a=>!(r&&a==="length"));if(r&&(o.length!==e.length||o.some((a,s)=>a!==String(s))))throw t("input","快照数组应为连续数组");return{array:r,keys:o}}function Jn(e){if(/^[\u0020-\u007e]*$/.test(e)&&!/["\\]/.test(e))return e.length+2;let t=2;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<32)t+=Wn.has(n)?2:6;else if(n===34||n===92)t+=2;else if(n<128)t++;else if(n<2048)t+=2;else if(n>=55296&&n<=57343){const o=e.charCodeAt(r+1);n<=56319&&o>=56320&&o<=57343?(t+=4,r++):t+=6}else t+=3}return t}function qn(e,t){const r=t.maxNodes??1e6;if(![t.maxBytes,r].every(u=>Number.isSafeInteger(u)&&u>0))throw t.error("budget","快照预算应为正安全整数");let n=0,o=0;const a=new Set,s=new Map;function i(u){if(u.length+2>t.maxBytes-o)throw t.error("budget","快照超过字节预算");const m=s.get(u);if(m!==void 0)return m;const g=Jn(u);return u.length<=256&&s.size<4096&&s.set(u,g),g}function c(u){if(o+=u,o>t.maxBytes)throw t.error("budget","快照超过字节预算")}function l(u,m){if(++n>r||m>64)throw t.error("budget","快照节点或深度超过预算");if(n%1024===0&&t.check?.(),typeof u=="string")return c(i(u)),u;if(u===null||typeof u=="boolean"||typeof u=="number"&&Number.isFinite(u))return c(String(u).length),typeof u=="number"&&Object.is(u,-0)?0:u;if(!u||typeof u!="object"||a.has(u))throw t.error("input","快照应为无循环的有限 JSON 值");return d(u,m)}function d(u,m){const{array:g,keys:b}=zn(u,t.error);a.add(u),c(2);const y=g?[]:{};let w=0;for(const h of b){const x=Object.getOwnPropertyDescriptor(u,h);if(x.get||x.set||!x.enumerable||["__proto__","constructor","prototype"].includes(h))throw t.error("input","快照不允许访问器或危险键");if(x.value===void 0&&!g)continue;c((w++?1:0)+(g?0:i(h)+1));const T=l(x.value===void 0?null:x.value,m+1);h in y?Object.defineProperty(y,h,{value:T,enumerable:!0,configurable:!0,writable:!0}):y[h]=T}return a.delete(u),y}t.check?.();const f=l(e,0);return t.check?.(),f}exports.DEFAULT_LABEL_PAGE_LIMIT=qe;exports.ReportCellEditError=M;exports.ReportSourceError=P;exports.ReportValidationError=lt;exports.applyReportCellEdit=Zr;exports.applyReportCellEditBatch=on;exports.applyReportEditResult=vt;exports.applyReportSourceMetadata=ke;exports.assertReportValidation=ft;exports.countTemplatePages=Pr;exports.createReportCellEdit=qr;exports.createReportCellEditBatch=nn;exports.createReportCellIndex=ht;exports.createReportCellResolver=V;exports.createReportEditSession=kn;exports.createReportSource=_n;exports.createReportTaskReporter=Tt;exports.defineReport=Ln;exports.editFromContext=z;exports.estimateListLayoutCells=$r;exports.explainDatasetField=Fn;exports.formatReportCellEdit=W;exports.getReportCellContext=le;exports.getReportEditSession=xn;exports.hasValidDataExplanation=It;exports.isReportDataTarget=Oe;exports.isReportValueState=kt;exports.notifyReportTaskEvent=we;exports.paginateTemplate=Pe;exports.paginateTemplatePages=Tr;exports.parseReportCellInput=Te;exports.projectListColumns=Je;exports.registerReportEditSession=Tn;exports.relocateReportCellEdits=sn;exports.reportCellEditKey=N;exports.reportOccurrenceScope=Ne;exports.reportSourceScope=Le;exports.reportTaskId=Pt;exports.snapshotReportJson=qn;exports.sourceChanged=de;exports.summarizeReportCellEdits=an;exports.templateDatasetJsonSchema=On;exports.templateDatasetRowCount=$n;exports.templateValidationDatasets=Ae;exports.validateReportDataset=jr;
@@ -0,0 +1 @@
1
+ "use strict";const m=require("./computed-DK6BruFz.cjs");function M(e,r){const l=()=>r.measures.map(c=>m.createAggregateAccumulator(c)),t=new Map,a=new Map,o=new Map,n=r.totals?l():void 0,s=(c,u)=>c?.forEach(i=>i.add(u));for(const c of e){const u=r.row(c),i=r.column(c);a.has(i.key)||a.set(i.key,i.label);let f=t.get(u.key);f||(f={label:u.label,cells:new Map,...r.totals?{totals:l()}:{}},t.set(u.key,f)),r.check(t.size,a.size);let d=f.cells.get(i.key);if(d||(d=l(),f.cells.set(i.key,d)),s(d,c),!r.totals)continue;let h=o.get(i.key);h||(h=l(),o.set(i.key,h)),s(f.totals,c),s(h,c),s(n,c)}return{groups:t,columns:a,columnTotals:o,totals:n}}function $(e,r){return JSON.stringify([e.slice(0,r.length),r.map(l=>[l===null?"null":typeof l,l])])}function x(e,r){return r.map(l=>{const t=Object.prototype.hasOwnProperty.call(e,l)?e[l]:null;if(t==null)return null;if(typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t))return t;throw new Error("矩阵维度必须是有限 JSON 标量")})}function N(e,r,l){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("矩阵层级应为对象");for(const t of[e.emptyLabel,e.subtotalLabel,e.totalLabel])if(t!==void 0&&typeof t!="string")throw new Error("矩阵层级标签应为字符串");b(e.row,r.length),b(e.column,l.length)}function b(e,r){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("矩阵轴配置应为对象");if(e.labels!==void 0&&(!Array.isArray(e.labels)||e.labels.length!==r||e.labels.some(l=>typeof l!="string")))throw new Error("矩阵维度标签必须与维度字段一一对应");if(e.sort!==void 0&&(!Array.isArray(e.sort)||e.sort.length>r||e.sort.some(l=>!["source","asc","desc"].includes(l))))throw new Error("矩阵维度排序应为 source、asc 或 desc");if(e.subtotals!==void 0&&(!Array.isArray(e.subtotals)||new Set(e.subtotals).size!==e.subtotals.length||e.subtotals.some(l=>!Number.isInteger(l)||l<1||l>=r)))throw new Error("矩阵小计深度应唯一且位于 1 至末级之前")}}function k(e,r,l){return{fields:e,options:r??{},hierarchy:l,root:{key:$(e,[]),values:[],children:new Map},leaves:0,expanded:0}}function A(e,r){const l=x(r,e.fields);let t=e.root;for(let a=1;a<=l.length;a++){const o=l[a-1];let n=t.children.get(o);if(!n){const s=l.slice(0,a);n={key:$(e.fields,s),values:s,children:new Map,parent:t},t.children.set(o,n),a===l.length?(e.leaves++,e.expanded++):e.options.subtotals?.includes(a)&&e.expanded++}t=n}}function L(e,r){if(e===r)return 0;if(e===null)return-1;if(r===null)return 1;if(typeof e=="number"&&typeof r=="number")return e-r;const l=`${typeof e}:${e}`,t=`${typeof r}:${r}`;return l<t?-1:1}function R(e,r){const l=[...e.children.values()];return r&&r!=="source"&&l.sort((t,a)=>L(t.values[t.values.length-1],a.values[a.values.length-1])*(r==="desc"?-1:1)),l}function y(e,r,l){const{key:t,values:a}=r;return{key:t,kind:l,depth:a.length,fields:e.fields.slice(0,a.length),values:a,labels:a.map(o=>o===null?e.hierarchy.emptyLabel??"(空)":String(o))}}function F(e,r){const l=[];function t(a){for(const o of R(a,e.options.sort?.[a.values.length]))o.children.size?(t(o),e.options.subtotals?.includes(o.values.length)&&l.push(y(e,o,"subtotal"))):l.push(y(e,o,"member"))}return t(e.root),r&&e.leaves&&l.push(y(e,e.root,"total")),l}function v(e,r,l){const t=x(r,e.fields);let a=e.root;for(const c of t){const u=a.children.get(c);if(!u)throw new Error("矩阵维度在预算检查后发生变化");a=u}const o=l?a.totalKeys:a.keys;if(o)return o;const n=[];for(let c=a;c;c=c.parent)n[c.values.length]=c.key;const s=[a.key,...(e.options.subtotals??[]).map(c=>n[c])];return l?(s.push(e.root.key),a.totalKeys=s):a.keys=s,s}function z(e,r,l){if(!(e.kind!=="member"&&r>e.depth))return e.kind==="total"?{key:"total",text:l.totalLabel??"合计",rowSpan:0}:e.kind==="subtotal"&&r===e.depth?{key:e.key,text:l.subtotalLabel??"小计",rowSpan:0}:{key:JSON.stringify(e.values.slice(0,r+1).map(t=>[typeof t,t])),text:e.labels[r],rowSpan:1}}function O(e,r){const l=e.columnFields.length+1,t=e.rowFields.length,a=Array.from({length:l},()=>Array(t+r.length).fill(null));for(let o=0;o<e.columnFields.length;o++){let n;r.forEach((s,c)=>{const u=z(s,o,e.hierarchy);if(!u){n=void 0;return}if(n?.key===u.key){n.cell.colSpan=(n.cell.colSpan??1)+1;return}const i={text:u.text,rowSpan:u.rowSpan||e.columnFields.length-o,editable:!1,derived:!0};a[o][t+c]=i,n={key:u.key,cell:i}})}return e.rowFields.forEach((o,n)=>{a[0][n]={text:e.hierarchy.row?.labels?.[n]??o,rowSpan:l,editable:!1,derived:!0}}),r.forEach((o,n)=>{const s=e.measures[o.measure];a[l-1][t+n]={text:s.label??`${s.field} (${s.op})`,editable:!1,derived:!0}}),{cells:a.map(o=>o.filter(n=>n!==null)),colWidthsMm:[...e.rowFields.map(()=>e.rowWidthMm??40),...r.map(()=>e.columnWidthMm??28)]}}function E(e,r,l,t){const a=+(!!r.totals&&e>0),o=l.expanded+a,n=(t.expanded+a)*r.measures.length+r.rowFields.length;if(o>(r.maxRows??1e3)||t.expanded+a>(r.maxColumns??200))throw new Error("矩阵层级展开数量超出预算(包含小计/总计)");if(o*n>(r.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算");return{rowCount:o,columnCount:n,cells:o*n}}function S(e,r){if(!Array.isArray(e)||e.length>(r.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const l=k(r.rowFields,r.hierarchy.row,r.hierarchy),t=k(r.columnFields,r.hierarchy.column,r.hierarchy);if(e.length*(1+(l.options.subtotals?.length??0)+ +!!r.totals)*(1+(t.options.subtotals?.length??0)+ +!!r.totals)*r.measures.length>(r.maxAggregateUpdates??1e7))throw new Error("矩阵聚合更新超出 maxAggregateUpdates 预算");let o=E(0,r,l,t);for(const n of e){if(!n||typeof n!="object"||Array.isArray(n))throw new Error("矩阵数据行应为对象");A(l,n),A(t,n),o=E(e.length,r,l,t)}return{row:l,column:t,shape:o}}function j(e,r){return S(e,r).shape}function p(e,r,l){const t=new Map;for(const a of e){const o=v(l.row,a,!!r.totals),n=v(l.column,a,!!r.totals);for(const s of o){let c=t.get(s);c||(c=new Map,t.set(s,c));for(const u of n){let i=c.get(u);i||(i=r.measures.map(f=>m.createAggregateAccumulator({...f,field:f.valueField??f.field})),c.set(u,i)),i.forEach(f=>f.add(a))}}}return t}function K(e,r){return e.flatMap((l,t)=>r.measures.map((a,o)=>({...l,field:l.kind==="total"?`total_${o}`:`c${t}_${o}`,measure:o,measureField:a.field,valueField:a.valueField??a.field,operation:a.op})))}function H(e,r){return e.kind==="total"?r.hierarchy.totalLabel??"合计":[...e.labels,...e.kind==="subtotal"?[r.hierarchy.subtotalLabel??"小计"]:[]].join(" / ")}function I(e,r){return[...r.rowFields.map((l,t)=>({field:`r${t}`,header:r.hierarchy.row?.labels?.[t]??l,semanticRole:"dimension"})),...e.map(l=>{const t=r.measures[l.measure];return{field:l.field,header:`${H(l,r)} · ${t.label??`${t.field} (${t.op})`}`,semanticRole:"measure",...t.digits===void 0?{}:{format:{kind:"number",digits:t.digits}}}})]}function T(e,r,l,t){return e.map(a=>{const o={};l.rowFields.forEach((n,s)=>{o[`r${s}`]=a.kind==="total"?s===0?l.hierarchy.totalLabel??"合计":null:a.labels[s]??(s===a.depth?l.hierarchy.subtotalLabel??"小计":null)});for(const n of r)o[n.field]=t.get(a.key)?.get(n.key)?.[n.measure]?.value()??(l.measures[n.measure].op==="count"?0:null);return o})}function _(e,r){const l=S(e,r),t=F(l.row,!!r.totals),a=K(F(l.column,!!r.totals),r),o=p(e,r,l);return{columns:I(a,r),rows:T(t,a,r,o),headerGrid:O(r,a),metadata:{rowFields:[...r.rowFields],rowLabels:[...r.hierarchy.row?.labels??r.rowFields],columnFields:[...r.columnFields],columnLabels:[...r.hierarchy.column?.labels??r.columnFields],rows:t,columns:a}}}function w(e,r){const l=r.map(t=>Object.prototype.hasOwnProperty.call(e,t)?e[t]:null);if(l.some(t=>t!=null&&typeof t!="string"&&typeof t!="boolean"&&!(typeof t=="number"&&Number.isFinite(t))))throw new Error("矩阵维度必须是有限 JSON 标量");return{key:JSON.stringify(l.map(t=>[typeof t,t??null])),label:l.map(t=>t==null?"":String(t)).join(" / ")}}function J(e){for(const r of["maxRows","maxColumns","maxInputRows","maxCells","maxAggregateUpdates"])if(e[r]!==void 0&&(!Number.isSafeInteger(e[r])||e[r]<1))throw new Error("矩阵预算应为正安全整数");for(const r of["columnWidthMm","rowWidthMm"])if(e[r]!==void 0&&(!Number.isFinite(e[r])||e[r]<=0))throw new Error("矩阵列宽应为正数")}function g(e){if(!e||!Array.isArray(e.rowFields)||!Array.isArray(e.columnFields)||!Array.isArray(e.measures))throw new Error("矩阵需要行维度、列维度和度量数组");for(const l of[e.rowFields,e.columnFields])if(l.some(t=>typeof t!="string"||!t.trim())||new Set(l).size!==l.length)throw new Error("矩阵维度字段应非空且唯一");if(J(e),!e.rowFields.length||!e.columnFields.length||e.rowFields.length>16||e.columnFields.length>16)throw new Error("矩阵需要 1–16 个行/列维度");if(!e.measures.length||e.measures.length>32)throw new Error("矩阵需要 1–32 个度量");if(e.measures.map(l=>{if(!l||typeof l!="object")throw new Error("矩阵度量应为对象");if(m.createAggregateAccumulator({...l,field:l.valueField??l.field}),l.label!==void 0&&typeof l.label!="string")throw new Error("矩阵度量标签应为字符串");return l.field}).some(l=>typeof l!="string"||!l.trim()))throw new Error("矩阵度量字段应非空");e.hierarchy!==void 0&&N(e.hierarchy,e.rowFields,e.columnFields)}function C(e,r){if(g(r),r.hierarchy)return j(e,r);if(!Array.isArray(e)||e.length>(r.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const l=new Set,t=new Set;for(const n of e){if(!n||typeof n!="object"||Array.isArray(n))throw new Error("矩阵数据行应为对象");if(l.add(w(n,r.rowFields).key),t.add(w(n,r.columnFields).key),l.size>(r.maxRows??1e3)||t.size>(r.maxColumns??200))throw new Error("矩阵维度数量超出预算");if((l.size+ +!!r.totals)*((t.size+ +!!r.totals)*r.measures.length+1)>(r.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算")}const a=l.size+ +(!!r.totals&&e.length>0),o=(t.size+ +!!r.totals)*r.measures.length+1;return{rowCount:a,columnCount:o,cells:a*o}}function P(e,r){if(r?.hierarchy)return g(r),_(e,r);C(e,r);const l=M(e,{row:n=>w(n,r.rowFields),column:n=>w(n,r.columnFields),measures:r.measures.map(n=>({...n,field:n.valueField??n.field})),totals:r.totals,check:()=>{}}),t=[...l.groups.values()].map(n=>({rowLabel:n.label})),a=[{field:"rowLabel",header:r.rowHeader??r.rowFields.join(" / "),semanticRole:"dimension"}],o={rowLabel:"合计"};return r.measures.forEach((n,s)=>{const c=[...l.columns.entries()].map(([u,i],f)=>({key:u,label:i,field:`c${f}_${s}`}));r.totals&&c.push({key:"",label:"合计",field:`total_${s}`});for(const u of c){const i=u.field===`total_${s}`;a.push({field:u.field,header:`${u.label} · ${n.label??`${n.field} (${n.op})`}`,semanticRole:"measure",...n.digits===void 0?{}:{format:{kind:"number",digits:n.digits}}});let f=0;for(const d of l.groups.values())t[f++][u.field]=(i?d.totals?.[s]:d.cells.get(u.key)?.[s])?.value()??(n.op==="count"?0:null);o[u.field]=(i?l.totals?.[s]:l.columnTotals.get(u.key)?.[s])?.value()??(n.op==="count"?0:null)}}),r.totals&&e.length&&t.push(o),{rows:t,columns:a}}exports.accumulatePivotRows=M;exports.createMatrixTable=P;exports.estimateMatrixTable=C;exports.validateMatrixOptions=g;
@@ -1,19 +1,19 @@
1
- import { c as g } from "./computed-f3pOqWLX.js";
1
+ import { c as m } from "./computed-f3pOqWLX.js";
2
2
  function x(e, r) {
3
- const l = () => r.measures.map((i) => g(i)), t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = r.totals ? l() : void 0, s = (i, c) => i?.forEach((u) => u.add(c));
4
- for (const i of e) {
5
- const c = r.row(i), u = r.column(i);
6
- n.has(u.key) || n.set(u.key, u.label);
7
- let f = t.get(c.key);
8
- f || (f = { label: c.label, cells: /* @__PURE__ */ new Map(), ...r.totals ? { totals: l() } : {} }, t.set(c.key, f)), r.check(t.size, n.size);
9
- let d = f.cells.get(u.key);
10
- if (d || (d = l(), f.cells.set(u.key, d)), s(d, i), !r.totals) continue;
11
- let w = o.get(u.key);
12
- w || (w = l(), o.set(u.key, w)), s(f.totals, i), s(w, i), s(a, i);
3
+ const l = () => r.measures.map((c) => m(c)), t = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = r.totals ? l() : void 0, s = (c, u) => c?.forEach((i) => i.add(u));
4
+ for (const c of e) {
5
+ const u = r.row(c), i = r.column(c);
6
+ a.has(i.key) || a.set(i.key, i.label);
7
+ let f = t.get(u.key);
8
+ f || (f = { label: u.label, cells: /* @__PURE__ */ new Map(), ...r.totals ? { totals: l() } : {} }, t.set(u.key, f)), r.check(t.size, a.size);
9
+ let d = f.cells.get(i.key);
10
+ if (d || (d = l(), f.cells.set(i.key, d)), s(d, c), !r.totals) continue;
11
+ let h = o.get(i.key);
12
+ h || (h = l(), o.set(i.key, h)), s(f.totals, c), s(h, c), s(n, c);
13
13
  }
14
- return { groups: t, columns: n, columnTotals: o, totals: a };
14
+ return { groups: t, columns: a, columnTotals: o, totals: n };
15
15
  }
16
- function h(e, r) {
16
+ function E(e, r) {
17
17
  return JSON.stringify([e.slice(0, r.length), r.map((l) => [l === null ? "null" : typeof l, l])]);
18
18
  }
19
19
  function M(e, r) {
@@ -27,9 +27,9 @@ function M(e, r) {
27
27
  function C(e, r, l) {
28
28
  if (!e || typeof e != "object" || Array.isArray(e)) throw new Error("矩阵层级应为对象");
29
29
  for (const t of [e.emptyLabel, e.subtotalLabel, e.totalLabel]) if (t !== void 0 && typeof t != "string") throw new Error("矩阵层级标签应为字符串");
30
- b(e.row, r.length), b(e.column, l.length);
30
+ g(e.row, r.length), g(e.column, l.length);
31
31
  }
32
- function b(e, r) {
32
+ function g(e, r) {
33
33
  if (e !== void 0) {
34
34
  if (!e || typeof e != "object" || Array.isArray(e)) throw new Error("矩阵轴配置应为对象");
35
35
  if (e.labels !== void 0 && (!Array.isArray(e.labels) || e.labels.length !== r || e.labels.some((l) => typeof l != "string"))) throw new Error("矩阵维度标签必须与维度字段一一对应");
@@ -37,16 +37,20 @@ function b(e, r) {
37
37
  if (e.subtotals !== void 0 && (!Array.isArray(e.subtotals) || new Set(e.subtotals).size !== e.subtotals.length || e.subtotals.some((l) => !Number.isInteger(l) || l < 1 || l >= r))) throw new Error("矩阵小计深度应唯一且位于 1 至末级之前");
38
38
  }
39
39
  }
40
- function k(e, r, l) {
41
- return { fields: e, options: r ?? {}, hierarchy: l, root: { values: [], children: /* @__PURE__ */ new Map() }, leaves: 0, expanded: 0 };
40
+ function b(e, r, l) {
41
+ return { fields: e, options: r ?? {}, hierarchy: l, root: { key: E(e, []), values: [], children: /* @__PURE__ */ new Map() }, leaves: 0, expanded: 0 };
42
42
  }
43
- function F(e, r) {
43
+ function k(e, r) {
44
44
  const l = M(r, e.fields);
45
45
  let t = e.root;
46
- for (let n = 1; n <= l.length; n++) {
47
- const o = l.slice(0, n), a = h(e.fields, o);
48
- let s = t.children.get(a);
49
- s || (s = { values: o, children: /* @__PURE__ */ new Map() }, t.children.set(a, s), n === l.length ? (e.leaves++, e.expanded++) : e.options.subtotals?.includes(n) && e.expanded++), t = s;
46
+ for (let a = 1; a <= l.length; a++) {
47
+ const o = l[a - 1];
48
+ let n = t.children.get(o);
49
+ if (!n) {
50
+ const s = l.slice(0, a);
51
+ n = { key: E(e.fields, s), values: s, children: /* @__PURE__ */ new Map(), parent: t }, t.children.set(o, n), a === l.length ? (e.leaves++, e.expanded++) : e.options.subtotals?.includes(a) && e.expanded++;
52
+ }
53
+ t = n;
50
54
  }
51
55
  }
52
56
  function N(e, r) {
@@ -59,76 +63,88 @@ function N(e, r) {
59
63
  }
60
64
  function L(e, r) {
61
65
  const l = [...e.children.values()];
62
- return r && r !== "source" && l.sort((t, n) => N(t.values[t.values.length - 1], n.values[n.values.length - 1]) * (r === "desc" ? -1 : 1)), l;
66
+ return r && r !== "source" && l.sort((t, a) => N(t.values[t.values.length - 1], a.values[a.values.length - 1]) * (r === "desc" ? -1 : 1)), l;
63
67
  }
64
68
  function y(e, r, l) {
69
+ const { key: t, values: a } = r;
65
70
  return {
66
- key: h(e.fields, r),
71
+ key: t,
67
72
  kind: l,
68
- depth: r.length,
69
- fields: e.fields.slice(0, r.length),
70
- values: r,
71
- labels: r.map((t) => t === null ? e.hierarchy.emptyLabel ?? "(空)" : String(t))
73
+ depth: a.length,
74
+ fields: e.fields.slice(0, a.length),
75
+ values: a,
76
+ labels: a.map((o) => o === null ? e.hierarchy.emptyLabel ?? "(空)" : String(o))
72
77
  };
73
78
  }
74
- function A(e, r) {
79
+ function F(e, r) {
75
80
  const l = [];
76
- function t(n) {
77
- for (const o of L(n, e.options.sort?.[n.values.length]))
78
- o.children.size ? (t(o), e.options.subtotals?.includes(o.values.length) && l.push(y(e, o.values, "subtotal"))) : l.push(y(e, o.values, "member"));
81
+ function t(a) {
82
+ for (const o of L(a, e.options.sort?.[a.values.length]))
83
+ o.children.size ? (t(o), e.options.subtotals?.includes(o.values.length) && l.push(y(e, o, "subtotal"))) : l.push(y(e, o, "member"));
79
84
  }
80
- return t(e.root), r && e.leaves && l.push(y(e, [], "total")), l;
85
+ return t(e.root), r && e.leaves && l.push(y(e, e.root, "total")), l;
81
86
  }
82
- function E(e, r, l) {
83
- const t = M(r, e.fields), n = [h(e.fields, t), ...(e.options.subtotals ?? []).map((o) => h(e.fields, t.slice(0, o)))];
84
- return l && n.push(h(e.fields, [])), n;
87
+ function A(e, r, l) {
88
+ const t = M(r, e.fields);
89
+ let a = e.root;
90
+ for (const c of t) {
91
+ const u = a.children.get(c);
92
+ if (!u) throw new Error("矩阵维度在预算检查后发生变化");
93
+ a = u;
94
+ }
95
+ const o = l ? a.totalKeys : a.keys;
96
+ if (o) return o;
97
+ const n = [];
98
+ for (let c = a; c; c = c.parent) n[c.values.length] = c.key;
99
+ const s = [a.key, ...(e.options.subtotals ?? []).map((c) => n[c])];
100
+ return l ? (s.push(e.root.key), a.totalKeys = s) : a.keys = s, s;
85
101
  }
86
102
  function R(e, r, l) {
87
103
  if (!(e.kind !== "member" && r > e.depth))
88
104
  return e.kind === "total" ? { key: "total", text: l.totalLabel ?? "合计", rowSpan: 0 } : e.kind === "subtotal" && r === e.depth ? { key: e.key, text: l.subtotalLabel ?? "小计", rowSpan: 0 } : { key: JSON.stringify(e.values.slice(0, r + 1).map((t) => [typeof t, t])), text: e.labels[r], rowSpan: 1 };
89
105
  }
90
106
  function z(e, r) {
91
- const l = e.columnFields.length + 1, t = e.rowFields.length, n = Array.from({ length: l }, () => Array(t + r.length).fill(null));
107
+ const l = e.columnFields.length + 1, t = e.rowFields.length, a = Array.from({ length: l }, () => Array(t + r.length).fill(null));
92
108
  for (let o = 0; o < e.columnFields.length; o++) {
93
- let a;
94
- r.forEach((s, i) => {
95
- const c = R(s, o, e.hierarchy);
96
- if (!c) {
97
- a = void 0;
109
+ let n;
110
+ r.forEach((s, c) => {
111
+ const u = R(s, o, e.hierarchy);
112
+ if (!u) {
113
+ n = void 0;
98
114
  return;
99
115
  }
100
- if (a?.key === c.key) {
101
- a.cell.colSpan = (a.cell.colSpan ?? 1) + 1;
116
+ if (n?.key === u.key) {
117
+ n.cell.colSpan = (n.cell.colSpan ?? 1) + 1;
102
118
  return;
103
119
  }
104
- const u = { text: c.text, rowSpan: c.rowSpan || e.columnFields.length - o, editable: !1, derived: !0 };
105
- n[o][t + i] = u, a = { key: c.key, cell: u };
120
+ const i = { text: u.text, rowSpan: u.rowSpan || e.columnFields.length - o, editable: !1, derived: !0 };
121
+ a[o][t + c] = i, n = { key: u.key, cell: i };
106
122
  });
107
123
  }
108
- return e.rowFields.forEach((o, a) => {
109
- n[0][a] = { text: e.hierarchy.row?.labels?.[a] ?? o, rowSpan: l, editable: !1, derived: !0 };
110
- }), r.forEach((o, a) => {
124
+ return e.rowFields.forEach((o, n) => {
125
+ a[0][n] = { text: e.hierarchy.row?.labels?.[n] ?? o, rowSpan: l, editable: !1, derived: !0 };
126
+ }), r.forEach((o, n) => {
111
127
  const s = e.measures[o.measure];
112
- n[l - 1][t + a] = { text: s.label ?? `${s.field} (${s.op})`, editable: !1, derived: !0 };
128
+ a[l - 1][t + n] = { text: s.label ?? `${s.field} (${s.op})`, editable: !1, derived: !0 };
113
129
  }), {
114
- cells: n.map((o) => o.filter((a) => a !== null)),
130
+ cells: a.map((o) => o.filter((n) => n !== null)),
115
131
  colWidthsMm: [...e.rowFields.map(() => e.rowWidthMm ?? 40), ...r.map(() => e.columnWidthMm ?? 28)]
116
132
  };
117
133
  }
118
134
  function v(e, r, l, t) {
119
- const n = +(!!r.totals && e > 0), o = l.expanded + n, a = (t.expanded + n) * r.measures.length + r.rowFields.length;
120
- if (o > (r.maxRows ?? 1e3) || t.expanded + n > (r.maxColumns ?? 200)) throw new Error("矩阵层级展开数量超出预算(包含小计/总计)");
121
- if (o * a > (r.maxCells ?? 2e6)) throw new Error("矩阵输出超出 maxCells 预算");
122
- return { rowCount: o, columnCount: a, cells: o * a };
135
+ const a = +(!!r.totals && e > 0), o = l.expanded + a, n = (t.expanded + a) * r.measures.length + r.rowFields.length;
136
+ if (o > (r.maxRows ?? 1e3) || t.expanded + a > (r.maxColumns ?? 200)) throw new Error("矩阵层级展开数量超出预算(包含小计/总计)");
137
+ if (o * n > (r.maxCells ?? 2e6)) throw new Error("矩阵输出超出 maxCells 预算");
138
+ return { rowCount: o, columnCount: n, cells: o * n };
123
139
  }
124
140
  function $(e, r) {
125
141
  if (!Array.isArray(e) || e.length > (r.maxInputRows ?? 1e5)) throw new Error("矩阵输入超出预算");
126
- const l = k(r.rowFields, r.hierarchy.row, r.hierarchy), t = k(r.columnFields, r.hierarchy.column, r.hierarchy);
142
+ const l = b(r.rowFields, r.hierarchy.row, r.hierarchy), t = b(r.columnFields, r.hierarchy.column, r.hierarchy);
127
143
  if (e.length * (1 + (l.options.subtotals?.length ?? 0) + +!!r.totals) * (1 + (t.options.subtotals?.length ?? 0) + +!!r.totals) * r.measures.length > (r.maxAggregateUpdates ?? 1e7)) throw new Error("矩阵聚合更新超出 maxAggregateUpdates 预算");
128
144
  let o = v(0, r, l, t);
129
- for (const a of e) {
130
- if (!a || typeof a != "object" || Array.isArray(a)) throw new Error("矩阵数据行应为对象");
131
- F(l, a), F(t, a), o = v(e.length, r, l, t);
145
+ for (const n of e) {
146
+ if (!n || typeof n != "object" || Array.isArray(n)) throw new Error("矩阵数据行应为对象");
147
+ k(l, n), k(t, n), o = v(e.length, r, l, t);
132
148
  }
133
149
  return { row: l, column: t, shape: o };
134
150
  }
@@ -137,68 +153,68 @@ function j(e, r) {
137
153
  }
138
154
  function O(e, r, l) {
139
155
  const t = /* @__PURE__ */ new Map();
140
- for (const n of e) {
141
- const o = E(l.row, n, !!r.totals), a = E(l.column, n, !!r.totals);
156
+ for (const a of e) {
157
+ const o = A(l.row, a, !!r.totals), n = A(l.column, a, !!r.totals);
142
158
  for (const s of o) {
143
- let i = t.get(s);
144
- i || (i = /* @__PURE__ */ new Map(), t.set(s, i));
145
- for (const c of a) {
146
- let u = i.get(c);
147
- u || (u = r.measures.map((f) => g({ ...f, field: f.valueField ?? f.field })), i.set(c, u)), u.forEach((f) => f.add(n));
159
+ let c = t.get(s);
160
+ c || (c = /* @__PURE__ */ new Map(), t.set(s, c));
161
+ for (const u of n) {
162
+ let i = c.get(u);
163
+ i || (i = r.measures.map((f) => m({ ...f, field: f.valueField ?? f.field })), c.set(u, i)), i.forEach((f) => f.add(a));
148
164
  }
149
165
  }
150
166
  }
151
167
  return t;
152
168
  }
153
169
  function p(e, r) {
154
- return e.flatMap((l, t) => r.measures.map((n, o) => ({
170
+ return e.flatMap((l, t) => r.measures.map((a, o) => ({
155
171
  ...l,
156
172
  field: l.kind === "total" ? `total_${o}` : `c${t}_${o}`,
157
173
  measure: o,
158
- measureField: n.field,
159
- valueField: n.valueField ?? n.field,
160
- operation: n.op
174
+ measureField: a.field,
175
+ valueField: a.valueField ?? a.field,
176
+ operation: a.op
161
177
  })));
162
178
  }
163
- function H(e, r) {
179
+ function K(e, r) {
164
180
  return e.kind === "total" ? r.hierarchy.totalLabel ?? "合计" : [...e.labels, ...e.kind === "subtotal" ? [r.hierarchy.subtotalLabel ?? "小计"] : []].join(" / ");
165
181
  }
166
- function I(e, r) {
182
+ function H(e, r) {
167
183
  return [
168
184
  ...r.rowFields.map((l, t) => ({ field: `r${t}`, header: r.hierarchy.row?.labels?.[t] ?? l, semanticRole: "dimension" })),
169
185
  ...e.map((l) => {
170
186
  const t = r.measures[l.measure];
171
187
  return {
172
188
  field: l.field,
173
- header: `${H(l, r)} · ${t.label ?? `${t.field} (${t.op})`}`,
189
+ header: `${K(l, r)} · ${t.label ?? `${t.field} (${t.op})`}`,
174
190
  semanticRole: "measure",
175
191
  ...t.digits === void 0 ? {} : { format: { kind: "number", digits: t.digits } }
176
192
  };
177
193
  })
178
194
  ];
179
195
  }
180
- function K(e, r, l, t) {
181
- return e.map((n) => {
196
+ function I(e, r, l, t) {
197
+ return e.map((a) => {
182
198
  const o = {};
183
- l.rowFields.forEach((a, s) => {
184
- o[`r${s}`] = n.kind === "total" ? s === 0 ? l.hierarchy.totalLabel ?? "合计" : null : n.labels[s] ?? (s === n.depth ? l.hierarchy.subtotalLabel ?? "小计" : null);
199
+ l.rowFields.forEach((n, s) => {
200
+ o[`r${s}`] = a.kind === "total" ? s === 0 ? l.hierarchy.totalLabel ?? "合计" : null : a.labels[s] ?? (s === a.depth ? l.hierarchy.subtotalLabel ?? "小计" : null);
185
201
  });
186
- for (const a of r) o[a.field] = t.get(n.key)?.get(a.key)?.[a.measure]?.value() ?? (l.measures[a.measure].op === "count" ? 0 : null);
202
+ for (const n of r) o[n.field] = t.get(a.key)?.get(n.key)?.[n.measure]?.value() ?? (l.measures[n.measure].op === "count" ? 0 : null);
187
203
  return o;
188
204
  });
189
205
  }
190
206
  function _(e, r) {
191
- const l = $(e, r), t = A(l.row, !!r.totals), n = p(A(l.column, !!r.totals), r), o = O(e, r, l);
192
- return { columns: I(n, r), rows: K(t, n, r, o), headerGrid: z(r, n), metadata: {
207
+ const l = $(e, r), t = F(l.row, !!r.totals), a = p(F(l.column, !!r.totals), r), o = O(e, r, l);
208
+ return { columns: H(a, r), rows: I(t, a, r, o), headerGrid: z(r, a), metadata: {
193
209
  rowFields: [...r.rowFields],
194
210
  rowLabels: [...r.hierarchy.row?.labels ?? r.rowFields],
195
211
  columnFields: [...r.columnFields],
196
212
  columnLabels: [...r.hierarchy.column?.labels ?? r.columnFields],
197
213
  rows: t,
198
- columns: n
214
+ columns: a
199
215
  } };
200
216
  }
201
- function m(e, r) {
217
+ function w(e, r) {
202
218
  const l = r.map(
203
219
  (t) => Object.prototype.hasOwnProperty.call(e, t) ? e[t] : null
204
220
  );
@@ -237,7 +253,7 @@ function S(e) {
237
253
  throw new Error("矩阵需要 1–32 个度量");
238
254
  if (e.measures.map((l) => {
239
255
  if (!l || typeof l != "object") throw new Error("矩阵度量应为对象");
240
- if (g({
256
+ if (m({
241
257
  ...l,
242
258
  field: l.valueField ?? l.field
243
259
  }), l.label !== void 0 && typeof l.label != "string")
@@ -252,47 +268,47 @@ function W(e, r) {
252
268
  if (!Array.isArray(e) || e.length > (r.maxInputRows ?? 1e5))
253
269
  throw new Error("矩阵输入超出预算");
254
270
  const l = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
255
- for (const a of e) {
256
- if (!a || typeof a != "object" || Array.isArray(a))
271
+ for (const n of e) {
272
+ if (!n || typeof n != "object" || Array.isArray(n))
257
273
  throw new Error("矩阵数据行应为对象");
258
- if (l.add(m(a, r.rowFields).key), t.add(m(a, r.columnFields).key), l.size > (r.maxRows ?? 1e3) || t.size > (r.maxColumns ?? 200))
274
+ if (l.add(w(n, r.rowFields).key), t.add(w(n, r.columnFields).key), l.size > (r.maxRows ?? 1e3) || t.size > (r.maxColumns ?? 200))
259
275
  throw new Error("矩阵维度数量超出预算");
260
276
  if ((l.size + +!!r.totals) * ((t.size + +!!r.totals) * r.measures.length + 1) > (r.maxCells ?? 2e6))
261
277
  throw new Error("矩阵输出超出 maxCells 预算");
262
278
  }
263
- const n = l.size + +(!!r.totals && e.length > 0), o = (t.size + +!!r.totals) * r.measures.length + 1;
264
- return { rowCount: n, columnCount: o, cells: n * o };
279
+ const a = l.size + +(!!r.totals && e.length > 0), o = (t.size + +!!r.totals) * r.measures.length + 1;
280
+ return { rowCount: a, columnCount: o, cells: a * o };
265
281
  }
266
282
  function T(e, r) {
267
283
  if (r?.hierarchy)
268
284
  return S(r), _(e, r);
269
285
  W(e, r);
270
286
  const l = x(e, {
271
- row: (a) => m(a, r.rowFields),
272
- column: (a) => m(a, r.columnFields),
273
- measures: r.measures.map((a) => ({ ...a, field: a.valueField ?? a.field })),
287
+ row: (n) => w(n, r.rowFields),
288
+ column: (n) => w(n, r.columnFields),
289
+ measures: r.measures.map((n) => ({ ...n, field: n.valueField ?? n.field })),
274
290
  totals: r.totals,
275
291
  check: () => {
276
292
  }
277
293
  // Cardinality/budgets were checked before allocating accumulators.
278
- }), t = [...l.groups.values()].map((a) => ({ rowLabel: a.label })), n = [{ field: "rowLabel", header: r.rowHeader ?? r.rowFields.join(" / "), semanticRole: "dimension" }], o = { rowLabel: "合计" };
279
- return r.measures.forEach((a, s) => {
280
- const i = [...l.columns.entries()].map(([c, u], f) => ({ key: c, label: u, field: `c${f}_${s}` }));
281
- r.totals && i.push({ key: "", label: "合计", field: `total_${s}` });
282
- for (const c of i) {
283
- const u = c.field === `total_${s}`;
284
- n.push({
285
- field: c.field,
286
- header: `${c.label} · ${a.label ?? `${a.field} (${a.op})`}`,
294
+ }), t = [...l.groups.values()].map((n) => ({ rowLabel: n.label })), a = [{ field: "rowLabel", header: r.rowHeader ?? r.rowFields.join(" / "), semanticRole: "dimension" }], o = { rowLabel: "合计" };
295
+ return r.measures.forEach((n, s) => {
296
+ const c = [...l.columns.entries()].map(([u, i], f) => ({ key: u, label: i, field: `c${f}_${s}` }));
297
+ r.totals && c.push({ key: "", label: "合计", field: `total_${s}` });
298
+ for (const u of c) {
299
+ const i = u.field === `total_${s}`;
300
+ a.push({
301
+ field: u.field,
302
+ header: `${u.label} · ${n.label ?? `${n.field} (${n.op})`}`,
287
303
  semanticRole: "measure",
288
- ...a.digits === void 0 ? {} : { format: { kind: "number", digits: a.digits } }
304
+ ...n.digits === void 0 ? {} : { format: { kind: "number", digits: n.digits } }
289
305
  });
290
306
  let f = 0;
291
307
  for (const d of l.groups.values())
292
- t[f++][c.field] = (u ? d.totals?.[s] : d.cells.get(c.key)?.[s])?.value() ?? (a.op === "count" ? 0 : null);
293
- o[c.field] = (u ? l.totals?.[s] : l.columnTotals.get(c.key)?.[s])?.value() ?? (a.op === "count" ? 0 : null);
308
+ t[f++][u.field] = (i ? d.totals?.[s] : d.cells.get(u.key)?.[s])?.value() ?? (n.op === "count" ? 0 : null);
309
+ o[u.field] = (i ? l.totals?.[s] : l.columnTotals.get(u.key)?.[s])?.value() ?? (n.op === "count" ? 0 : null);
294
310
  }
295
- }), r.totals && e.length && t.push(o), { rows: t, columns: n };
311
+ }), r.totals && e.length && t.push(o), { rows: t, columns: a };
296
312
  }
297
313
  export {
298
314
  x as a,