@agile-team/mach-report 2.23.1 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/{ExcelBindingWizard-BrTmdo7f.cjs → ExcelBindingWizard-BV12hGiK.cjs} +1 -1
- package/dist/{ExcelBindingWizard-CcDMLO8Q.js → ExcelBindingWizard-Cy_lPjWV.js} +3 -3
- package/dist/ParamEditor-DenKjvKu.cjs +1 -0
- package/dist/ParamEditor-PyOqHzzw.js +750 -0
- package/dist/{ReportBatchPanel-CJB67WNd.js → ReportBatchPanel-8EFtMrKk.js} +2 -2
- package/dist/{ReportBatchPanel-CHxBtG9R.cjs → ReportBatchPanel-pQ6d0yqJ.cjs} +1 -1
- package/dist/ReportLabelStudio-B_KF3Zc_.cjs +1 -0
- package/dist/{ReportLabelStudio-Tplc1TLJ.js → ReportLabelStudio-HUeo2TsU.js} +68 -68
- package/dist/ReportParamPanel-8xR85nz-.cjs +1 -0
- package/dist/{ReportParamPanel-GI43aGa0.js → ReportParamPanel-DA-YpkvC.js} +328 -298
- package/dist/ReportPreview-CyUXJSVX.cjs +6 -0
- package/dist/ReportPreview-_wTJnsG1.js +7120 -0
- package/dist/{ReportTemplateLibrary-BFQIX0sg.cjs → ReportTemplateLibrary-CjArKxRG.cjs} +1 -1
- package/dist/{ReportTemplateLibrary-KqX4E2sN.js → ReportTemplateLibrary-DH8jl9IF.js} +28 -28
- package/dist/RuleEditor-Bmj98oC4.cjs +1 -0
- package/dist/{RuleEditor-OPX1awrH.js → RuleEditor-GDydlEHz.js} +846 -834
- package/dist/{TemplateOutlinePanel-CVYKVLv_.cjs → TemplateOutlinePanel-B554_qk1.cjs} +1 -1
- package/dist/{TemplateOutlinePanel-DQS-eOs6.js → TemplateOutlinePanel-DjPqzU9h.js} +10 -10
- package/dist/{TemplateReusePanel-CY6O93Zk.cjs → TemplateReusePanel-D0628OYc.cjs} +1 -1
- package/dist/{TemplateReusePanel-DKXiFTyB.js → TemplateReusePanel-DtYbCN7U.js} +2 -2
- package/dist/TemplateReviewPanel-CSwvCz3f.cjs +1 -0
- package/dist/TemplateReviewPanel-D_FR4ISq.js +602 -0
- package/dist/artifact-integrity.json +94 -94
- package/dist/assets-B4AJIOTB.cjs +1 -0
- package/dist/assets-D0FbszhB.js +137 -0
- package/dist/{auto-BB99S802.js → auto-BksreoKc.js} +5 -5
- package/dist/auto-C3mGqzJ8.cjs +1 -0
- package/dist/capabilities-CTwlcl8q.cjs +1 -0
- package/dist/capabilities-lqDEZSq5.js +121 -0
- package/dist/data-bar-2NLRzOCQ.cjs +1 -0
- package/dist/{data-bar-IkI6VvMQ.js → data-bar-BnGtnJ82.js} +1 -1
- package/dist/designer-BNf7NWd6.js +7589 -0
- package/dist/designer-DWnZZ_ej.cjs +2 -0
- package/dist/designer.cjs +1 -1
- package/dist/designer.d.cts +137 -4
- package/dist/designer.d.ts +137 -4
- package/dist/designer.js +5 -5
- package/dist/diagnostic-collector-1sqd7DQP.js +355 -0
- package/dist/diagnostic-collector-D3rlvxm3.cjs +1 -0
- package/dist/{dom-JWrchIre.js → dom-C90cTM6Y.js} +4 -4
- package/dist/dom-CxOkm_Sy.cjs +1 -0
- package/dist/{encoding-7lquyj0w.cjs → encoding-CkziAnZI.cjs} +1 -1
- package/dist/{encoding-CEd-dq9A.js → encoding-DSc9zv2F.js} +2 -2
- package/dist/{font-loader-D8pI87fL.cjs → font-loader-D-znWNWS.cjs} +1 -1
- package/dist/{font-loader-CNWXomuV.js → font-loader-i7lZbqH_.js} +1 -1
- package/dist/{grid-strokes-EoY66L2f.js → grid-strokes-BPiV1WHe.js} +1 -1
- package/dist/grid-strokes-DYf-6DMl.cjs +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +46 -7
- package/dist/index.d.ts +46 -7
- package/dist/index.js +69 -68
- package/dist/{json-snapshot-BRnzKudk.js → json-snapshot-BJWZNryO.js} +919 -791
- package/dist/json-snapshot-C7QZrRBf.cjs +2 -0
- package/dist/{pdf-CJToa81Z.js → pdf-0_5XiTCx.js} +2499 -2492
- package/dist/{pdf-DpMkW72B.cjs → pdf-DWuq6uxx.cjs} +31 -31
- package/dist/pdf.cjs +1 -1
- package/dist/pdf.d.cts +18 -0
- package/dist/pdf.d.ts +18 -0
- package/dist/pdf.js +2 -2
- package/dist/{plugin-_BkUVc2z.js → plugin-B1ydqEmS.js} +1 -1
- package/dist/{plugin-BWTp-X7b.cjs → plugin-BQBz2vLG.cjs} +1 -1
- package/dist/prefill-2p9wrpn9.cjs +1 -0
- package/dist/{prefill-CWGdnqQd.js → prefill-Cuzh1wxf.js} +13 -13
- package/dist/prepared-CVbgO9KR.js +128 -0
- package/dist/prepared-DAwe8Il2.cjs +1 -0
- package/dist/protocol-BOri9qJL.js +105 -0
- package/dist/protocol-DD5dHSz-.cjs +1 -0
- package/dist/record-bindings-CAyM5tGg.cjs +1 -0
- package/dist/{record-bindings-DatJZv_e.js → record-bindings-fhav-NLG.js} +1 -1
- package/dist/{region-binding-workflow-DjrXuR1q.js → region-binding-workflow-Cm4mqhih.js} +2 -2
- package/dist/{region-binding-workflow-l7NGfagJ.cjs → region-binding-workflow-DWCUgjZl.cjs} +1 -1
- package/dist/report-encoding-worker.cjs +1 -1
- package/dist/report-encoding-worker.js +1 -1
- package/dist/rich-text-layout-X9YOz1JD.cjs +3 -0
- package/dist/{rich-text-layout-Ciwa6D2o.js → rich-text-layout-YJHtCWQI.js} +1 -1
- package/dist/runtime-BpSAgOw1.js +201 -0
- package/dist/runtime-Cd2UTnwe.cjs +1 -0
- package/dist/sbom.cdx.json +1 -1
- package/dist/server/node.d.cts +55 -7
- package/dist/server/node.d.ts +55 -7
- package/dist/server-node.cjs +5 -5
- package/dist/server-node.js +2721 -2430
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +47 -12
- package/dist/server.d.ts +47 -12
- package/dist/server.js +8 -8
- package/dist/style.css +1 -1
- package/dist/{template-catalog-DtrtT1FY.cjs → template-catalog--yBX169M.cjs} +1 -1
- package/dist/{template-catalog-CRuZL3pi.js → template-catalog-Bu7s7ReF.js} +3 -3
- package/dist/template-fragments-5EzVn7bm.cjs +1 -0
- package/dist/{template-fragments-CPpGpQoz.js → template-fragments-Di2vDFnx.js} +2 -2
- package/dist/{template-registry-O0hNIOfB.js → template-registry-BCBF2b8j.js} +10 -10
- package/dist/template-registry-Bnh5aEYf.cjs +1 -0
- package/dist/textwrap-BPFxhpOw.cjs +4 -0
- package/dist/{textwrap-D4ZksyMK.js → textwrap-CmVkhMhx.js} +1 -1
- package/dist/vue/async.d.cts +97 -18
- package/dist/vue/async.d.ts +97 -18
- package/dist/vue/index.d.cts +127 -28
- package/dist/vue/index.d.ts +127 -28
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +192 -162
- package/dist/{workbook-session-C9ZmCBwY.js → workbook-session-B6P_-5a4.js} +2 -2
- package/dist/{workbook-session-C6-SrnCT.cjs → workbook-session-BnPK3T58.cjs} +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +55 -7
- package/dist/worker.d.ts +55 -7
- package/dist/worker.js +4 -4
- package/dist/xlsx.cjs +4 -4
- package/dist/xlsx.d.cts +18 -1
- package/dist/xlsx.d.ts +18 -1
- package/dist/xlsx.js +279 -272
- package/package.json +1 -1
- package/dist/ParamEditor-BGjovFUe.js +0 -737
- package/dist/ParamEditor-CeNp4_zQ.cjs +0 -1
- package/dist/ReportLabelStudio-g8PkqJWn.cjs +0 -1
- package/dist/ReportParamPanel-C7fZTllk.cjs +0 -1
- package/dist/ReportPreview-BoGBGyRr.cjs +0 -6
- package/dist/ReportPreview-QLONCyci.js +0 -6257
- package/dist/RuleEditor-BZUP9yvL.cjs +0 -1
- package/dist/TemplateReviewPanel-DbeNC8Ms.cjs +0 -1
- package/dist/TemplateReviewPanel-Dijwm9YE.js +0 -593
- package/dist/assets-D2gHc4Mz.cjs +0 -1
- package/dist/assets-T_gDeFaz.js +0 -132
- package/dist/auto-BrPWo7Xm.cjs +0 -1
- package/dist/capabilities-DiBj4Qgl.cjs +0 -1
- package/dist/capabilities-pg7j7VLT.js +0 -106
- package/dist/data-bar-CeZuFmYl.cjs +0 -1
- package/dist/designer-BZoVWTgl.js +0 -7172
- package/dist/designer-zS2uKJmY.cjs +0 -2
- package/dist/dom-ChE5D-L-.cjs +0 -1
- package/dist/grid-strokes-Be24LGuV.cjs +0 -1
- package/dist/json-snapshot-DNiIbpOr.cjs +0 -2
- package/dist/prefill-PaAy6wLk.cjs +0 -1
- package/dist/prepared-CJy_qk7d.js +0 -94
- package/dist/prepared-D0yCSxSO.cjs +0 -1
- package/dist/progress-ByiOxUD3.js +0 -250
- package/dist/progress-WomPRP3B.cjs +0 -1
- package/dist/protocol-BG16rz6D.js +0 -90
- package/dist/protocol-wzhl1Fim.cjs +0 -1
- package/dist/record-bindings-MBxbeBsi.cjs +0 -1
- package/dist/rich-text-layout-DK7A_a5r.cjs +0 -3
- package/dist/runtime-DYMOS_gz.cjs +0 -1
- package/dist/runtime-PiCax9zQ.js +0 -171
- package/dist/template-fragments-GVjpew_q.cjs +0 -1
- package/dist/template-registry-DI59PXVK.cjs +0 -1
- package/dist/textwrap-DEHqAjKZ.cjs +0 -4
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const E=require("./diagnostic-collector-D3rlvxm3.cjs"),A=require("./textwrap-BPFxhpOw.cjs"),k=require("./computed-DK6BruFz.cjs"),S=require("./record-bindings-CAyM5tGg.cjs"),_e=require("./matrix-B8QWbsGM.cjs"),W=require("./template-serialization-CqQY4zDg.cjs"),H=require("./template-registry-Bnh5aEYf.cjs"),Kt=require("./report-params-VTg8MoCp.cjs"),Ke=require("./param-validation-C-8sRJLq.cjs"),ze=require("./number-format-CZ2T_5kF.cjs"),Me=require("./dataset-IrlXbUvh.cjs"),jt=4096,je=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]),i=t.get(a);if(i!==void 0)return t.delete(a),t.set(a,i),i;const s=e.measureMm(n,o);if(Number.isFinite(s)&&a.length<=je){for(;t.size>=jt||r+a.length>je;){const c=t.keys().next().value;r-=c.length,t.delete(c)}t.set(a,s),r+=a.length}return s}}}function Bt(e,t){return{member:"body",subtotal:"subtotal",total:"grand-total"}[e?.rows.get(t)?.kind??"member"]}function Ht(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=_e.createMatrixTable(t,Ht(e)),n=r.columns.map(s=>({...s,widthMm:s.semanticRole==="dimension"?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:s.semanticRole==="dimension"?"center":"right"})),o={...e,columns:n,headerGrid:r.headerGrid,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};e.layout==="wide"&&(o.widthMm=n.reduce((s,c)=>s+c.widthMm,0));const a=r.metadata,i=a?{rows:new WeakMap(r.rows.map((s,c)=>[s,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,...i?{matrix:i}:{}}}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=E.resolveGridLayout({...e.headerGrid,colWidthsMm:o},o.reduce((c,l)=>c+l,0),n.length),i=new WeakMap;for(const{cell:c,ci:l,ri:u,widthMm:f}of a.cells){const d={...S.resolveListHeaderStyle(e,e.columns[l]),...c.style},m=E.resolveFontSize(d).fontSizePt,b=(A.wrapText(c.text??"",Math.max(1,f-r*2),{fontSizePt:m,fontFamily:d.fontFamily,bold:d.bold,italic:d.italic,letterSpacingPt:d.letterSpacing},t).length*m*(d.lineHeight??E.LINE_HEIGHT)*25.4/72+r*2)/(c.rowSpan??1);for(let w=u;w<u+(c.rowSpan??1);w++)n[w]=Math.max(n[w]??0,b);i.set(c,d)}const s=e.headerGrid.cells.map(c=>c.map(l=>l?{...l,style:i.get(l)}:null));return{...e.headerGrid,cells:s,rowHeightsMm:n}}function Wt(e,t,r){const n=new Set,o=e.cells.map((a,i)=>{const s=[];let c=0;for(const l of a){for(;n.has(`${i}:${c}`);)c++;const u=l?.colSpan??1,f=l?.rowSpan??1;let d=0;for(let m=c;m<c+u;m++){t.has(m)&&d++;for(let g=i+1;g<i+f;g++)n.add(`${g}:${m}`)}d&&s.push(l?{...l,colSpan:d}:null),c+=u}return s});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:Wt(e.headerGrid,t,r.map(n=>n.widthMm))}:{}}}function*_t(e){const{page:t}=e;H.validateReportPageFlow(t.components,t.flow);let r=0,n=0;for(const o of H.reportFlowGroups(t.components,t.flow)){e.active();const a=o.band,i=o.components.some(u=>u.kind==="list"&&u.cardinality!=="record"),s=i?0:o.components.reduce((u,f)=>Math.max(u,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(!i&&s>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);!i&&c+s>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let l=c+s;for(const u of o.components){const f=c+u.topMm-a.topMm;u.kind==="list"?(yield*e.list(u,f,d=>{l=i?d:Math.max(l,d)}),e.active()):e.append({...u,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,i)=>{i!==r&&(e.clear(),t=0,r=i);const s=JSON.stringify([n,o,a.fontSizePt,a.fontFamily,a.bold,a.italic,a.letterSpacingPt]),c=e.get(s);if(c)return e.delete(s),e.set(s,c),c.lines.slice();const l=A.wrapText(n,o,a,i),u=s.length+l.reduce((f,d)=>f+d.length,0);if(u<=De){for(;e.size>=Jt||t+u>De;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(s,{lines:l.slice(),units:u}),t+=u}return l}}const qe=1e4,Be=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,i)=>a+(i?.children?.reduce((s,c)=>s+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,i=r.maxPages??qe,s=Ut(e);let c=0,l=0;for(const[u,f]of o.entries()){if(xe(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new S.ReportBindingError(`$.datasets.${n.dataset}[${u}]`,"标签记录应为对象",u);const d={rowIndex:u,dataset:n.dataset},m=Xe(n,f,d);if(m!==void 0){const b=JSON.stringify([typeof m,m]);if(a.has(b))throw new S.ReportBindingError(`$.datasets.${n.dataset}[${u}].${n.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",u,n.rowKey);a.add(b)}const g=Ue(n,f,d);if(c+=g*e.pages.length,l+=g*s,c>i)throw new S.PaginatePageLimitError(i,c);if(l>Be)throw new S.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Be},请分批生成`,u)}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=E.resolveFontSize(n).fontSizePt,a=e.text??e.lines?.join(`
|
|
2
|
+
`)??"";if(a.length>16384)throw new S.ReportBindingError(r,"标签文本超过 16384 字符预算,请缩小字段内容",t.rowIndex);const i=t.wrapText(a,e.widthMm,{fontSizePt:o,bold:n.bold,italic:n.italic,fontFamily:n.fontFamily,letterSpacingPt:n.letterSpacing},t.options.measurer??A.heuristicMeasurer),s=i.length*o*E.resolveLineHeight(n)*25.4/72;if(s>e.heightMm+.05)throw new S.ReportBindingError(r,`标签文字需要约 ${s.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`,t.rowIndex,e.binding?.field);return{...e,lines:i}}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,i)=>a.map((s,c)=>s?.children?.length?{...s,children:s.children.flatMap((l,u)=>{const f=Ye(l,t,`${r}.grid.cells.${i}.${c}.children.${u}`);return f?[f]:[]})}:s))}),Qt(o===n.grid?n:{...n,grid:o},t,r)}function Zt(e,t,r,n,o,a){return{...e,components:e.components.flatMap((i,s)=>{const c=Ye(i,r,`$.pages.${t}.components.${s}`);return c?[{...c,meta:{...c.meta,labelSource:{pageIndex:t,componentIndex:s}}}]:[]}),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(H.validateTemplateRepeat(e,n),n.length)throw new S.ReportBindingError(n[0].path,n[0].message);if(!e.repeat){for(const[s,c]of e.pages.entries())yield{page:c,pageIndex:s};return}const o=e.repeat,a=Xt(e,t,r),i=qt();for(const[s,c]of a.entries()){const l={row:c,rowIndex:s,dataset:o.dataset,options:r,wrapText:i},u=Ue(o,c,l),f=Xe(o,c,l);for(let d=0;d<u;d++)for(const[m,g]of e.pages.entries())xe(r.signal),yield{page:Zt(g,m,l,d,u,f),pageIndex:m}}}function tr(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 ee(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 Y(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=E.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:n,fontFamily:t.fontFamily??E.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:n*(t.lineHeight??E.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function rr(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??E.DEFAULT_FONT_PT,a=e.paddingMm??1,i=e.columns.map(y=>y.align??y.style?.align??e.align??"left"),s=e.columns.map((y,h)=>({...E.mergeComponentStyles({fontSize:o,verticalAlign:"middle"},y.style),align:i[h]==="auto"?"left":i[h]})),c=s.map((y,h)=>i[h]==="auto"?{left:y,center:{...y,align:"center"},right:{...y,align:"right"}}:void 0),l=e.columns.map((y,h)=>y.rules?.map(x=>{const T=c[h];if(T)return{left:E.mergeComponentStyles(T.left,x.style),center:E.mergeComponentStyles(T.center,x.style),right:E.mergeComponentStyles(T.right,x.style)};const I=E.mergeComponentStyles(s[h],x.style);return{left:I,center:I,right:I}})),u=e.columns.map(y=>S.resolveListHeaderStyle(e,y)),f=e.columns.map(y=>y.header);let d=e.rowHeightMm??0;for(let y=0;y<f.length;y++){const h=u[y],x=E.resolveFontSize(h).fontSizePt,T=A.wrapText(f[y],e.columns[y].widthMm-a*2,{fontSizePt:x,fontFamily:h.fontFamily??E.DEFAULT_FONT_FAMILY,italic:h.italic,bold:h.bold,letterSpacingPt:h.letterSpacing},t),I=x*(h.lineHeight??E.LINE_HEIGHT)*25.4/72;d=Math.max(d,Math.max(T.length,1)*I+a*2)}const m=f.map((y,h)=>({text:y,style:u[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(y=>y.widthMm),w=nr(Vt(e,t),b,{cells:[m],colWidthsMm:b,rowHeightsMm:[d],paddingMm:a});return{fontSizePt:o,paddingMm:a,visuals:W.createColumnVisualResolvers(e.columns,r,n),visibility:e.columns.map(y=>y.visibleWhen?k.compileReportPredicate(y.visibleWhen):void 0),ruleReaders:e.columns.map(y=>y.rules?.map(h=>k.compileReportPredicate(h.when))),cellStyles:s,autoStyles:c,ruleStyles:l,textMetrics:new WeakMap,numberFormats:e.columns.map(y=>S.toExcelNumberFormat(y.format)),derivedFields:new Set(e.computed?.map(y=>y.field)),borderStyle:g,headerHeightMm:w.rowHeightsMm.reduce((y,h)=>y+h,0),headerGrid:w,colWidthsMm:b,columns:e.columns}}function nr(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 or(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 Q(e,t,r){const n=e.columns,o=e.tree?.rows.get(t);let a=e.rowHeightFloorMm;const i=new Array(n.length);for(let s=0;s<n.length;s++){const c=n[s],l=e.visibility[s]?.(t)!==!1,u=l?t[c.field]:null,f=e.autoStyles[s]?S.resolveListAutoAlignment(u,c.format,c.semanticRole):"left";let d=e.autoStyles[s]?.[f]??e.cellStyles[s];if(c.rules){for(let x=0;x<c.rules.length;x++)if(e.ruleReaders[s][x](t)){d=e.ruleStyles[s][x][f];break}}const m=c.format?S.formatValue(u,c.format):S.listCellText(u),g=ar(e,c,o);d=ir(e,c,d,o);const b=Qe(e,d),w=A.wrapText(m,Math.max(1,c.widthMm-e.paddingMm*2-g),b.measureOptions,r);a=Math.max(a,w.length*b.lineMm+e.paddingMm*2);const y=rr(u),h={text:m,style:d};u!=null&&e.visuals[s]?.apply(h,t),y!==void 0&&(h.value=y),or(h,c,e.numberFormats[s]),sr(h,c,e,o,g),e.derivedFields.has(c.field)&&(h.derived=!0,h.editable=!1),l||(h.editable=!1),i[s]=h}return{grid:{cells:[i],colWidthsMm:e.colWidthsMm,rowHeightsMm:[a],paddingMm:e.paddingMm},heightMm:a,...e.matrix?{meta:{matrix:{row:e.matrix.rows.get(t)}}}:{}}}function ar(e,t,r){return!r||t.field!==e.tree.list.tree.labelField?0:S.listTreeIndent(e.tree.list,t,r,e.paddingMm)}function ir(e,t,r,n){return!n||t.field!==e.tree.list.tree.labelField||r.align==="left"?r:{...r,align:"left"}}function sr(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 i=Ze(a[n.field]),s=o.get(i);s?s.push(a):o.set(i,[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(i=>i.field===a)).map(a=>({field:a,op:"sum"})),...n];return new Map(o.map(a=>{const i=e.find(c=>c.field===a.field)?.format??{kind:"number",thousands:!0},s=k.aggregateRows(t,{...a,field:a.valueField??a.field});return[a.field,{text:S.formatValue(s,i),...s===null?{}:{value:s},...typeof s=="number"?{numberFormat:S.toExcelNumberFormat(i)}:{}}]}))}function rt(e,t){const r=e.findIndex(n=>t.includes(n.field));return r<0?1:r}function X(e,t,r,n,o,a){const i=[],s=Math.max(0,Math.min(a,e.columns.length)),c=E.mergeComponentStyles({fontSize:e.fontSizePt},o);s&&i.push({text:r,colSpan:s,style:{bold:!0,...c}});for(let d=s;d<e.columns.length;d++){const m=e.columns[d],g=n.get(m.field),b=e.autoStyles[d]?.[S.resolveListAutoAlignment(g?.value,m.format)]??e.cellStyles[d];i.push({...g,text:g?.text??"",style:E.mergeComponentStyles(b,o)})}const l={text:r,colSpan:e.columns.length,style:{bold:!0,...c}},u=s?[i]:[[l],i],f=u.map(d=>cr(e,d,t));return{grid:{cells:u,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((d,m)=>d+m,0)}}function cr(e,t,r){let n=e.rowHeightFloorMm,o=0;for(const a of t){let i=0;const s=o+(a.colSpan??1);for(;o<s;o++)i+=e.colWidthsMm[o]??0;const c=Qe(e,a.style),l=A.wrapText(a.text??"",i-e.paddingMm*2,c.measureOptions,r);n=Math.max(n,l.length*c.lineMm+e.paddingMm*2)}return n}function lr(e,t,r){const{templatePage:n,current:o,warnings:a,nextId:i,pushCurrent:s}=r,c=()=>ee(n,o),l=Math.max(o.marginTopMm,Y(n)),u=n.layout==="wide"?Y(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}},d=new Map,m=new Map,g={kind:"rect",leftMm:e.leftMm,topMm:0,widthMm:e.widthMm,heightMm:t.headerHeightMm,grid:t.headerGrid,nid:i("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 w=Math.max(r.startTop??e.topMm,l);e.header!==!1&&(b(w),w+=t.headerHeightMm+r.mmPerRow);function y(){const p=Math.max(r.flow||n.layout==="wide"?0:e.topMm,u);return(e.header!==!1&&e.headerEveryPage!==!1?p+t.headerHeightMm:u)+[...m.values()].reduce((R,$)=>R+$.heightMm,0)}function h(){const p=n.layout==="wide"?0:o.marginBottomMm;return Math.min(n.heightMm-p,ee(n,o))-y()}function x(p){if(w+p<=c())return;s(),o.components=[],o.heightMm=n.heightMm,n.layout==="wide"&&(o.marginTopMm=0,o.marginBottomMm=0);const C=Math.max(r.flow||n.layout==="wide"?0:e.topMm,u);e.header!==!1&&e.headerEveryPage!==!1?(b(C),w=C+t.headerHeightMm):w=u;for(const R of m.values())I(R,"listgr","group-header")}function T(p,C,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,C,R,$)}function I(p,C,R,$){const v=p.table?.id??f.id,F=R==="header"?-1:d.get(v)??0;R!=="header"&&d.set(v,F+p.grid.cells.length),o.components.push({kind:"rect",leftMm:e.leftMm,topMm:w,widthMm:e.widthMm,heightMm:p.heightMm,grid:p.grid,nid:i(C),table:{...f,...p.table,role:R,rowIndex:F,...$?{source:$}:{}},style:t.borderStyle,...e.meta||p.meta?{meta:{...e.meta,...p.meta}}:{}}),w+=p.heightMm}function L(p){p<=h()&&x(p)}return{keepTogether:L,placeGridRow:T,setGroupHeader:(p,C)=>{C?m.set(p,C):m.delete(p)},bottom:()=>w}}function dr(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=dr(e,o),i=JSON.stringify(a.rowKey);if(n.has(i))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);n.add(i),r.set(o,a)}return r}function ur(e,t,r,n,o){if(!e.grandTotal)return;const a=typeof e.grandTotal=="object"?e.grandTotal:void 0,i=ae(e)[0],s=a?.fields??i?.subtotal??[],c=a?.aggregates??i?.aggregates??[];if(s.length===0&&c.length===0){n.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const l=X(r,n.measurer,a?.label??"合计",tt(e.columns,t,s,c),a?.style??{},rt(e.columns,[...s,...c.map(u=>u.field)]));o.placeGridRow(l,"listgt","grand-total")}function B(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 Ce(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 fr(e,t,r){const n=e.detail;if(!n)return;const o=new Set;for(const l of t){const u=ge(l[n.parentKey]);if(o.has(u))throw new Error("主从明细的主表关联键重复");o.add(u)}const a=r.datasets[n.dataset]??[],i=new Map,s=[];for(const l of a){const u=l[n.foreignKey];if(!nt(u)&&n.unmatched==="ignore")continue;const f=ge(u);if(!o.has(f)){if(n.unmatched!=="ignore")throw new Error(`明细数据集 ${n.dataset} 存在未关联的业务键`);continue}const d=i.get(f);d?d.push(l):i.set(f,[l]),s.push(l)}const c=Ce({...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,s,r.signal),rowHeightFloorMm:c.rowHeightMm??0},rows:i,sources:oe(c,s)}}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*mr(e,t,r,n,o){if(!r)return;const a=r.rows.get(ge(t[e.detail.parentKey]))??[];if(!a.length)return;const i={id:`${n.tableId}:detail`,columnKeys:r.list.columns.map(s=>s.field),title:e.detail.label};e.detail.label&&o.placeGridRow({...X(r.inter,n.measurer,e.detail.label,new Map,{},r.list.columns.length),table:i},"listdl","group-header"),e.detail.header!==!1&&o.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:i},"listdh","header"),yield*n.takePages();for(const s of a)B(n.signal),o.placeGridRow({...Q(r.inter,s,n.measurer),table:i},"listdr","body",r.sources.get(s)),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("树形布局需要可见的标签列");W.validateTreeComputed(e.tree,e.computed)}function gr(e,t,r){ot(e);const n=W.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)),i=new Map,s=new WeakMap;for(const c of n.entries)i.set(c.row,a.get(c.original)),s.set(c.row,c);return{list:o,rows:n.rows,sources:i,treeRows:s,totalRows:n.leaves}}function hr(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=hr(e,t);if(o)return r.prepared.set(e,o),o;if(e.tree){const c=gr(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 i=a===t?void 0:new Map(a.map((c,l)=>[c,t[l]]));e.rowVisibleWhen&&(a=a.filter(k.compileReportPredicate(e.rowVisibleWhen)));const s=Gt(e,a);if(!e.matrix){const c=oe(e,i?a.map(l=>i.get(l)):a);s.sources=i?new Map(a.map(l=>[l,c.get(i.get(l))])):c}return r.prepared.set(e,s),s}function pr(e,t,r,n){if(!n.flow)return;const{current:o,templatePage:a}=n,i=Math.max(o.marginTopMm,Y(a)),s=Math.max(n.startTop??e.topMm,i),c=(e.header===!1?0:t.headerHeightMm)+(r[0]?Q(t,r[0],n.measurer).heightMm:0);s+c<=ee(a,o)+.001||s<=i+.001||(n.pushCurrent(),o.components=[],o.heightMm=a.heightMm,a.layout==="wide"&&(o.marginTopMm=0,o.marginBottomMm=0),n.startTop=Math.max(o.marginTopMm,Y(a)))}function*wr(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),i=Ce(e),s=ae(i),c={...Re(i,r.measurer,o,r.signal),rowHeightFloorMm:i.rowHeightMm??0,matrix:n.matrix,...n.treeRows?{tree:{list:i,rows:n.treeRows}}:{}};pr(i,c,o,r);const l=lr(i,c,r),u=fr(i,o,r);let f;for(const d of et(o,s)){if(B(r.signal),d.kind==="row")l.placeGridRow(f??Q(c,d.row,r.measurer),"listr",Bt(n.matrix,d.row),a.get(d.row)),f=void 0,yield*r.takePages(),yield*mr(i,d.row,u,r,l);else if(d.kind==="groupHeader"){const m=X(c,r.measurer,d.label,new Map,d.group.headerStyle??{},i.columns.length);f??=Q(c,d.firstRow,r.measurer);const g=s.slice(d.depth+1).reduce((b,w)=>b+X(c,r.measurer,(w.headerTemplate??"{value}").replace(/\{value\}/g,S.listCellText(d.firstRow[w.field])),new Map,w.headerStyle??{},i.columns.length).heightMm,0);d.group.keepWithNext!==!1&&l.keepTogether(m.heightMm+g+f.heightMm),l.placeGridRow(m,"listg","group-header"),d.group.repeatHeader&&l.setGroupHeader(d.depth,m)}else if(d.kind==="subtotal"){const m=d.group.subtotal??[],g=d.group.aggregates??[],b=X(c,r.measurer,d.label,tt(i.columns,d.rows,m,g),d.group.subtotalStyle??{},rt(i.columns,[...m,...g.map(w=>w.field)]));l.placeGridRow(b,"listst","subtotal")}else l.setGroupHeader(d.depth);yield*r.takePages()}ur(i,n.totalRows??o,c,r,l),r.finished?.(l.bottom()),yield*r.takePages()}function ie(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 se(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=>se(o,t))}:{}}:null))}}:{}}}function yr(e){let t=!1;for(const r of e.pages)for(const n of r.components)ie(n)&&se(n,o=>(o.includes("{totalPages}")&&(t=!0),o));return t}function br(e,t,r,n,o,a){const i={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}:{}},s=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)i.components.push(se(c,s));if(e.layout==="wide"){const c=i.components.reduce((l,u)=>Math.max(l,u.topMm+u.heightMm),0);i.marginBottomMm=o?e.marginBottomMm??0:0,i.pageHeightMm=Math.max(1,c+i.marginBottomMm)}return i}function Ee(e){return e.cells.reduce((t,r)=>t+r.reduce((n,o)=>n+(o?1+(o.children?.reduce((a,i)=>a+it(i),0)??0):0),0),0)}function it(e){return e.grid?Ee(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 vr(e,t){const r=at(e,t.datasets[e.dataset]??[],t),n=Ce(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,i)=>a+Q(o,i,t.measurer).heightMm,0)}function*Mr(e){const{templatePage:t,current:r}=e,n=new Map(t.components.map((a,i)=>[a,i])),o=(a,i,s)=>{const c=e.datasets[a.dataset];return Array.isArray(c)||e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id??""} 输出为空`),wr(a,Array.isArray(c)?c:[],{...e,tableId:`${e.tableId}:${n.get(a)}`,startTop:i,finished:s,flow:!!t.flow})};if(t.flow){yield*_t({page:t,active:()=>B(e.signal),top:()=>Math.max(r.marginTopMm,Y(t)),bottom:()=>ee(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=>vr(a,e),list:o});return}for(const a of t.components)ie(a)||(a.kind==="list"?yield*o(a):r.components.push(...e.resolveChart(a)))}function*Z(e,t,r,n,o,a=new WeakMap,i){let s=0,c=0,l=0;const u=Dt(r.measurer??A.heuristicMeasurer),f=S.createChartResolver(t,r.signal,r.maxChartComponents),d=m=>`${m}_${(++s).toString(36)}`;for(const{pageIndex:m,page:g}of er(e,t,r)){B(r.signal);const b=tr(g),w=g.components.filter(ie);let y=[];const h=(T=!1)=>{if(B(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,...w].reduce((I,L)=>I+it(L),0),l>r.maxCells))throw new S.PaginateCellLimitError(r.maxCells,l);y.push(br(g,b,w,++c,T,o))},x=()=>{const T=y;return y=[],T};yield*Mr({templatePage:g,current:b,warnings:n,nextId:d,pushCurrent:h,takePages:x,datasets:t,resolveChart:f,signal:r.signal,formula:r.formula,prepared:a,measurer:u,mmPerRow:r.mmPerRow??0,tableId:`table:${m}`}),h(!0),yield*x()}i&&(i.chartComponents=f.used())}function Sr(e,t,r={}){ce(r);let n=0;for(const o of Z(e,t,{...r,onWarning:void 0},[]))n++;return n}function*xr(e,t,r={}){yield*Rr(e,t,r)}function*Rr(e,t,r,n){ce(r);const o=yr(e),a=new WeakMap;let i=r.knownTotalPages;if(o&&i===void 0){i=0;for(const l of Z(e,t,r,[],void 0,a))i++}const s=[];let c=0;for(const l of Z(e,t,r,s,i,a,n)){for(;c<s.length;c++)r.onWarning?.(s[c]);yield l}}function Pe(e,t,r={}){const n=typeof r=="number"?{mmPerRow:r}:r;ce(n);const o=[],a={chartComponents:0},i=[...Z(e,t,n,o,n.knownTotalPages,void 0,a)];return ct(e,n,i,o,a)}async function st(e,t,r={}){ce(r),B(r.signal);const n=[],o=[],a={chartComponents:0};let i=performance.now(),s=0;for(const c of Z(e,t,r,n,r.knownTotalPages,void 0,a))o.push(c),(++s>=8||performance.now()-i>=8)&&(await new Promise(l=>setTimeout(l,0)),B(r.signal),i=performance.now(),s=0);return B(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(i=>ie(i)?se(i,s=>s.replace(/\{totalPages\}/g,String(r.length))):i);return n.forEach(a=>t.onWarning?.(a)),{plan:{schemaVersion:E.RENDER_PLAN_SCHEMA_VERSION,...Se(e)?{requiresRecalculation:!0}:{},pages:r},warnings:n,...o}}function Cr(e){const t=e.columns.find(a=>!a.hidden)?.field;if(!t)return{groups:0,total:0};const r=ae(e),n=(a=[],i=[])=>a.includes(t)||i.some(s=>s.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 Er(e,t,r){ot(e);const n=W.flattenTreeInput(t[e.dataset]??[],e.tree,r),o=e.columns.filter(i=>!i.hidden).length,a=e.header===!1?0:e.headerGrid?Ee(e.headerGrid):o;return n.length*o+a+ +!!e.grandTotal*2*o}function Pr(e,t,r={}){if(e.tree)return Er(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=_e.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,i=Cr(e);let s=(n*(1+2*a+i.groups)+ +!!e.grandTotal*(1+i.total))*o;if(s+=e.header===!1?0:e.headerGrid?Ee(e.headerGrid):o,e.cardinality==="record"&&n===0&&(s+=o),e.detail){const c=t[e.detail.dataset]?.length??0,l=e.detail.columns.filter(u=>!u.hidden).length;s+=(c+n*(+(e.detail.header!==!1)+ +!!e.detail.label))*l}if(!Number.isSafeInteger(s))throw new RangeError("报表单元格估算超出安全整数预算");return s}class lt extends Error{constructor(t){super(t.map(r=>r.message).join(";")),this.issues=t,this.name="ReportValidationError"}}function He(e,t,r){if(!Number.isSafeInteger(e)||e<1||e>r)throw new Error(`校验 ${t} 超出预算`);return e}function Tr(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("未知校验范围");Tr(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 kr(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 Ir(e,t){const r=t.computed?.length?{fields:t.computed,formula:t.formula,signal:t.signal}:void 0;if(t.tree){const o=W.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 Fr(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 $r(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=He(t.maxChecks??2e6,"maxChecks",1e7),o=He(t.maxIssues??1e3,"maxIssues",1e4);t.rowKey!==void 0&&k.computationFieldName(t.rowKey);const a=Ir(e,t),{rows:i,summaryRows:s,rowKey:c}=a;Fr(i,c);const l=dt(t.rules),u=l.reduce((d,m)=>d+(m.rule.scope==="dataset"?m.checks+s.length*(m.rule.aggregates?.length??0):i.length*m.checks),0);if(r.checks+=u,r.checks>n)throw new Error("整批校验超出 maxChecks 预算");const f=[];for(const d of l)(d.rule.scope==="dataset"?[Object.fromEntries((d.rule.aggregates??[]).map(g=>[g.field,k.aggregateRows(s,{...g,field:g.valueField??g.field})]))]:i).forEach((g,b)=>{if(Ge(t.signal),!g||typeof g!="object"||Array.isArray(g))throw new Error("校验数据行应为对象");if(!(d.when&&!d.when(g)||d.assert(g))){if(f.length>=o)throw new Error("校验问题超出 maxIssues 预算,请缩小范围");f.push(kr(d.rule,g,d.rule.scope==="dataset"?void 0:b,d.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 Or(e,t,r,n=[]){dt(t.rules);const o=[],a={checks:0};for(const[s,c]of e.entries()){const l=new Map;for(const u of c.template.pages)for(const f of u.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[u,f]of l){const d=t.rules.filter(m=>!m.dataset||m.dataset===u);if(d.length&&(o.push(...ut(c.datasets[u]??[],{...t,rules:d,...f,formula:n[s],signal:r},a).map(m=>({...m,dataset:u,sourceScope:c.sourceScope}))),o.length>(t.maxIssues??1e3)))throw new Error("整批候选校验问题超出 maxIssues 预算")}}const i=new Set(e.flatMap(s=>s.template.pages.flatMap(c=>c.components.flatMap(l=>l.kind==="list"?[l.dataset,...l.detail?[l.detail.dataset]:[]]:[]))));if(t.rules.some(s=>s.dataset&&!i.has(s.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 i=E.resolveGridLayout(n,e.widthMm,e.heightMm).cells.filter(c=>c.ri===t).findIndex(c=>c.ci===r),s=o[i];return s?{cell:s,sourceColumnIndex:i}:null}function Ar(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function Nr(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 Lr(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 Kr(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 jr(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=Ar(r),o=Lr(r,e);return{address:{...t},cell:r,component:e,value:n,valueType:Nr(r,n),table:Kr(e,t),source:jr(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(s){if(!s.grid)return;let c=r.get(s);if(!c){const l=E.resolveGridLayout(s.grid,s.widthMm,s.heightMm),u=new Map,f=new Map;for(const d of l.cells){const m=u.get(d.ri)??0;u.set(d.ri,m+1);const g=s.grid.cells[d.ri]?.[m];g&&f.set(`${d.ri}:${d.ci}`,g)}c={layout:t?l:void 0,cells:f},r.set(s,c)}return c}function o(s){if(!mt(s))return null;const c=e.pages[s.pageIndex]?.components[s.componentIndex];if(!c)return null;const l=n(c)?.cells.get(`${s.rowIndex}:${s.columnIndex}`);return l?he(c,s,l):null}function*a(s,c){const l=e.pages[s]?.components[c],u=l&&n(l);if(u)for(const f of i(l).cells){const d=u.cells.get(`${f.ri}:${f.ci}`);d&&(yield he(l,{pageIndex:s,componentIndex:c,rowIndex:f.ri,columnIndex:f.ci},d))}}function i(s){const c=n(s);return c&&(c.layout??E.resolveGridLayout(s.grid,s.widthMm,s.heightMm))}return{resolve:o,entries:a,layout:i}}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 Dr(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 Br(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:Dr(e,ze.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new M("number");return r}function Hr(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"?Br(t,e):e.valueType==="boolean"?Hr(t):t===null?null:String(t)}function Gr(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 _(e,t){return t===null?"":typeof t=="boolean"?Gr(t,e):typeof t=="number"?ze.formatExcelNumber(t,e.cell.numberFormat):String(t)}function Vr(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:_(e,r)}}function Wr(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,i=gt(e,o,a),s=[...n.cells],c=[...s[o]],l=_(t,r.value),u={...i.cell,value:r.value,text:l,rawText:l};return c[i.sourceColumnIndex]=u,s[o]=c,{...e,grid:{...n,cells:s}}}function _r(e,t){const r=e.table?.columnKeys,n=t.table?.columnKey;return r&&n!==void 0?r.flatMap((o,a)=>o===n?[a]:[]):[]}function zr(e,t,r,n,o,a){const i=t.table,s=o.table;if(!i||!s||i.id!==s.id||i.role!==s.role||!t.grid)return t;const c=s.rowIndex-i.rowIndex;if(c<0||c>=t.grid.cells.length)return t;let l=t;for(const u of _r(t,o)){const f=le(e,{pageIndex:r,componentIndex:n,rowIndex:c,columnIndex:u});f?.editable&&Wr(o,f)&&(l=pt(l,f,a))}return l}function Jr(e,t,r,n,o,a){const i=o.address;return o.table?.columnKey!==void 0?zr(e,t,r,n,o,a):i.pageIndex===r&&i.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 qr(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:_(r,n)};if(Object.is(n,r.value)&&o.text===r.cell.text)return e;const a=e.pages.map((i,s)=>{const c=i.components.map((l,u)=>Jr(e,l,s,u,r,o));return c.every((l,u)=>l===i.components[u])?i:{...i,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 i=a.relation,s=i?new Set(i.parentRows.map(c=>JSON.stringify(c[i.detail.parentKey]))):void 0;(n.datasets[a.dataset]??[]).forEach((c,l)=>{if(i&&!s.has(JSON.stringify(c[i.detail.foreignKey])))return;const u=c[a.rowKey];if(typeof u!="string"&&typeof u!="number")return;const f=`${o}:${a.dataset}:${l}:${a.rowKey}`;if(r.has(f))return;r.add(f);const d=te({sourceScope:n.sourceScope,datasetId:a.dataset,rowKey:u}),m=t.get(d)??[];m.push({partIndex:o,dataset:a.dataset,rowIndex:l,row:c,binding:a}),t.set(d,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 Set;for(const{row:o,field:a,value:i}of t){const s=r[o.partIndex],c=JSON.stringify([o.partIndex,o.dataset]);n.has(c)||(s.datasets[o.dataset]=[...s.datasets[o.dataset]],n.add(c)),s.datasets[o.dataset][o.rowIndex]={...s.datasets[o.dataset][o.rowIndex],[a]:i}}for(const o of n){const[a,i]=JSON.parse(o);k.forkComputedDataset(e[a].datasets[i],r[a].datasets[i])}return r}function Ur(e,t,r){const n=[],o=new Set;return e.forEach((a,i)=>{for(const s of wt(a))t.has(J({sourceScope:a.sourceScope,datasetId:s.dataset}))&&(a.datasets[s.dataset]??[]).forEach((c,l)=>{const u={partIndex:i,dataset:s.dataset,rowIndex:l,row:c,binding:s};for(const[f,d]of[[s.revisionField,r.revision],[s.sourceTokenField,r.sourceToken]]){if(!f||d===void 0)continue;const m=`${i}:${s.dataset}:${l}:${f}`;o.has(m)||(o.add(m),n.push({row:u,field:f,value:d}))}})}),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 i=a.datasetId&&t.get(J({...a,datasetId:a.datasetId}));return!i||(i.revision===void 0||Object.is(i.revision,a.revision))&&(i.sourceToken===void 0||i.sourceToken===a.sourceToken)?a:{...a,...i.revision!==void 0?{revision:i.revision}:{},...i.sourceToken!==void 0?{sourceToken:i.sourceToken}:{}}}function n(a){const i=a.map(s=>{const c=s.table?.source?r(s.table.source):void 0,l=s.table&&c!==s.table.source?{...s.table,source:c}:s.table,u=s.grid?.cells.map(d=>{const m=d.map(g=>{if(!g)return g;const b=g.source?r(g.source):void 0,w=g.children?n(g.children):void 0;return b===g.source&&w===g.children?g:{...g,source:b,children:w}});return m.some((g,b)=>g!==d[b])?m:d}),f=s.grid&&u?.some((d,m)=>d!==s.grid.cells[m])?{...s.grid,cells:u}:s.grid;return l!==s.table||f!==s.grid?{...s,table:l,grid:f}:s});return i.some((s,c)=>s!==a[c])?i:a}const o=e.pages.map(a=>{const i=n(a.components);return i!==a.components?{...a,components:i}:a});return o.some((a,i)=>a!==e.pages[i])?{...e,pages:o}:e}function Xr(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function We(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):Xr(e.address)}function Yr(e,t){if(!t.length)return e;const r=new Map(t.map(c=>[We(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 i(c,l,u){const f=c.grid;if(!f||!o.has(`${l}:${u}`)&&!n.has(c.table?.id??""))return c;const d=new Map,m=new Map;for(const g of E.resolveGridLayout(f,c.widthMm,c.heightMm).cells){const b=m.get(g.ri)??0;m.set(g.ri,b+1);const w=a({pageIndex:l,componentIndex:u,rowIndex:g.ri,columnIndex:g.ci}),y=w&&r.get(We(w));if(!y||!w.editable)continue;const h=d.get(g.ri)??[...f.cells[g.ri]],x=_(w,y.value);Object.is(w.value,y.value)&&x===w.cell.text||(h[b]={...g.cell,value:y.value,text:x,rawText:x},d.set(g.ri,h))}return d.size?{...c,grid:{...f,cells:f.cells.map((g,b)=>d.get(b)??g)}}:c}const s=e.pages.map((c,l)=>{const u=c.components.map((f,d)=>i(f,l,d));return u.every((f,d)=>f===c.components[d])?c:{...c,components:u}});return s.every((c,l)=>c===e.pages[l])?e:{...e,pages:s}}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 Qr(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:i,value:s})=>{const c=o(i);if(!c)throw new M("missing");const l=z(c,s),u=N(l);if(n.has(u))throw new M("duplicate");return n.add(u),l});return{requestId:r,edits:a}}function Zr(e,t){if(t.edits.length>1e4)throw new M("limit");const r=V(e),n=new Set,o=t.edits.map(a=>{const i=r(a.address);if(!i)throw new M("missing");const s=N(a);if(n.has(s))throw new M("duplicate");if(n.add(s),de(i,a)||!Object.is(i.value,a.previousValue)||(i.cell.text??"")!==a.previousText)throw new M("conflict");return z(i,a.value)});return Yr(e,o)}function en(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,i)=>{if(!(!a.grid||a.table?.role!=="body"))for(let s=0;s<a.grid.cells.length;s++)for(let c=0;c<a.table.columnKeys.length;c++){const l=r({pageIndex:o,componentIndex:i,rowIndex:s,columnIndex:c});l?.source&&l.editable&&t.set(N(l),l)}})),t}function tn(e,t,r){const n=Mt(e),o=V(e);return t.map(a=>{const i=a.source?n.get(N(a)):o(a.address);if(!i||N(i)!==N(a))throw new M("missing");return{address:{...i.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 i=Object.keys(e),s=i.map(c=>re(e,c));t.push({object:e,prototype:Object.getPrototypeOf(e),keys:i,values:s,...e instanceof Date?{date:Date.prototype.getTime.call(e)}:{},...Array.isArray(e)?{length:e.length}:{}});for(const c of s)xt(c,t,r,n,o+1,a);r.delete(e)}function rn(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,i)=>o[i]===a&&Object.is(re(t,a),n[i]))}function nn(e){return Rt(e)}function on(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(rn)}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 an(e){return ne(e,{nodes:0},0,!0)}function sn(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 cn(e,t,r={}){return(await Ct(e,t,r)).plan}async function Ct(e,t,r={}){return st(e,t,{...r,knownTotalPages:void 0})}function ln(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 dn(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"?ln(o):!o.binding&&!o.chartBinding&&!o.grid&&!o.table&&!o.richParagraphs)))}function un(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 fn(e){return e.pages.every(t=>t.components.every(r=>!r.grid||r.grid.cells.every(n=>n.every(o=>!!o&&Fe(o)))))}function mn(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,i=E.resolveFontSize(a).fontSizePt;if(!Number.isFinite(o)||o<1||!Number.isFinite(i)||i<=0)return!1;const s={fontSizePt:i,fontFamily:a?.fontFamily??E.DEFAULT_FONT_FAMILY,italic:a?.italic,bold:a?.bold,letterSpacingPt:a?.letterSpacing};return A.wrapText(t.previousText,o,s,A.heuristicMeasurer).length===A.wrapText(t.value,o,s,A.heuristicMeasurer).length}function gn(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 hn(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||!gn(a,e)||e.style?.rotateDeg)return null;const i=a.cells[0],s=[...i];for(let c=0;c<i.length;c++){const l=i[c];if(!l||!Fe(l))return null;const u=o.get(e.table.columnKeys[c]);if(u){if(!mn(l,u,a.colWidthsMm[c],a.paddingMm??.5))return null;s[c]={...l,value:u.value,text:u.value},r.add(u)}}return s.some((c,l)=>c!==i[l])?{...e,grid:{...a,cells:[s]}}:e}async function pn(e,t,r){const n=un(t);if(!n||!t.length)return null;const o=new Set,a=[];let i=0;for(const c of e.pages){const l=[];for(const u of c.components){if(r?.aborted)return null;const f=hn(u,n,o);if(!f)return null;l.push(f),++i%128===0&&await new Promise(d=>setTimeout(d,0))}a.push(l.some((u,f)=>u!==c.components[f])?{...c,components:l}:c)}if(o.size!==t.length)return null;const s={...e,pages:a};return H.validateRenderPlan(s).ok?s:null}function wn(e,t,r){let n=dn(t,r),o=e,a;function i(c){if(o=c,a=void 0,!!n){if(!fn(c)){n=!1;return}try{a=on(c)}catch{n=!1}}}i(e);async function s(c,l,u){if(!n||c!==o||!a?.())return null;const f=a,d=await pn(c,l,u);return d&&f()?{plan:d,unchanged:f}:null}return{candidate:s,publish:i}}const pe=new WeakMap;function yn(e){return pe.get(e)}function U(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function Et(e,t){return e[t]===void 0?"":e[t]}function bn(e,t){if(t.edits.length>1e4)throw new M("limit");const r=V(e),n=new Set,o=[],a=t.edits.map(i=>{const s=r(i.address);if(!s?.source)throw new M("missing");const c=N(i);if(n.has(c))throw new M("duplicate");if(n.add(c),de(s,i)||!Object.is(s.value,i.previousValue)||(s.cell.text??"")!==i.previousText)throw new M("conflict");return o.push(s),z(s,i.value)});return{batch:{requestId:t.requestId,edits:a},contexts:o}}function vn(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(Et(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:_(n,n.value)},n}function Mn(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,Ur(e,n,r))}function Sn(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 xn(e,t){return $e(e,t)}function $e(e,t,r){let n=t.parts;const o=t.rebuild,a=[...t.validationFormulas??[]],i=r?wn(e,n,r):void 0;let s=nn(n),c=e,l;const u=new Map,f=new Map;function d(b){if(b!==c)throw new M("conflict");if(l)return l;if(!s?.())throw new M("conflict");return sn(n)}async function m(b,w,y,h={}){U(h.signal),w={requestId:w.requestId,edits:w.edits.map(v=>({...v,address:{...v.address},source:v.source?{...v.source}:void 0,table:v.table?{...v.table}:void 0}))},y=y.map(v=>({...v,address:{...v.address},source:v.source?{...v.source}:void 0,table:v.table?{...v.table}:void 0,cell:{...v.cell}})),await new Promise(v=>setTimeout(v,0)),U(h.signal);const x=d(b),T=bt(x,vn(x,w.edits)),I=await i?.candidate(b,w.edits,h.signal);U(h.signal);const L=ke(I?.plan??await o(T,h.signal),f);U(h.signal);let D=!1,p=[],C="allow",R=!1;function $(v){return R=!0,p=Object.freeze(Or(T,v,h.signal,a).map(F=>Object.freeze({...F}))),R=!1,C=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,C);const F=Mn(T,w,v),K=vt(L,w,v);if(v){const j=Sn(f,w,v);for(const[q,G]of u)j.has(J(G.source))&&u.set(q,fe(G,G.value,v))}return y.forEach((j,q)=>u.set(N(j),fe(j,w.edits[q].value,v))),D=!0,l=F,n=void 0,s=void 0,c=K,i?.publish(c),pe.set(c,g),c}}}const g={get plan(){return c},async prepare(b,w,y){const h=bn(b,w);return m(b,h.batch,h.contexts,y)},async prepareHistory(b,w,y,h,x){if(!h.trim()||w.length>1e4)throw new M("limit");const T=d(b),I=yt(T),L=Mt(b),D=new Set,C=w.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 K=L.get(F)??u.get(F);if(!K?.source)throw new M("missing");const j=I(K.source)[0];return fe(K,Et(j.row,K.source.field))}).map((v,F)=>({context:v,edit:z(v,w[F][y])})).filter(({edit:v})=>!Object.is(v.previousValue,v.value)),R={requestId:h,edits:C.map(({edit:v})=>v)},$=C.map(({context:v})=>v);return{batch:R,contexts:$,prepared:await m(b,R,$,x)}}};return pe.set(e,g),g}function Rn(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)=>cn(r[0].template,r[0].datasets,{...e.pagination,signal:n})},[e.pagination])}let Cn=0;function Pt(){return`report-${Date.now()}-${++Cn}`}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 i=await o();return r(n,"completed",a),i}catch(i){throw r(n,"failed",a),i}},runSync(n,o,a){r(n,"started",a);try{const i=o();return r(n,"completed",a),i}catch(i){throw r(n,"failed",a),i}}}}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 En(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 i of a.components){if(i.kind!=="list"||i.tree?.input!=="nested")continue;const s=n.get(i.dataset);if(s&&(s.childrenField??"children")!==(i.tree.childrenField??"children"))throw new Error("同一数据集的嵌套树应使用相同 childrenField");n.set(i.dataset,i.tree)}if(!n.size)return t;const o={...t};for(const[a,i]of n){const s=Math.min(i.maxRows??1e5,r.maxRows??1/0);o[a]=W.flattenTreeInput(t[a]??[],{...i,maxRows:s},r.signal)}return o}function Pn(e,t,r={}){return Object.values(Ae(e,t,r)).reduce((n,o)=>n+o.length,0)}function Tn(e,t,r){const n=Me.datasetJsonSchema(r),o=e?.pages.flatMap(s=>s.components).find(s=>s.kind==="list"&&s.dataset===t&&s.tree?.input==="nested");if(!o||o.kind!=="list"||!o.tree)return n;const a=n.items,i=o.tree.childrenField??"children";return{...n,items:{$ref:"#/$defs/treeNode"},$defs:{treeNode:{...a,properties:{...a.properties,[i]:{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(i=>i.map(s=>!s||!s.source&&!s.children?s:{...s,...s.source?{source:{...s.source,sourceScope:t}}:{},...s.children?{children:Ft(s.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 kn(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 In(e){const t=r=>r.grid?.cells.reduce((n,o)=>n+o.reduce((a,i)=>a+(i?1+(i.children?.reduce((s,c)=>s+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),i=t.maxChartComponents-t.usedChartComponents;if(a!==void 0&&a<1&&r.pages.length&&!kn(r,n))throw new S.PaginatePageLimitError(0,1);if(i<1&&r.pages.some(s=>s.components.some(c=>c.kind!=="list"&&c.chartBinding)))throw new S.PaginateChartComponentLimitError(i,1);return{...e,signal:o??e?.signal,maxPages:me(a,e?.maxPages),maxCells:me(be(t.maxCells,t.usedCells),e?.maxCells),maxChartComponents:me(i,e?.maxChartComponents)}}function Ot(e,t){const r=In(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 Fn(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(i){throw new P("validate",`报表 ${o.reportId} 数据映射失败`,i)}}}}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(i=>{o(),r(i)},i=>{o(),n(i)})}):Promise.resolve(e)}function $n(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 On(e,t,r){const{reportId:n,signal:o}=t;try{const a=await ve(e(t),o);O(o);const i=H.validateReportTemplate(a);if(!i.ok)throw new P("validate",`报表 ${n} 模板校验失败:${i.errors.slice(0,3).map(s=>`${s.path}: ${s.message}`).join("; ")}`);return r.push(...i.warnings.map(s=>`${n}: ${s.path}: ${s.message}`)),a}catch(a){throw o?.aborted?ue(o):a instanceof P?a:a instanceof H.ReportTemplateError?new P("validate",`报表 ${n} 模板校验失败:${a.message}`,a):new P("fetch",`报表 ${n} 模板加载失败:${a instanceof Error?a.message:String(a)}`,a)}}async function An(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 i=await ve(e.provider.query(t),o);O(o),Nn(i,r),a=i.datasets,n?.(r,i)}else a=e.datasets??{}}catch(i){throw o?.aborted?ue(o):i instanceof P?i:new P("fetch",`报表 ${r} 取数失败:${i instanceof Error?i.message:String(i)}`,i)}return O(o),a}function Nn(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 Ln(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,i]of Object.entries(e.dataSchema??{})){let s;try{s=Me.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0,i,{...e.dataValidation,path:`$.datasets.${a}`})}catch(c){throw new P("config",`报表 ${r} 数据集 ${a} 字段契约配置无效`,c)}if(!s.ok)throw new P("validate",`报表 ${r} 数据集 ${a} 不符合字段契约:${s.issues[0]?.message}`,{issues:s.issues})}}async function Kn(e,t,r,n,o){try{let a;try{a=an(e)}catch{}const i=a??e,s=$t(t.pagination,n,i.template,i.datasets,o),c=a?await st(i.template,i.datasets,s):Pe(i.template,i.datasets,s);return Ot(n,c),{result:c,part:i}}catch(a){O(o);const i=At(a,n);throw new P("validate",`报表 ${r} 排版失败:${i instanceof Error?i.message:String(i)}`,i)}}function Nt(e,t,r,n,o){const a=new Map,i=s=>{let c=a.get(s);return c===void 0&&(c=JSON.stringify([r,n,s]),a.set(s,c)),c};for(const s of t.pages)e.push({...s,meta:{...s.meta,reportScope:Ne(r,n)},components:Ft(s.components,o??Le(r,n),i)})}async function jn(e,t,r,n,o){const a=[],i=ye(n);for(const[l,u]of e.entries()){O(o);try{const f=await Ct(u.template,u.datasets,$t(t[l]?.pagination,i,u.template,u.datasets,o));Ot(i,f),Nt(a,f.plan,l,r[l],u.sourceScope)}catch(f){throw At(f,i)}}const s={schemaVersion:E.RENDER_PLAN_SCHEMA_VERSION,...e.some(l=>Se(l.template))?{requiresRecalculation:!0}:{},pages:a},c=H.validateRenderPlan(s);if(!c.ok)throw new P("validate",`重算渲染计划校验失败:${c.errors[0]?.message}`);return s}function Dn(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:i,onWarning:s,onQueryResult:c,...l})=>{O(i);const u=Tt({...l,signal:i}),f=[...o],d={...a};if(f.length===0)throw new P("config","缺少报表 ID");const m=f.map(r),g=u.runSync("validate",()=>m.map(p=>Ke.assertReportParams(p.params??(typeof p.template=="function"?[]:p.template.params)??[],d))),b=[],w=[],y=ye(t),h=[];for(const[p,C]of m.entries()){O(i);const R=f[p],$={reportId:R,params:g[p],signal:i},v=typeof C.template=="function"?await u.run("query",()=>On(C.template,$,h),R):C.template;$.params=u.runSync("validate",()=>Ke.assertReportParams(C.params??v.params??[],$.params),R);const F=await u.run("query",()=>An(C,$,R,(G,Lt)=>c?.(G,Lt,p)),R);u.runSync("validate",()=>{$n(F,R),t.onDatasets?.(R,F,v),Ln(C,F,R,v,i)},R),O(i);const K=Le(p,R,C.sourceScope),{result:j,part:q}=await u.run("layout",()=>Kn({template:v,datasets:F,sourceScope:K},C,R,y,i),R);w.push(q),Nt(b,j.plan,p,R,K),h.push(...j.warnings.map(G=>`${R}: ${G}`))}O(i);const x={schemaVersion:E.RENDER_PLAN_SCHEMA_VERSION,...w.some(p=>Se(p.template))?{requiresRecalculation:!0}:{},pages:b},T=u.runSync("validate",()=>{const p=H.validateRenderPlan(x);if(!p.ok)throw new P("validate",`渲染计划校验失败:${p.errors.slice(0,3).map(C=>`${C.path}: ${C.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:w,validationFormulas:I.map(p=>p.pagination?.formula),rebuild:(p,C)=>jn(p,I,f,L,C)},I.map(p=>p.pagination))}catch{h.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const D=s??t.onWarning??(p=>console.warn("[mach-report]",p));for(const p of h)O(i),D(p);return O(i),x},{getParamDefs:o=>Kt.getReportParamDefs(e,o)})}const Bn=new Set([8,9,10,12,13]);function Hn(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,i)=>a!==String(i))))throw t("input","快照数组应为连续数组");return{array:r,keys:o}}function Gn(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+=Bn.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 Vn(e,t){const r=t.maxNodes??1e6;if(![t.maxBytes,r].every(d=>Number.isSafeInteger(d)&&d>0))throw t.error("budget","快照预算应为正安全整数");let n=0,o=0;const a=new Set,i=new Map;function s(d){if(d.length+2>t.maxBytes-o)throw t.error("budget","快照超过字节预算");const m=i.get(d);if(m!==void 0)return m;const g=Gn(d);return d.length<=256&&i.size<4096&&i.set(d,g),g}function c(d){if(o+=d,o>t.maxBytes)throw t.error("budget","快照超过字节预算")}function l(d,m){if(++n>r||m>64)throw t.error("budget","快照节点或深度超过预算");if(n%1024===0&&t.check?.(),typeof d=="string")return c(s(d)),d;if(d===null||typeof d=="boolean"||typeof d=="number"&&Number.isFinite(d))return c(String(d).length),typeof d=="number"&&Object.is(d,-0)?0:d;if(!d||typeof d!="object"||a.has(d))throw t.error("input","快照应为无循环的有限 JSON 值");return u(d,m)}function u(d,m){const{array:g,keys:b}=Hn(d,t.error);a.add(d),c(2);const w=g?[]:{};let y=0;for(const h of b){const x=Object.getOwnPropertyDescriptor(d,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((y++?1:0)+(g?0:s(h)+1));const T=l(x.value===void 0?null:x.value,m+1);h in w?Object.defineProperty(w,h,{value:T,enumerable:!0,configurable:!0,writable:!0}):w[h]=T}return a.delete(d),w}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=qr;exports.applyReportCellEditBatch=Zr;exports.applyReportEditResult=vt;exports.applyReportSourceMetadata=ke;exports.assertReportValidation=ft;exports.countTemplatePages=Sr;exports.createReportCellEdit=Vr;exports.createReportCellEditBatch=Qr;exports.createReportCellIndex=ht;exports.createReportCellResolver=V;exports.createReportEditSession=Rn;exports.createReportSource=Dn;exports.createReportTaskReporter=Tt;exports.defineReport=Fn;exports.editFromContext=z;exports.estimateListLayoutCells=Pr;exports.explainDatasetField=En;exports.formatReportCellEdit=_;exports.getReportCellContext=le;exports.getReportEditSession=yn;exports.hasValidDataExplanation=It;exports.isReportDataTarget=Oe;exports.isReportValueState=kt;exports.notifyReportTaskEvent=we;exports.paginateTemplate=Pe;exports.paginateTemplatePages=xr;exports.parseReportCellInput=Te;exports.projectListColumns=Je;exports.registerReportEditSession=xn;exports.relocateReportCellEdits=tn;exports.reportCellEditKey=N;exports.reportOccurrenceScope=Ne;exports.reportSourceScope=Le;exports.reportTaskId=Pt;exports.snapshotReportJson=Vn;exports.sourceChanged=de;exports.summarizeReportCellEdits=en;exports.templateDatasetJsonSchema=Tn;exports.templateDatasetRowCount=Pn;exports.templateValidationDatasets=Ae;exports.validateReportDataset=$r;
|