@agile-team/mach-report 2.25.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 (77) hide show
  1. package/README.md +4 -2
  2. package/dist/{ExcelBindingWizard-NQ_v396s.js → ExcelBindingWizard-bs3F4dD8.js} +3 -3
  3. package/dist/{ExcelBindingWizard-BgJG-T6k.cjs → ExcelBindingWizard-jSdjBtWw.cjs} +1 -1
  4. package/dist/{ParamEditor-Z-3yodp5.js → ParamEditor-B7YVD28E.js} +1 -1
  5. package/dist/{ParamEditor-DEP38mBp.cjs → ParamEditor-CGfaweYX.cjs} +1 -1
  6. package/dist/{ReportBatchPanel-D33LjMrA.cjs → ReportBatchPanel-BRJt0TXp.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-DG8FV-5X.js → ReportBatchPanel-BTKHtLTW.js} +1 -1
  8. package/dist/{ReportLabelStudio-Bz-xAayk.cjs → ReportLabelStudio-BvK_WBke.cjs} +1 -1
  9. package/dist/{ReportLabelStudio-BZp23_hA.js → ReportLabelStudio-CZwqyO3t.js} +2 -2
  10. package/dist/{ReportPreview-CilFAS9U.js → ReportPreview-CnxaDTCO.js} +4 -4
  11. package/dist/{ReportPreview-dOOzPts2.cjs → ReportPreview-DqFBcsJQ.cjs} +2 -2
  12. package/dist/{ReportTemplateLibrary-DpSGgvFa.js → ReportTemplateLibrary-C7sB0Jay.js} +1 -1
  13. package/dist/{ReportTemplateLibrary-uG1gENaW.cjs → ReportTemplateLibrary-ClwxhnC0.cjs} +1 -1
  14. package/dist/{RuleEditor-BONALh1Q.js → RuleEditor-CsDGFaWz.js} +3 -3
  15. package/dist/{RuleEditor-bLXiRcxL.cjs → RuleEditor-D-OdaGdR.cjs} +1 -1
  16. package/dist/{TemplateOutlinePanel-JGBKeF3e.js → TemplateOutlinePanel-CXOT7d1r.js} +1 -1
  17. package/dist/{TemplateOutlinePanel-C3nfHuaR.cjs → TemplateOutlinePanel-DAqR9zQi.cjs} +1 -1
  18. package/dist/{TemplateReusePanel-DXQUO6nQ.js → TemplateReusePanel-Dcfx3Hba.js} +2 -2
  19. package/dist/{TemplateReusePanel-BKhgp6kg.cjs → TemplateReusePanel-ygIi-Ajz.cjs} +1 -1
  20. package/dist/{TemplateReviewPanel-DhL7Hapy.js → TemplateReviewPanel-COU8FqPq.js} +1 -1
  21. package/dist/{TemplateReviewPanel-5RWFUUEf.cjs → TemplateReviewPanel-DyGULVxr.cjs} +1 -1
  22. package/dist/analytics.cjs +1 -1
  23. package/dist/analytics.js +2 -2
  24. package/dist/artifact-integrity.json +71 -71
  25. package/dist/{auto-umW_ozwr.js → auto-D7x7QsWD.js} +4 -4
  26. package/dist/{auto-D-eDZa_V.cjs → auto-mPK9W0y5.cjs} +1 -1
  27. package/dist/{designer-CCyj5WYS.js → designer-B597ZdC0.js} +4 -4
  28. package/dist/{designer-Cj7fn4Hh.cjs → designer-DFIdv_n7.cjs} +1 -1
  29. package/dist/designer.cjs +1 -1
  30. package/dist/designer.js +1 -1
  31. package/dist/{encoding-CEkBtlUP.js → encoding-Amq3XrtU.js} +2 -2
  32. package/dist/{encoding-Cipno7dq.cjs → encoding-DRVXs5xm.cjs} +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +8 -8
  35. package/dist/{json-snapshot-x0JpllWL.js → json-snapshot-CBVWZvyC.js} +661 -614
  36. package/dist/json-snapshot-DCFEtfFw.cjs +2 -0
  37. package/dist/matrix-DUYPRL7t.cjs +1 -0
  38. package/dist/{matrix-C6e_r_vp.js → matrix-b6T291xo.js} +120 -104
  39. package/dist/{plugin-CttO46hc.js → plugin-BdCplNe1.js} +1 -1
  40. package/dist/{plugin-B_k23hut.cjs → plugin-DHe8y5pD.cjs} +1 -1
  41. package/dist/{prefill-BkF9Fw_p.js → prefill-Buy4NJ15.js} +1 -1
  42. package/dist/{prefill-BvkuwooY.cjs → prefill-Cw4ZYGXZ.cjs} +1 -1
  43. package/dist/{prepared-CSywIEAZ.cjs → prepared-BlNeOjoO.cjs} +1 -1
  44. package/dist/{prepared-Cyuh61fJ.js → prepared-CBJ7BkK0.js} +1 -1
  45. package/dist/{protocol-BwbJNVZl.cjs → protocol-BU_4sXP0.cjs} +1 -1
  46. package/dist/{protocol-DwtxjXzO.js → protocol-CB19KXGr.js} +2 -2
  47. package/dist/{region-binding-workflow-D8I4QWRh.js → region-binding-workflow-EYxvUYJ-.js} +1 -1
  48. package/dist/{region-binding-workflow-COD8nISZ.cjs → region-binding-workflow-NdkMSFCh.cjs} +1 -1
  49. package/dist/report-encoding-worker.cjs +1 -1
  50. package/dist/report-encoding-worker.js +1 -1
  51. package/dist/{runtime-BE30icyB.js → runtime-B5d_lQNQ.js} +3 -3
  52. package/dist/{runtime-DRSuy_SQ.cjs → runtime-BRx8Agqr.cjs} +1 -1
  53. package/dist/sbom.cdx.json +1 -1
  54. package/dist/server-node.cjs +5 -5
  55. package/dist/server-node.js +1686 -1622
  56. package/dist/server.cjs +1 -1
  57. package/dist/server.js +6 -6
  58. package/dist/{template-catalog-D_gl93va.js → template-catalog-CM6U_RlD.js} +2 -2
  59. package/dist/{template-catalog-C0riwrx7.cjs → template-catalog-Cj66M84u.cjs} +1 -1
  60. package/dist/{template-fragments-D94ZZmPc.js → template-fragments-BDxdCuMD.js} +1 -1
  61. package/dist/{template-fragments-CgzPdFKB.cjs → template-fragments-DbKdxI1z.cjs} +1 -1
  62. package/dist/template-registry-B-AK1oam.cjs +1 -0
  63. package/dist/{template-registry-DZOtRY7t.js → template-registry-DeVgwEZj.js} +143 -142
  64. package/dist/vue-async.cjs +1 -1
  65. package/dist/vue-async.js +3 -3
  66. package/dist/vue.cjs +1 -1
  67. package/dist/vue.js +4 -4
  68. package/dist/{workbook-session-SzfILBJJ.js → workbook-session-B6hRjTyX.js} +1 -1
  69. package/dist/{workbook-session-DR2j6Hxm.cjs → workbook-session-BclW7KKH.cjs} +1 -1
  70. package/dist/worker.cjs +1 -1
  71. package/dist/worker.js +4 -4
  72. package/dist/xlsx.cjs +1 -1
  73. package/dist/xlsx.js +3 -3
  74. package/package.json +1 -1
  75. package/dist/json-snapshot-DQdkA_At.cjs +0 -2
  76. package/dist/matrix-B8QWbsGM.cjs +0 -1
  77. package/dist/template-registry-BMScUmM4.cjs +0 -1
package/dist/worker.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./protocol-BwbJNVZl.cjs"),s=require("./auto-D-eDZa_V.cjs"),R=require("./encoding-Cipno7dq.cjs");function p(n,e=globalThis){const a=t=>{r.isReportWorkerRequest(t.data)&&r.runReportWorkerRequest(n,t.data,o=>e.postMessage({protocol:r.REPORT_WORKER_PROTOCOL,id:t.data.id,type:"event",event:o})).then(o=>e.postMessage(o,r.reportWorkerTransferList(o)))};return e.addEventListener("message",a),()=>e.removeEventListener("message",a)}exports.ReportWorkerError=r.ReportWorkerError;exports.ReportWorkerStartError=s.ReportWorkerStartError;exports.createAutoReportExporter=s.createAutoReportExporter;exports.createBrowserReportExecutor=s.createBrowserReportExecutor;exports.serveReportEncodingWorker=R.serveReportEncodingWorker;exports.serveReportWorker=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./protocol-BU_4sXP0.cjs"),s=require("./auto-mPK9W0y5.cjs"),R=require("./encoding-DRVXs5xm.cjs");function p(n,e=globalThis){const a=t=>{r.isReportWorkerRequest(t.data)&&r.runReportWorkerRequest(n,t.data,o=>e.postMessage({protocol:r.REPORT_WORKER_PROTOCOL,id:t.data.id,type:"event",event:o})).then(o=>e.postMessage(o,r.reportWorkerTransferList(o)))};return e.addEventListener("message",a),()=>e.removeEventListener("message",a)}exports.ReportWorkerError=r.ReportWorkerError;exports.ReportWorkerStartError=s.ReportWorkerStartError;exports.createAutoReportExporter=s.createAutoReportExporter;exports.createBrowserReportExecutor=s.createBrowserReportExecutor;exports.serveReportEncodingWorker=R.serveReportEncodingWorker;exports.serveReportWorker=p;
package/dist/worker.js CHANGED
@@ -1,7 +1,7 @@
1
- import { i as a, r as R, R as p, a as n } from "./protocol-DwtxjXzO.js";
2
- import { b as W } from "./protocol-DwtxjXzO.js";
3
- import { R as g, c as k, a as u } from "./auto-umW_ozwr.js";
4
- import { s as x } from "./encoding-CEkBtlUP.js";
1
+ import { i as a, r as R, R as p, a as n } from "./protocol-CB19KXGr.js";
2
+ import { b as W } from "./protocol-CB19KXGr.js";
3
+ import { R as g, c as k, a as u } from "./auto-D7x7QsWD.js";
4
+ import { s as x } from "./encoding-Amq3XrtU.js";
5
5
  function d(s, r = globalThis) {
6
6
  const t = (o) => {
7
7
  a(o.data) && R(s, o.data, (e) => r.postMessage({ protocol: p, id: o.data.id, type: "event", event: e })).then((e) => r.postMessage(e, n(e)));
package/dist/xlsx.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./diagnostic-collector-wASg6Fzs.cjs"),N=require("./index-CUNw7dL9.cjs"),G=require("./data-bar-DzceAVeR.cjs"),p=require("./workbook-session-DR2j6Hxm.cjs"),j=require("./media-B7vnpD8k.cjs"),H=require("./capabilities-D4nfhcvB.cjs"),q=require("./assets-BYdpkTIt.cjs"),R=require("./workbook-sheets-CaPAulQ6.cjs"),w=require("./region-binding-workflow-COD8nISZ.cjs");function _(e){const t=N.encodePng({width:1,height:1,channels:4,depth:8,data:new Uint8Array([1,3,5].map(o=>parseInt(e.slice(o,o+2),16)).concat(89))});return`data:image/png;base64,${btoa(String.fromCharCode(...t))}`}function U(e,t,o){const n=new Map;let r=0;return(a,i,s,l)=>{const c=G.dataBarBox(i.cell.dataBar,i.widthMm,i.heightMm,l);if(!c)return;if(++r>t)throw new Error(`Excel 数据条超过 ${t} 个绘图预算,请缩小范围或调整 maxDataBars`);let d=n.get(c.color);d||(d=_(c.color),n.set(c.color,d)),r===1&&o.push("数据条为静态半透明视觉快照,保留原始单元格值;Excel 编辑不会重算条形,绘图叠加文字的混色与预览可能略有差异。"),e.write(a,{kind:"image",leftMm:0,topMm:0,widthMm:c.width,heightMm:c.height,imageData:d},s,{leftMm:i.xMm+c.x,offsetMm:c.y})}}async function X(e,t,o){const n=e.pages.flatMap(i=>i.components),r=h.createOutputScheduler(o);let a=0;for(;n.length;){const i=n.pop();for(const s of i.grid?.cells??[])for(const l of s){if(l?.dataBar&&l.dataBar.end>l.dataBar.start&&++a>t)throw new Error(`Excel 数据条超过 ${t} 个绘图预算,请缩小范围或调整 maxDataBars`);l?.children&&n.push(...l.children);const c=r();c&&await c}}}function A(e,t){return{richText:e.flatMap((o,n)=>[...n?[{text:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./diagnostic-collector-wASg6Fzs.cjs"),N=require("./index-CUNw7dL9.cjs"),G=require("./data-bar-DzceAVeR.cjs"),p=require("./workbook-session-BclW7KKH.cjs"),j=require("./media-B7vnpD8k.cjs"),H=require("./capabilities-D4nfhcvB.cjs"),q=require("./assets-BYdpkTIt.cjs"),R=require("./workbook-sheets-CaPAulQ6.cjs"),w=require("./region-binding-workflow-NdkMSFCh.cjs");function _(e){const t=N.encodePng({width:1,height:1,channels:4,depth:8,data:new Uint8Array([1,3,5].map(o=>parseInt(e.slice(o,o+2),16)).concat(89))});return`data:image/png;base64,${btoa(String.fromCharCode(...t))}`}function U(e,t,o){const n=new Map;let r=0;return(a,i,s,l)=>{const c=G.dataBarBox(i.cell.dataBar,i.widthMm,i.heightMm,l);if(!c)return;if(++r>t)throw new Error(`Excel 数据条超过 ${t} 个绘图预算,请缩小范围或调整 maxDataBars`);let d=n.get(c.color);d||(d=_(c.color),n.set(c.color,d)),r===1&&o.push("数据条为静态半透明视觉快照,保留原始单元格值;Excel 编辑不会重算条形,绘图叠加文字的混色与预览可能略有差异。"),e.write(a,{kind:"image",leftMm:0,topMm:0,widthMm:c.width,heightMm:c.height,imageData:d},s,{leftMm:i.xMm+c.x,offsetMm:c.y})}}async function X(e,t,o){const n=e.pages.flatMap(i=>i.components),r=h.createOutputScheduler(o);let a=0;for(;n.length;){const i=n.pop();for(const s of i.grid?.cells??[])for(const l of s){if(l?.dataBar&&l.dataBar.end>l.dataBar.start&&++a>t)throw new Error(`Excel 数据条超过 ${t} 个绘图预算,请缩小范围或调整 maxDataBars`);l?.children&&n.push(...l.children);const c=r();c&&await c}}}function A(e,t){return{richText:e.flatMap((o,n)=>[...n?[{text:`
2
2
  `}]:[],...o.segments.map(r=>{const a=h.mergeComponentStyles(t,r.style),i=a.color?.replace(/^#/,"");return{text:r.kind==="field"?r.field??"":r.text??"",font:{name:a.fontFamily,bold:a.bold,italic:a.italic,underline:a.underline,size:h.resolveFontSize(a).fontSizePt,.../^[a-f\d]{6}$/i.test(i??"")?{color:{argb:`FF${i.toUpperCase()}`}}:{}}}})])}}function K(e,t){const o=e.children?.filter(a=>a.kind==="text"&&!a.grid)??[];if(!e.richParagraphs?.length&&!o.length)return;const n=h.mergeComponentStyles(t,e.style),r=e.richParagraphs?.length?[...e.richParagraphs]:e.text?[{segments:[{text:e.text}]}]:[];for(const a of o){const i=h.mergeComponentStyles(n,a.style),s=a.richParagraphs?.length?a.richParagraphs:[{segments:[{text:a.lines?.join(`
3
3
  `)??a.text??""}]}];for(const l of s)r.push({...l,segments:l.segments.map(c=>({...c,style:h.mergeComponentStyles(i,c.style)}))})}return A(r,n)}function J(e,t,o){let n=o*72/25.4;if(!Number.isFinite(n)||t+Math.ceil(n/409)-1>1048576)throw new Error("Excel 图片占位超过工作表行数上限");for(;n>0;){if(t>1048576)throw new Error("Excel 图片占位超过工作表行数上限");const r=Math.min(409,n);e.getRow(t++).height=r,n-=r}return t}function V(e,t,o){let n=Math.round(t*36e3),r=0;if(!Number.isSafeInteger(n))throw new Error("Excel 图片锚点超出安全坐标范围");for(e.properties.defaultColWidth??=8.43;r<16384;){const a=e.getColumn(r+1).width??e.properties.defaultColWidth,i=Math.round(p.excelColumnWidthToMm(a)*36e3);if(!Number.isSafeInteger(i)||i<=0)throw new Error("Excel 图片锚点所在列宽无效");if(n<i)return{col:r+n/i,row:o-1,nativeCol:r,nativeColOff:n,nativeRow:o-1,nativeRowOff:0};n-=i,r++}throw new Error("Excel 图片锚点超过16384列上限")}function Q(e,t,o){let n=o*72/25.4;if(!Number.isFinite(n)||Math.abs(n)>1048576*409)throw new Error("Excel 图片纵向偏移超过工作表范围");const r=a=>{const i=e.getRow(a).height??e.properties.defaultRowHeight??15;if(!Number.isFinite(i)||i<=0)throw new Error("Excel 图片锚点所在行高无效");return i};for(;n<0&&t>1;)n+=r(--t);for(;t<=1048576&&n>=r(t);)n-=r(t++);if(t>1048576||n<0)throw new Error("Excel 图片移动到工作表边界之外");return{nativeRow:t-1,nativeRowOff:Math.round(n*25.4/72*36e3)}}function Y(e,t,o){const n=j.createImageMediaInspector(t),r=new Map;return{write(a,i,s,l){if(![i.widthMm,i.heightMm,i.leftMm].every(Number.isFinite)||i.widthMm<0||i.heightMm<0||i.leftMm<0)throw new Error("Excel 图片尺寸无效");if(!i.widthMm||!i.heightMm)return s;if(!i.imageData||!/^data:image\/(png|jpe?g);base64,/i.test(i.imageData))return o.push(`${i.nid??i.kind}: Excel 图片仅支持 PNG/JPEG data URI,已跳过`),s;const c=n(i.imageData);let d=r.get(c.dataUrl);d===void 0&&(d=e.addImage({base64:c.dataUrl,extension:c.extension}),r.set(c.dataUrl,d));const g=l?s:J(a,s,i.heightMm);return a.addImage(d,{tl:{...V(a,l?.leftMm??i.leftMm,s),...l?Q(a,s,l.offsetMm):{}},ext:{width:i.widthMm*96/25.4,height:i.heightMm*96/25.4},editAs:"oneCell"}),g}}}function P(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function T(e,t){const o=e.meta?.xlsxFlow;if(o===void 0)return;if(!P(o)||o.version!=="1.0"||!Number.isSafeInteger(o.columnStart)||Number(o.columnStart)<0)throw new Error("Excel 多区域几何标记无效,不能按列序猜测输出");if(!e.grid)throw new Error("Excel 多区域输出只接受显式网格组件");const n=o,r=e.grid.colWidthsMm;if(!r?.length||n.columnStart+r.length>t.length||r.some((a,i)=>Math.abs(a-t[n.columnStart+i])>.001))throw new Error("Excel 多区域列位置与网格列宽不一致");return n}function $(e){const t=e.meta?.xlsxFlow;if(t===void 0){if(e.components.some(n=>n.meta?.xlsxFlow!==void 0))throw new Error("Excel 多区域页面缺少完整列几何标记");return}const o=Z(t,e.meta?.reportScope);for(const n of e.components){const r=T(n,o.widths);if(!r)throw new Error("Excel 多区域页面混入没有区域几何的组件,请使用独立页面模板");const a=o.widths.slice(0,r.columnStart).reduce((s,l)=>s+l,e.marginLeftMm??0),i=n.grid.colWidthsMm.reduce((s,l)=>s+l,0);if(Math.abs(a-n.leftMm)>.01||Math.abs(i-n.widthMm)>.01)throw new Error("Excel 多区域标记与真实横向位置不一致")}return o}function Z(e,t){if(!P(e)||e.version!=="1.0"||typeof e.sheet!="string"||!e.sheet.trim()||typeof e.templateId!="string"||!e.templateId.trim())throw new Error("Excel 多区域工作表标识无效");if(!Array.isArray(e.fullWidthsMm)||!e.fullWidthsMm.length||e.fullWidthsMm.length>16384||e.fullWidthsMm.some(o=>typeof o!="number"||!Number.isFinite(o)||o<=0||o>2e3))throw new Error("Excel 多区域完整列宽无效");if(t!==void 0&&(typeof t!="string"||!t.trim()))throw new Error("Excel 多区域报表命名空间无效");return{key:JSON.stringify([t??e.templateId,e.sheet]),sheet:e.sheet,widths:e.fullWidthsMm}}function v(e){return Math.round(e*1e6)/1e6}function ee(e,t,o,n,r){return e.components.filter(a=>n?a.pageAnchor==="header"?t===0:a.pageAnchor==="footer"?t===o-1:a.table?.role!=="header"?!0:r.has(a.table.id)?!1:(r.add(a.table.id),!0):!0)}function te(e,t,o,n){const r=e.components.filter(i=>!t.includes(i)&&i.table?.role==="header"),a=t.filter(i=>!i.pageAnchor).reduce((i,s)=>Math.max(i,s.topMm+s.heightMm),e.marginTopMm??0);return t.map(i=>{let s=i.topMm;return o&&i.pageAnchor==="footer"&&(s=a),s-=r.filter(l=>l.topMm+l.heightMm<=s+.001).reduce((l,c)=>l+c.heightMm,0),{component:i,layout:h.resolveGridLayout(i.grid,i.widthMm,i.heightMm),top:s,column:T(i,n).columnStart}})}function ne(e,t,o){const n=t.length-1;if(n*o.length>1e6)throw new Error("Excel 多区域单页超过 100 万几何单元格,请减小预览分页高度或列数");const r=new Map(t.map((s,l)=>[s,l])),a=new Map,i=new Map;for(const s of e)for(const l of s.layout.cells){if(!Object.keys(l.cell).length)continue;const c=r.get(v(s.top+l.yMm)),d=r.get(v(s.top+l.yMm+l.heightMm)),g=s.column+l.ci,m=g+(l.cell.colSpan??1),u=`${c}:${g}`;for(let f=c;f<d;f++)for(let E=g;E<m;E++){const M=`${f}:${E}`;if(i.has(M))throw new Error("Excel 多区域实际单元格互相覆盖,已终止输出,未覆盖已有内容");i.set(M,u)}a.set(u,{...l.cell,style:h.resolveGridCellStyle(s.component.style,l.cell),rowSpan:d-c,colSpan:m-g})}return Array.from({length:n},(s,l)=>{const c=[];for(let d=0;d<o.length;d++){const g=`${l}:${d}`,m=a.get(g);m?(c.push(m),d+=(m.colSpan??1)-1):i.has(g)||c.push(null)}return c})}function ie(e,t){const o=new Set,n=[];let r;for(const[a,{page:i}]of e.entries()){const s=$(i);if(r&&(s.key!==r.key||s.widths.length!==r.widths.length||s.widths.some((u,f)=>Math.abs(u-r.widths[f])>.001)))throw new Error("Excel 多区域分页的工作表或列结构不一致");r??=s;const l=ee(i,a,e.length,t,o),c=te(i,l,t,s.widths);if(!c.length)continue;const d=[...new Set(c.flatMap(u=>[...u.layout.rows.map(f=>v(u.top+f.pos)),v(u.top+u.component.heightMm)]))].sort((u,f)=>u-f),g=ne(c,d,s.widths),m=d.slice(1).map((u,f)=>u-d[f]);n.push({kind:"rect",leftMm:0,topMm:0,widthMm:s.widths.reduce((u,f)=>u+f,0),heightMm:m.reduce((u,f)=>u+f,0),grid:{cells:g,colWidthsMm:s.widths,rowHeightsMm:m}})}return n}const F=72/25.4,re=32767,oe=253;function b(e,t){if(typeof e!="string")return;if(e.length>re)throw new Error(`Excel 单元格 ${t} 最多支持 32767 个字符,无法无损导出;内容未裁剪`);let o=0;for(let n=0;n<e.length;n++)if(e.charCodeAt(n)===10&&++o>oe)throw new Error(`Excel 单元格 ${t} 最多支持 253 个换行,无法无损导出;内容未改写`)}function y(e){if(!e)return;const t=e.replace("#","");return/^[0-9a-fA-F]{6}$/.test(t)?`FF${t.toUpperCase()}`:void 0}function I(e,t={}){e.font={name:t.fontFamily,bold:t.bold===!0,italic:t.italic===!0,underline:t.underline===!0,size:h.resolveFontSize(t).fontSizePt,color:y(t.color)?{argb:y(t.color)}:void 0}}const S={a3:{width:297,height:420,code:8},a4:{width:210,height:297,code:9},a5:{width:148,height:210,code:11}};function ae(e,t,o,n){if(t&&t!=="auto")return S[t].code;const r=Math.min(e.pageWidthMm,e.pageHeightMm),a=Math.max(e.pageWidthMm,e.pageHeightMm),i=Object.values(S).find(s=>Math.abs(r-s.width)<=1&&Math.abs(a-s.height)<=1);return i?i.code:(n.push(`page ${o+1}: 自定义纸张 ${e.pageWidthMm}×${e.pageHeightMm}mm 无对应 Excel 纸型,打印设置回退 A4;可显式配置 paperSize`),S.a4.code)}function se(e,t,o,n){const r=typeof t.text=="string"?t.text:"";if(o!=="raw"||!Object.prototype.hasOwnProperty.call(t,"value")){b(r,e.address),e.value=r;return}const a=t.value;if(a===null||typeof a=="string"||typeof a=="boolean"||typeof a=="number"&&Number.isFinite(a)){b(a,e.address),e.value=a,t.numberFormat&&(e.numFmt=t.numberFormat);return}b(r,e.address),e.value=r,n.push(`原始单元格值无效,已保留显示文本:${e.address}`)}function le(e){const t=$(e);return t?{id:`xlsx-flow:${t.key}`,title:t.sheet,wide:!0,flow:!0}:ce(e)}function ce(e){const o=e.components.filter(n=>n.table!==void 0)[0]?.table;if(!(!o||typeof o.id!="string"||!o.id.trim()||!Array.isArray(o.columnKeys)||!o.columnKeys.length)){for(const n of e.components){if(n.table){if(!n.grid||n.table.id!==o.id)return;continue}if(n.grid||n.kind!=="text"&&!h.isImageBackedComponent(n))return}return{id:o.id,title:o.title,wide:o.layout==="wide"||e.layout==="wide"}}}function de(e,t){const o=new Set;for(const[n,r]of e.pages.entries())if(!t[n])for(const a of r.components)typeof a.table?.id=="string"&&o.add(a.table.id);return o}function C(e){return e.layout==="wide"||e.components.some(t=>t.table?.layout==="wide")}function he(e,t,o){const n=[],r=e.pages.map(le),a=de(e,r);for(const[i,s]of e.pages.entries()){const l=r[i],c=l&&!a.has(l.id),d=t==="pages"||!c?void 0:l;if(t==="continuous"&&!d)throw new Error(`page ${i+1}: continuous Excel 需要完整、单一的逻辑表来源;自由布局请使用 sheetMode: 'pages'`);const g=d!==void 0&&(t==="continuous"||d.wide);!g&&t!=="pages"&&C(s)&&o.push(`page ${i+1}: 混合或缺少逻辑表来源,已保留独立 Sheet,未猜测合并内容`);const m=n[n.length-1];g&&m?.continuous&&m.tableId===d.id?m.pages.push({page:s,index:i}):n.push({pages:[{page:s,index:i}],continuous:g,...g?{tableId:d.id,title:d.title}:{},...l?.flow?{flow:!0,title:l.title}:{}})}return n}function W(e,t,o){return!e||e.length===t.length&&e.every((n,r)=>o(n,t[r]))}function ge(e,t,o,n){const r=e.table,a=t.columns.map(l=>l.size),i=W(n.keys,r.columnKeys,(l,c)=>l===c),s=W(n.widths,a,(l,c)=>Math.abs(l-c)<=.001);if(r.columnKeys.length!==a.length||!i||!s)throw new Error(`page ${o+1}: 连续 Excel 逻辑表 ${r.id} 的列结构或列宽不一致`);if(n.keys??=r.columnKeys,n.widths??=a,r.role==="header"){if(r.rowIndex!==-1)throw new Error(`page ${o+1}: 连续 Excel 表头 rowIndex 必须为 -1`);n.headerSeen=!0}else{if(!["body","group-header","subtotal","grand-total"].includes(r.role)||r.rowIndex!==n.expectedRow)throw new Error(`page ${o+1}: 连续 Excel 逻辑行来源不连续或重复(期望 ${n.expectedRow})`);n.expectedRow+=t.rows.length}}function ue(e,t){const o={expectedRow:0,headerSeen:!1};for(const{page:n,index:r}of e.pages)for(const a of n.components){const i=t.get(a);a.table&&i&&ge(a,i,r,o)}if(!o.headerSeen)throw new Error("连续 Excel 逻辑表缺少明确表头来源")}function fe(e,t,o){let n=(e?.replace(/[\\/*?:[\]]/g," ").replace(/\s+/g," ").trim()||`Sheet${t+1}`).slice(0,31).replace(/^'+|'+$/g,"").trim()||`Sheet${t+1}`;n.toLowerCase()==="history"&&(n+=" 报表");let r=n,a=1;for(;o.has(r.toLowerCase());){const i=` (${++a})`;r=n.slice(0,31-i.length)+i}return o.add(r.toLowerCase()),r}function me(e){const t=new Set;function o(n,r,a,i){return n<=r?n:(t.has(a)||(e.push(i),t.add(a)),r)}return{column:n=>o(n,255,"column","Excel 单列宽度上限为 255 字符,超宽列已收敛至 255;单元格值完整保留,显示范围可能受限"),row:n=>o(n,409,"row","Excel 行高上限为 409pt,超高行已收敛至 409pt;单元格值完整保留,显示范围可能受限")}}async function we(e,t){const o=e.flow?ie(e.pages,e.continuous).map(i=>({comp:i,pageIndex:e.pages[0].index})):e.pages.flatMap(({page:i,index:s},l)=>i.components.filter(c=>!e.continuous||(c.pageAnchor!=="header"||l===0)&&(c.pageAnchor!=="footer"||l===e.pages.length-1)).map(c=>({comp:c,pageIndex:s}))),n=new Map;let r=1,a=0;for(const{comp:i}of o)if(i.grid){const s=h.resolveGridLayout(i.grid,i.widthMm,i.heightMm);n.set(i,s),r=Math.max(r,s.columns.length);const l=t(s.cells.length);l&&await l}else i.kind==="text"&&(a=Math.max(a,i.widthMm));if(r>16384)throw new Error("Excel 最多支持 16384 列,无法无损导出此报表");return{components:o,grids:n,columnCount:r,textWidthMm:a}}function xe(e,t,o){const{page:n,index:r}=e.pages[0],a=t!==void 0&&t!=="auto";return(e.continuous||C(n))&&!a?{}:{pageSetup:{paperSize:ae(n,t,r,o),orientation:n.pageWidthMm>n.pageHeightMm?"landscape":"portrait",fitToPage:!0,...e.continuous?{fitToWidth:1,fitToHeight:0}:{}}}}function pe(e){const t=y(e.borderColor??e.lineColor),o={style:"thin",...t?{color:{argb:t}}:{}};return{...e.borderTop!==!1?{top:o}:{},...e.borderLeft!==!1?{left:o}:{},...e.borderBottom!==!1?{bottom:o}:{},...e.borderRight!==!1?{right:o}:{}}}function Me(e,t){e.alignment={horizontal:t.align??"left",vertical:t.verticalAlign??"middle",wrapText:!0};const o=y(t.backgroundColor);o&&(e.fill={type:"pattern",pattern:"solid",fgColor:{argb:o}}),e.border=pe(t),I(e,t)}function Ee(e,t){for(const[o,n]of t.columns.entries()){const r=e.sheet.getColumn(o+1),a=e.limits.column(p.mmToExcelColumnWidth(n.size));(r.width==null||r.width<a)&&(r.width=a)}}function be(e,t,o){for(const[n,r]of t.rows.entries()){const a=e.sheet.getRow(o+n),i=e.limits.row(r.size*F);(a.height==null||a.height<i)&&(a.height=i)}}function ye(e,t,o,n){const r=Math.max(1,Math.min(t.cell.colSpan??1,o.columns.length-t.ci)),a=Math.max(1,Math.min(t.cell.rowSpan??1,o.rows.length-t.ri));(r>1||a>1)&&e.mergeCells(n+t.ri,t.ci+1,n+t.ri+a-1,t.ci+r)}async function Se(e,t,o,n){if(n+o.rows.length-1>1048576)throw new Error("Excel 最多支持 1048576 行,无法无损导出此报表");be(e,o,n);for(const r of o.cells){const a=e.sheet.getCell(n+r.ri,r.ci+1);se(a,r.cell,e.valueMode,e.warnings);const i=K(r.cell,t.style);i&&(b(i.richText.map(c=>c.text).join(""),a.address),a.value=i);const s=t.grid?.paddingMm??.5;e.dataBars(e.sheet,r,n+r.ri,s);for(const c of r.cell.children??[])h.isImageBackedComponent(c)&&!c.grid&&e.images.write(e.sheet,c,n+r.ri,{leftMm:r.xMm+s+(r.cell.indentMm??0)+c.leftMm,offsetMm:s+c.topMm});Me(a,h.resolveGridCellStyle(t.style,r.cell)),r.cell.indentMm&&(a.alignment={...a.alignment,indent:Math.min(250,Math.max(1,Math.round(r.cell.indentMm/2.5)))}),ye(e.sheet,r,o,n);const l=e.schedule();l&&await l}return n+o.rows.length}function ve(e,t,o,n){const r=Array.isArray(t.lines)&&t.lines.length>0?t.lines.join(`
4
4
  `):t.text??"",a=e.sheet.getRow(o),i=a.getCell(1);t.richParagraphs?.length||b(r,i.address),i.value=t.richParagraphs?.length?A(t.richParagraphs,t.style):r,typeof i.value=="object"&&i.value&&"richText"in i.value&&b(i.value.richText.map(l=>l.text).join(""),i.address),i.alignment={horizontal:t.style?.align??"left",vertical:t.style?.verticalAlign??"middle",wrapText:!0};const s=y(t.style?.backgroundColor);return s&&(i.fill={type:"pattern",pattern:"solid",fgColor:{argb:s}}),I(i,t.style),n>1&&e.sheet.mergeCells(o,1,o,n),a.height=e.limits.row(t.heightMm*F),o+1}function Ce(e,t,o){const n=t+o-1;e.views=[{state:"frozen",ySplit:n,xSplit:0}],e.pageSetup.printTitlesRow=`1:${n}`}async function ke(e,t,o,n){!t.grids.size&&t.textWidthMm>0&&(e.sheet.getColumn(1).width=e.limits.column(p.mmToExcelColumnWidth(t.textWidthMm)));for(const i of t.grids.values()){Ee(e,i);const s=e.schedule(i.columns.length);s&&await s}let r=1,a=!1;for(const{comp:i,pageIndex:s}of t.components){const l=o&&i.table?.role==="header";if(l&&a)continue;if(r>1048576)throw new Error("Excel 最多支持 1048576 行,无法无损导出此报表");const c=t.grids.get(i);if(c)l&&(Ce(e.sheet,r,c.rows.length),a=!0),r=await Se(e,i,c,r);else if(i.kind==="text")r=ve(e,i,r,t.columnCount);else if(h.isImageBackedComponent(i)){const d=p.importedImageOverlay(i,o),g=n.write(e.sheet,i,d?.row??r,d);d||(r=g)}else e.warnings.push(`page ${s+1} ${i.nid??i.kind}: 组件类型 ${i.kind} 暂不支持 xlsx 导出,已跳过`)}}function Be(e){if(e.maxDataBars!==void 0&&(!Number.isSafeInteger(e.maxDataBars)||e.maxDataBars<0||e.maxDataBars>1e5))throw new Error("xlsx maxDataBars 必须是 0–100000 的整数");if(e.valueMode!==void 0&&e.valueMode!=="text"&&e.valueMode!=="raw")throw new Error("xlsx valueMode 必须是 text 或 raw");if(e.paperSize!==void 0&&e.paperSize!=="auto"&&!Object.prototype.hasOwnProperty.call(S,e.paperSize))throw new Error("xlsx paperSize 必须是 auto、a3、a4 或 a5");if(e.sheetMode!==void 0&&!["auto","pages","continuous"].includes(e.sheetMode))throw new Error("xlsx sheetMode 必须是 auto、pages 或 continuous")}function Re(e,t,o){const n=H.collectOutputDiagnostics(e,"xlsx",t,o);return{diagnostics:n.entries,...t.diagnosticLimit===void 0?{}:{diagnosticSummary:n.snapshot()}}}function We(e,t,o,n,r){return{workbook:e,warnings:t.entries,...r===void 0?{}:{warningCount:t.total},...o,...n.length?{notes:n}:{}}}async function O(e,t={}){const o=R.snapshotAdditionalSheets(t.additionalSheets),n=R.snapshotSheetNames(t.sheetNames);Be(t),h.assertOutputActive(t.signal);const r=t.assetRegistry||t.assetRenderers?await q.resolvePlanAssets(e,{...t,format:"xlsx"}):{plan:e,diagnostics:[]};e=r.plan;const a=Re(e,t,r);await X(e,t.maxDataBars??1e4,t);const i=new p.ExcelJSRuntime.Workbook,s=h.createDiagnosticMessages(t.diagnosticLimit),l=Y(i,t,s),c=[],d=U(l,t.maxDataBars??1e4,c),g=me(s),m=he(e,t.sheetMode,s),u=m.length+(o?.length??0),f=new Set,E=h.createOutputScheduler(t);for(const[M,x]of m.entries()){const k=await we(x,E);x.continuous&&!x.flow&&ue(x,k.grids);const D=x.pages[0].page,B=n?.[M]??t.sheetName?.(M)??fe(x.title,M,f);f.add(B.toLowerCase());const z=i.addWorksheet(B,xe(x,t.paperSize,s)),L=t.valueMode??(C(D)||x.continuous||x.flow?"raw":"text");h.assertOutputActive(t.signal),await ke({sheet:z,warnings:s,limits:g,valueMode:L,schedule:E,images:l,dataBars:d},k,x.continuous,l),await h.outputCheckpoint(t,M+1,u)}return await Ae(i,o,t,m.length,u),We(i,s,a,c,t.diagnosticLimit)}async function Ae(e,t=[],o,n,r){const a=h.createOutputScheduler(o);for(const i of t){if(h.assertOutputActive(o.signal),e.worksheets.some(l=>l.name.toLowerCase()===i.name.toLowerCase()))throw new TypeError(`附加工作表名称已被报表使用 ${i.name}`);const s=e.addWorksheet(i.name);i.columnWidths&&(s.columns=i.columnWidths.map(l=>({width:l})));for(const l of i.rows){const c=s.addRow([...l]);c.alignment={vertical:"top",wrapText:!0};const d=a(l.length);d&&await d}await h.outputCheckpoint(o,++n,r)}h.assertOutputActive(o.signal)}async function Pe(e,t={}){let o=1;const n=t.onProgress?(i,s)=>{o=s+1,h.notifyOutputProgress(t,i,o)}:void 0,r=await O(e,{...t,onProgress:n});h.assertOutputActive(t.signal);const a=await r.workbook.xlsx.writeBuffer();return h.assertOutputActive(t.signal),h.notifyOutputProgress(t,o,o),{...r,buffer:a}}exports.importExcelTemplate=p.importExcelTemplate;exports.inspectExcelWorkbook=p.inspectExcelWorkbook;exports.openExcelWorkbook=p.openExcelWorkbook;exports.bindExcelTemplate=w.bindExcelTemplate;exports.createExcelBindingDocument=w.createExcelBindingDocument;exports.createExcelBindingSession=w.createExcelBindingSession;exports.createExcelRegionBindingDocument=w.createExcelRegionBindingDocument;exports.createExcelRegionBindingSession=w.createExcelRegionBindingSession;exports.excelBindingCellRange=w.excelBindingCellRange;exports.excelBindingRowRange=w.excelBindingRowRange;exports.getExcelSheetWindow=w.getExcelSheetWindow;exports.parseExcelBindingSession=w.parseExcelBindingSession;exports.parseExcelRegionBindingSession=w.parseExcelRegionBindingSession;exports.validateExcelBindingFields=w.validateExcelBindingFields;exports.validateExcelBindingRecipe=w.validateExcelBindingRecipe;exports.validateExcelBindingRegions=w.validateExcelBindingRegions;exports.validateExcelRegionBindings=w.validateExcelRegionBindings;exports.validateExcelRegionFields=w.validateExcelRegionFields;exports.validateExcelRegionGeometry=w.validateExcelRegionGeometry;exports.renderPlanToWorkbook=O;exports.renderPlanToXlsx=Pe;
package/dist/xlsx.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { y as v, m as b, a as W, r as R, b as T, A as M, v as U, o as F, B as A, i as C } from "./diagnostic-collector-gB07PHy2.js";
2
2
  import { e as X } from "./index-CPh6tqge.js";
3
3
  import { d as K } from "./data-bar-Bfh54sT4.js";
4
- import { e as J, E as V, m as I, i as q } from "./workbook-session-SzfILBJJ.js";
5
- import { a as et, b as tt, o as nt } from "./workbook-session-SzfILBJJ.js";
4
+ import { e as J, E as V, m as I, i as q } from "./workbook-session-B6hRjTyX.js";
5
+ import { a as et, b as tt, o as nt } from "./workbook-session-B6hRjTyX.js";
6
6
  import { c as Q } from "./media-Y90dHK9z.js";
7
7
  import { c as Y } from "./capabilities-CN_kSVjO.js";
8
8
  import { r as Z } from "./assets-C4MIvzQ4.js";
9
9
  import { s as ee, a as te } from "./workbook-sheets-D4M7XXBh.js";
10
- import { b as it, c as ot, a as at, d as st, e as lt, f as ct, g as dt, h as ht, p as ft, i as gt, v as ut, j as mt, k as wt, l as xt, m as pt, n as Mt } from "./region-binding-workflow-D8I4QWRh.js";
10
+ import { b as it, c as ot, a as at, d as st, e as lt, f as ct, g as dt, h as ht, p as ft, i as gt, v as ut, j as mt, k as wt, l as xt, m as pt, n as Mt } from "./region-binding-workflow-EYxvUYJ-.js";
11
11
  function ne(e) {
12
12
  const t = X({ width: 1, height: 1, channels: 4, depth: 8, data: new Uint8Array([1, 3, 5].map((o) => parseInt(e.slice(o, o + 2), 16)).concat(89)) });
13
13
  return `data:image/png;base64,${btoa(String.fromCharCode(...t))}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agile-team/mach-report",
3
- "version": "2.25.0",
3
+ "version": "2.25.1",
4
4
  "description": "独立的 TypeScript 报表引擎:模板分页、DOM/Canvas/PDF/Excel 输出与 Vue 3 预览组件",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -1,2 +0,0 @@
1
- "use strict";const E=require("./diagnostic-collector-wASg6Fzs.cjs"),A=require("./textwrap-LhJkHWb1.cjs"),k=require("./computed-DK6BruFz.cjs"),S=require("./record-bindings-B7djSjNs.cjs"),_e=require("./matrix-B8QWbsGM.cjs"),W=require("./template-serialization-CqQY4zDg.cjs"),H=require("./template-registry-BMScUmM4.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: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((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??"auto"),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,c.valueType):"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,m.semanticRole,m.valueType)]??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;
@@ -1 +0,0 @@
1
- "use strict";const g=require("./computed-DK6BruFz.cjs");function $(e,r){const l=()=>r.measures.map(i=>g.createAggregateAccumulator(i)),t=new Map,n=new Map,o=new Map,a=r.totals?l():void 0,s=(i,c)=>i?.forEach(u=>u.add(c));for(const i of e){const c=r.row(i),u=r.column(i);n.has(u.key)||n.set(u.key,u.label);let f=t.get(c.key);f||(f={label:c.label,cells:new Map,...r.totals?{totals:l()}:{}},t.set(c.key,f)),r.check(t.size,n.size);let d=f.cells.get(u.key);if(d||(d=l(),f.cells.set(u.key,d)),s(d,i),!r.totals)continue;let w=o.get(u.key);w||(w=l(),o.set(u.key,w)),s(f.totals,i),s(w,i),s(a,i)}return{groups:t,columns:n,columnTotals:o,totals:a}}function h(e,r){return JSON.stringify([e.slice(0,r.length),r.map(l=>[l===null?"null":typeof l,l])])}function S(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("矩阵层级标签应为字符串");k(e.row,r.length),k(e.column,l.length)}function k(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 A(e,r,l){return{fields:e,options:r??{},hierarchy:l,root:{values:[],children:new Map},leaves:0,expanded:0}}function F(e,r){const l=S(r,e.fields);let t=e.root;for(let n=1;n<=l.length;n++){const o=l.slice(0,n),a=h(e.fields,o);let s=t.children.get(a);s||(s={values:o,children:new Map},t.children.set(a,s),n===l.length?(e.leaves++,e.expanded++):e.options.subtotals?.includes(n)&&e.expanded++),t=s}}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,n)=>L(t.values[t.values.length-1],n.values[n.values.length-1])*(r==="desc"?-1:1)),l}function y(e,r,l){return{key:h(e.fields,r),kind:l,depth:r.length,fields:e.fields.slice(0,r.length),values:r,labels:r.map(t=>t===null?e.hierarchy.emptyLabel??"(空)":String(t))}}function E(e,r){const l=[];function t(n){for(const o of R(n,e.options.sort?.[n.values.length]))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"))}return t(e.root),r&&e.leaves&&l.push(y(e,[],"total")),l}function v(e,r,l){const t=S(r,e.fields),n=[h(e.fields,t),...(e.options.subtotals??[]).map(o=>h(e.fields,t.slice(0,o)))];return l&&n.push(h(e.fields,[])),n}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,n=Array.from({length:l},()=>Array(t+r.length).fill(null));for(let o=0;o<e.columnFields.length;o++){let a;r.forEach((s,i)=>{const c=z(s,o,e.hierarchy);if(!c){a=void 0;return}if(a?.key===c.key){a.cell.colSpan=(a.cell.colSpan??1)+1;return}const u={text:c.text,rowSpan:c.rowSpan||e.columnFields.length-o,editable:!1,derived:!0};n[o][t+i]=u,a={key:c.key,cell:u}})}return e.rowFields.forEach((o,a)=>{n[0][a]={text:e.hierarchy.row?.labels?.[a]??o,rowSpan:l,editable:!1,derived:!0}}),r.forEach((o,a)=>{const s=e.measures[o.measure];n[l-1][t+a]={text:s.label??`${s.field} (${s.op})`,editable:!1,derived:!0}}),{cells:n.map(o=>o.filter(a=>a!==null)),colWidthsMm:[...e.rowFields.map(()=>e.rowWidthMm??40),...r.map(()=>e.columnWidthMm??28)]}}function M(e,r,l,t){const n=+(!!r.totals&&e>0),o=l.expanded+n,a=(t.expanded+n)*r.measures.length+r.rowFields.length;if(o>(r.maxRows??1e3)||t.expanded+n>(r.maxColumns??200))throw new Error("矩阵层级展开数量超出预算(包含小计/总计)");if(o*a>(r.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算");return{rowCount:o,columnCount:a,cells:o*a}}function x(e,r){if(!Array.isArray(e)||e.length>(r.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const l=A(r.rowFields,r.hierarchy.row,r.hierarchy),t=A(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=M(0,r,l,t);for(const a of e){if(!a||typeof a!="object"||Array.isArray(a))throw new Error("矩阵数据行应为对象");F(l,a),F(t,a),o=M(e.length,r,l,t)}return{row:l,column:t,shape:o}}function j(e,r){return x(e,r).shape}function p(e,r,l){const t=new Map;for(const n of e){const o=v(l.row,n,!!r.totals),a=v(l.column,n,!!r.totals);for(const s of o){let i=t.get(s);i||(i=new Map,t.set(s,i));for(const c of a){let u=i.get(c);u||(u=r.measures.map(f=>g.createAggregateAccumulator({...f,field:f.valueField??f.field})),i.set(c,u)),u.forEach(f=>f.add(n))}}}return t}function H(e,r){return e.flatMap((l,t)=>r.measures.map((n,o)=>({...l,field:l.kind==="total"?`total_${o}`:`c${t}_${o}`,measure:o,measureField:n.field,valueField:n.valueField??n.field,operation:n.op})))}function I(e,r){return e.kind==="total"?r.hierarchy.totalLabel??"合计":[...e.labels,...e.kind==="subtotal"?[r.hierarchy.subtotalLabel??"小计"]:[]].join(" / ")}function K(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:`${I(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(n=>{const o={};l.rowFields.forEach((a,s)=>{o[`r${s}`]=n.kind==="total"?s===0?l.hierarchy.totalLabel??"合计":null:n.labels[s]??(s===n.depth?l.hierarchy.subtotalLabel??"小计":null)});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);return o})}function _(e,r){const l=x(e,r),t=E(l.row,!!r.totals),n=H(E(l.column,!!r.totals),r),o=p(e,r,l);return{columns:K(n,r),rows:T(t,n,r,o),headerGrid:O(r,n),metadata:{rowFields:[...r.rowFields],rowLabels:[...r.hierarchy.row?.labels??r.rowFields],columnFields:[...r.columnFields],columnLabels:[...r.hierarchy.column?.labels??r.columnFields],rows:t,columns:n}}}function m(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 b(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(g.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(b(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 a of e){if(!a||typeof a!="object"||Array.isArray(a))throw new Error("矩阵数据行应为对象");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))throw new Error("矩阵维度数量超出预算");if((l.size+ +!!r.totals)*((t.size+ +!!r.totals)*r.measures.length+1)>(r.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算")}const n=l.size+ +(!!r.totals&&e.length>0),o=(t.size+ +!!r.totals)*r.measures.length+1;return{rowCount:n,columnCount:o,cells:n*o}}function P(e,r){if(r?.hierarchy)return b(r),_(e,r);C(e,r);const l=$(e,{row:a=>m(a,r.rowFields),column:a=>m(a,r.columnFields),measures:r.measures.map(a=>({...a,field:a.valueField??a.field})),totals:r.totals,check:()=>{}}),t=[...l.groups.values()].map(a=>({rowLabel:a.label})),n=[{field:"rowLabel",header:r.rowHeader??r.rowFields.join(" / "),semanticRole:"dimension"}],o={rowLabel:"合计"};return r.measures.forEach((a,s)=>{const i=[...l.columns.entries()].map(([c,u],f)=>({key:c,label:u,field:`c${f}_${s}`}));r.totals&&i.push({key:"",label:"合计",field:`total_${s}`});for(const c of i){const u=c.field===`total_${s}`;n.push({field:c.field,header:`${c.label} · ${a.label??`${a.field} (${a.op})`}`,semanticRole:"measure",...a.digits===void 0?{}:{format:{kind:"number",digits:a.digits}}});let f=0;for(const d of l.groups.values())t[f++][c.field]=(u?d.totals?.[s]:d.cells.get(c.key)?.[s])?.value()??(a.op==="count"?0:null);o[c.field]=(u?l.totals?.[s]:l.columnTotals.get(c.key)?.[s])?.value()??(a.op==="count"?0:null)}}),r.totals&&e.length&&t.push(o),{rows:t,columns:n}}exports.accumulatePivotRows=$;exports.createMatrixTable=P;exports.estimateMatrixTable=C;exports.validateMatrixOptions=b;
@@ -1 +0,0 @@
1
- "use strict";const P=require("./computed-DK6BruFz.cjs"),re=require("./matrix-B8QWbsGM.cjs"),k=require("./diagnostic-collector-wASg6Fzs.cjs"),fe=require("./code-options-BUTChiZZ.cjs"),G=require("./param-validation-C-8sRJLq.cjs"),w=require("./template-serialization-CqQY4zDg.cjs");function de(e,i,t){e!==void 0&&(typeof e!="string"||!e.trim()||e.length>4096)&&t.push({path:i,message:"来源范围应为不超过 4096 字符的非空字符串"})}function U(e,i,t){e.editable!==void 0&&typeof e.editable!="boolean"&&t.push({path:`${i}.editable`,message:"编辑控制应为布尔值"}),e.valueType!==void 0&&!["text","number","boolean"].includes(e.valueType)&&t.push({path:`${i}.valueType`,message:"编辑类型应为 text、number 或 boolean"})}function ce(e,i,t){U(e,i,t),e.indentMm!==void 0&&(typeof e.indentMm!="number"||!Number.isFinite(e.indentMm)||e.indentMm<0)&&t.push({path:`${i}.indentMm`,message:"单元格缩进应为有限非负数"}),e.derived!==void 0&&typeof e.derived!="boolean"&&t.push({path:`${i}.derived`,message:"派生结果标记应为布尔值"}),z(e.source,`${i}.source`,t,!0),e.formula!==void 0&&typeof e.formula!="string"&&t.push({path:`${i}.formula`,message:"单元格公式应为字符串"})}function z(e,i,t,s=!1){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)){t.push({path:i,message:"业务来源应为对象"});return}const n=e;de(n.sourceScope,`${i}.sourceScope`,t);for(const a of["datasetId",...s?["field"]:[]])(typeof n[a]!="string"||!n[a].trim())&&t.push({path:`${i}.${a}`,message:"业务标识应为非空字符串"});for(const a of["rowKey","revision"]){const o=n[a];o===void 0&&!(s&&a==="rowKey")||typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o))&&t.push({path:`${i}.${a}`,message:"业务键及修订号应为字符串或有限数字"})}n.sourceToken!==void 0&&typeof n.sourceToken!="string"&&t.push({path:`${i}.sourceToken`,message:"来源令牌应为字符串"})}const ue=new Set(["text","image","barcode","qrcode","chart","line","rect","ellipse"]);function p(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function R(e){return e===null?"null":typeof e=="string"?JSON.stringify(e.slice(0,120)):["number","boolean","undefined"].includes(typeof e)?String(e):`[${typeof e}]`}function he(e,i,t,s){const n=e[i];(typeof n!="number"||!Number.isFinite(n))&&s.push({path:`${t}.${i}`,message:`应为有限数字,实际 ${R(n)}`})}function me(e,i,t){if(e!==void 0){const s=`${i}.table`;if(!p(e))t.push({path:s,message:"逻辑表来源应为对象"});else{z(e.source,`${s}.source`,t),(typeof e.id!="string"||!e.id.trim())&&t.push({path:`${s}.id`,message:"逻辑表 ID 应为非空字符串"});const n=e.role;["header","body","group-header","subtotal","grand-total"].includes(n)||t.push({path:`${s}.role`,message:"未知逻辑表行角色"});const a=e.rowIndex;(typeof a!="number"||!Number.isInteger(a)||(n==="header"?a!==-1:a<0))&&t.push({path:`${s}.rowIndex`,message:"表头索引应为 -1,内容行索引应为非负整数"}),(!Array.isArray(e.columnKeys)||e.columnKeys.some(o=>typeof o!="string"))&&t.push({path:`${s}.columnKeys`,message:"逻辑列字段应为字符串数组"}),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&t.push({path:`${s}.layout`,message:"布局应为 page 或 wide"}),e.title!==void 0&&typeof e.title!="string"&&t.push({path:`${s}.title`,message:"逻辑表名称应为字符串"})}}}function ge(e,i,t,s){if(e!==void 0)if(!p(e)||!Array.isArray(e.cells))t.push({path:`${i}.grid.cells`,message:"grid.cells 应为二维数组"});else{const n=e.paddingMm;n!==void 0&&(typeof n!="number"||!Number.isFinite(n)||n<0)&&t.push({path:`${i}.grid.paddingMm`,message:"单元格内距应为有限非负数"}),e.cells.forEach((a,o)=>{if(!Array.isArray(a)){t.push({path:`${i}.grid.cells.${o}`,message:"行应为数组"});return}a.forEach((r,f)=>{if(r==null)return;const d=`${i}.grid.cells.${o}.${f}`;if(!p(r)){t.push({path:d,message:"网格单元格应为对象或 null"});return}ce(r,d,t),r.dataBar!==void 0&&!k.validDataBar(r.dataBar)&&t.push({path:`${d}.dataBar`,message:"数据条应包含 0–1 有序比例与 #RRGGBB 颜色"}),q(r.richParagraphs,d,t),Array.isArray(r.children)&&r.children.forEach((c,m)=>{B(c,`${i}.grid.cells.${o}.${f}.children.${m}`,t,s)})})})}}function T(e,i,t,s){e!==void 0&&!i.includes(e)&&s.push({path:t,message:"未知富文本属性值"})}function O(e,i,t,s,n=0){for(const a of i){const o=e[a];o!==void 0&&(typeof o!="number"||!Number.isFinite(o)||o<n)&&s.push({path:`${t}.${a}`,message:"富文本数值应为范围内有限数字"})}}function pe(e,i,t){if(e!==void 0){if(!p(e)){t.push({path:i,message:"富文本样式应为对象"});return}for(const s of["fontFamily","color","backgroundColor","lineColor","borderColor"])e[s]!==void 0&&typeof e[s]!="string"&&t.push({path:`${i}.${s}`,message:"富文本样式应为字符串"});for(const s of["bold","italic","underline","borderTop","borderRight","borderBottom","borderLeft"])e[s]!==void 0&&typeof e[s]!="boolean"&&t.push({path:`${i}.${s}`,message:"富文本样式应为布尔值"});O(e,["fontSize","fontSizePx","lineWidthPt","lineHeight","opacity"],i,t),O(e,["letterSpacing","rotateDeg"],i,t,-1/0),typeof e.opacity=="number"&&e.opacity>1&&t.push({path:`${i}.opacity`,message:"透明度不能大于1"}),T(e.align,["left","center","right","justify"],`${i}.align`,t),T(e.verticalAlign,["top","middle","bottom"],`${i}.verticalAlign`,t)}}function le(e,i,t){if(!p(e)){t.push({path:i,message:"富文本片段应为对象"});return}T(e.kind,["text","field"],`${i}.kind`,t);for(const s of["text","field"])e[s]!==void 0&&typeof e[s]!="string"&&t.push({path:`${i}.${s}`,message:"富文本内容应为字符串"});pe(e.style,`${i}.style`,t)}function q(e,i,t){if(e!==void 0){if(!Array.isArray(e)){t.push({path:`${i}.richParagraphs`,message:"richParagraphs 应为数组"});return}e.forEach((s,n)=>{const a=`${i}.richParagraphs.${n}`;if(!p(s)||!Array.isArray(s.segments)){t.push({path:a,message:"段落缺少 segments 数组"});return}T(s.align,["left","center","right","justify"],`${a}.align`,t),O(s,["lineHeight","spaceBeforeMm","spaceAfterMm","indentMm"],a,t),s.segments.forEach((o,r)=>le(o,`${a}.segments.${r}`,t))})}}function D(e,i,t,s=[]){const n=k.componentTreeIssue([e],i);if(n){t.push(n);return}B(e,i,t,s)}function B(e,i,t,s=[]){if(!p(e)){t.push({path:i,message:"组件应为对象"});return}const n=e.kind;typeof n!="string"?t.push({path:`${i}.kind`,message:"组件缺少 kind 字符串"}):ue.has(n)||s.push({path:`${i}.kind`,message:`未知组件类型 ${R(n)},将以兜底方式渲染`});for(const a of["leftMm","topMm","widthMm","heightMm"])he(e,a,i,t);typeof e.leftMm=="number"&&e.leftMm<-100&&t.push({path:`${i}.leftMm`,message:"几何数值异常(leftMm<-100)"});for(const a of["widthMm","heightMm"])typeof e[a]=="number"&&e[a]<0&&t.push({path:`${i}.${a}`,message:"组件尺寸不能为负数"});me(e.table,i,t),$e(e.code,n,i,t),ye(e,i,t),e.pageAnchor!==void 0&&!["header","footer"].includes(e.pageAnchor)&&t.push({path:`${i}.pageAnchor`,message:"页面锚点应为 header 或 footer"}),e.lineDirection!==void 0&&!["down","up"].includes(e.lineDirection)&&t.push({path:`${i}.lineDirection`,message:"线段方向应为 down 或 up"}),ge(e.grid,i,t,s),q(e.richParagraphs,i,t)}function ye(e,i,t){if(e.chartBinding!==void 0)try{if(P.validateReportChartBinding(e.chartBinding),e.kind!=="chart"||["binding","imageData","grid","pageAnchor"].some(s=>e[s]!==void 0))throw new Error("绑定图表不能设置图片、网格、记录绑定或页眉页脚");if(typeof e.widthMm!="number"||e.widthMm<45||typeof e.heightMm!="number"||e.heightMm<35)throw new Error("绑定图表至少需要 45×35mm")}catch(s){t.push({path:`${i}.chartBinding`,message:s instanceof Error?s.message:String(s)})}}function $e(e,i,t,s){if(e!==void 0)for(const n of fe.codeOptionIssues(e,i))s.push({path:`${t}.code${n.path?`.${n.path}`:""}`,message:n.message})}function X(e,i,t){if(!p(e))return;e.binding!==void 0&&t.push({path:`${i}.binding`,message:"渲染计划不允许未解析字段绑定"}),e.chartBinding!==void 0&&t.push({path:`${i}.chartBinding`,message:"渲染计划不允许未解析图表绑定"});const s=e.grid;!p(s)||!Array.isArray(s.cells)||s.cells.forEach((n,a)=>{Array.isArray(n)&&n.forEach((o,r)=>{!p(o)||!Array.isArray(o.children)||o.children.forEach((f,d)=>X(f,`${i}.grid.cells.${a}.${r}.children.${d}`,t))})})}function Y(e,i,t,s=[]){if(!p(e)){t.push({path:i,message:"页应为对象"});return}const n=e.pageWidthMm,a=e.pageHeightMm;(typeof n!="number"||!Number.isFinite(n)||n<=0)&&t.push({path:`${i}.pageWidthMm`,message:`页宽非法: ${R(n)}`}),(typeof a!="number"||!(a>0&&a<5e3))&&t.push({path:`${i}.pageHeightMm`,message:`页高非法: ${R(a)}`}),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&t.push({path:`${i}.layout`,message:"布局应为 page 或 wide"});const o=e.components;if(!Array.isArray(o))t.push({path:`${i}.components`,message:"components 应为数组"});else if(Array.isArray(o)){const r=k.componentTreeIssue(o,`${i}.components`);if(r){t.push(r);return}o.forEach((f,d)=>{B(f,`${i}.components.${d}`,t,s),X(f,`${i}.components.${d}`,t)})}}function Q(e){const i=[],t=[],s=p(e)?e.pages:void 0;if(p(e)&&e.requiresRecalculation!==void 0&&typeof e.requiresRecalculation!="boolean"&&i.push({path:"$.requiresRecalculation",message:"重算能力要求应为布尔值"}),!Array.isArray(s))i.push({path:"$.pages",message:e==null?"渲染计划为空":"渲染计划缺少 pages 数组"});else{const n=k.renderTreeIssue(s);if(n)return{ok:!1,errors:[...i,n],warnings:t};s.forEach((o,r)=>Y(o,`$.pages.${r}`,i,t)),s.length>2e3&&t.push({path:"$.pages",message:`页数异常大(${s.length} 页),渲染与打印耗时可能显著增加`});const a=s.reduce((o,r)=>o+(p(r)&&Array.isArray(r.components)?r.components.length:0),0);a>5e4&&t.push({path:"$.pages",message:`组件总数异常大(${a} 个),可能触发浏览器性能限制`})}return{ok:i.length===0,errors:i,warnings:t}}function be(e){const i=Q(e);if(!i.ok){const t=i.errors.slice(0,3).map(s=>`${s.path}: ${s.message}`).join("; ");throw new Error(`渲染计划校验失败(${i.errors.length} 处): ${t}`)}return e.pages}function V(e){return e.kind==="list"?e.id:e.nid}function Ae(e){return e.kind==="list"?!1:e.pageAnchor!==void 0||e.kind==="text"&&typeof e.text=="string"&&/\{(?:page|totalPages)\}/.test(e.text)}function we(e,i){const t=e.filter(n=>i.componentIds.includes(V(n)??""));if(t.filter(n=>n.kind==="list"&&n.cardinality!=="record").length&&t.length!==1)throw new Error("纵向重复区域必须独占流式分段,不能与静态或单记录区域并排");for(const n of t){const a=n.kind==="list"?n.topMm+(n.rowHeightMm??0):n.topMm+n.heightMm;if(n.topMm<i.topMm-.001||a>i.topMm+i.heightMm+.001)throw new Error("流式分段应完整包含其组件的原始纵向范围")}}function Me(e,i){if(!i)return e.map(s=>({components:[s]}));const t=new Map(e.map(s=>[V(s),s]));return i.bands.map(s=>({band:s,components:s.componentIds.map(n=>{const a=t.get(n);if(!a)throw new Error(`流式区域引用不存在的组件:${n}`);return a})}))}function Z(e,i){if(!i||!Array.isArray(i.bands)||!i.bands.length||i.bands.length>1e4)throw new Error("流式排版应包含 1–10000 个区域");const t=new Set,s=new Set;for(const n of e){if(Ae(n))continue;const a=V(n);if(!a||t.has(a))throw new Error("流式排版组件应具有唯一标识");t.add(a)}if(Ee(e,i,t,s),s.size!==t.size)throw new Error("流式排版必须显式包含每个非锚点组件")}function Ee(e,i,t,s){let n=-1/0;for(const a of i.bands){if(!Number.isFinite(a.topMm)||!Number.isFinite(a.heightMm)||a.topMm<0||a.heightMm<=0||a.topMm<n-.001)throw new Error("流式区域应按原始位置排序,尺寸有效且不重叠");if(!Array.isArray(a.componentIds)||!a.componentIds.length)throw new Error("流式区域不能没有组件");for(const o of a.componentIds){if(!t.has(o)||s.has(o))throw new Error(`流式区域组件缺失、重复或包含页锚点:${o}`);s.add(o)}we(e,a),n=a.topMm+a.heightMm}}const ke=new Set(["__proto__","prototype","constructor"]);function $(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function S(e){return typeof e=="string"&&!!e.trim()&&!ke.has(e)}function x(e,i,t,s){for(const n of Object.keys(e))i.includes(n)||s.push({path:`${t}.${n}`,message:"存在未知配置字段"})}function Se(e,i,t){if(e!==void 0){if(!$(e)||!["number","percent","date"].includes(String(e.kind))){t.push({path:i,message:"绑定格式应为 number、percent 或 date"});return}x(e,e.kind==="date"?["kind","pattern"]:e.kind==="number"?["kind","digits","thousands"]:["kind","digits"],i,t),e.digits!==void 0&&(!Number.isInteger(e.digits)||Number(e.digits)<0||Number(e.digits)>100)&&t.push({path:`${i}.digits`,message:"精度应为 0..100 整数"}),e.thousands!==void 0&&typeof e.thousands!="boolean"&&t.push({path:`${i}.thousands`,message:"千分位开关应为布尔值"}),e.pattern!==void 0&&typeof e.pattern!="string"&&t.push({path:`${i}.pattern`,message:"日期格式应为字符串"})}}function ve(e,i,t){const s=e.binding;if(s===void 0)return;const n=`${i}.binding`;if(!$(s)){t.push({path:n,message:"字段绑定应为对象"});return}(!["text","image","barcode","qrcode"].includes(String(e.kind))||e.grid!==void 0)&&t.push({path:n,message:"绑定仅支持独立文本、图片、条码与二维码组件"}),x(s,["field","format","prefix","suffix","emptyText"],n,t),S(s.field)||t.push({path:`${n}.field`,message:"绑定字段应为安全的非空字段名(按字面读取自有字段)"});for(const a of["prefix","suffix","emptyText"])s[a]!==void 0&&typeof s[a]!="string"&&t.push({path:`${n}.${a}`,message:"应为字符串"});Se(s.format,`${n}.format`,t),e.kind==="image"&&["format","prefix","suffix"].some(a=>s[a]!==void 0)&&t.push({path:n,message:"图片绑定直接读取 PNG/JPEG data URL,不支持文本格式或前后缀"})}function Ne(e,i){if(!$(e)){i.push({path:"$.repeat",message:"逐记录配置应为对象"});return}x(e,["dataset","rowKey","copies"],"$.repeat",i),S(e.dataset)||i.push({path:"$.repeat.dataset",message:"数据集应为安全的非空名称"}),e.rowKey!==void 0&&!S(e.rowKey)&&i.push({path:"$.repeat.rowKey",message:"业务主键应为安全的非空字段名"});const t=e.copies;t!==void 0&&($(t)?(x(t,["field"],"$.repeat.copies",i),S(t.field)||i.push({path:"$.repeat.copies.field",message:"复制数字段应为安全的非空字段名"})):(!Number.isSafeInteger(t)||Number(t)<1||Number(t)>1e3)&&i.push({path:"$.repeat.copies",message:"每条记录复制数应为 1..1000 整数"}))}function ee(e,i,t,s){if(!$(e))return;ve(e,i,s),e.binding!==void 0&&!t&&s.push({path:`${i}.binding`,message:"字段绑定需要模板 repeat 数据集;普通报表请使用列表字段"}),t&&e.kind==="list"&&s.push({path:i,message:"逐记录标签使用固定组件;动态列表请使用普通报表模板"}),e.chartBinding!==void 0&&(t||i.includes(".children."))&&s.push({path:`${i}.chartBinding`,message:"数据图表应放在普通报表的页面或流式分区,不放在逐记录标签或嵌套单元格内"});const n=e.grid;$(n)&&Array.isArray(n.cells)&&n.cells.forEach((a,o)=>{Array.isArray(a)&&a.forEach((r,f)=>{$(r)&&Array.isArray(r.children)&&r.children.forEach((d,c)=>ee(d,`${i}.grid.cells.${o}.${f}.children.${c}`,t,s))})})}function te(e,i){const t=e.repeat!==void 0;t&&Ne(e.repeat,i),Array.isArray(e.pages)&&e.pages.forEach((s,n)=>{if(!$(s))return;const a=`$.pages.${n}`;t&&(s.layout==="wide"||s.flow!==void 0)&&i.push({path:a,message:"逐记录标签仅支持固定尺寸页面,不支持宽表或流式分区"}),Array.isArray(s.components)&&s.components.forEach((o,r)=>{const f=`${a}.components.${r}`;if(ee(o,f,t,i),!t||!$(o))return;const{leftMm:d,topMm:c,widthMm:m,heightMm:l}=o;[d,c,m,l,s.widthMm,s.heightMm].every(y=>typeof y=="number"&&Number.isFinite(y))&&(Number(d)<0||Number(c)<0||Number(d)+Number(m)>Number(s.widthMm)+.001||Number(c)+Number(l)>Number(s.heightMm)+.001)&&i.push({path:f,message:"标签组件超出纸张边界,请调整位置或尺寸"})})})}function Re(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function _(e,i,t){if(e!==void 0)try{P.compileReportPredicate(e)}catch(s){t.push({path:i,message:s instanceof Error?s.message:String(s)})}}function ie(e,i,t){if(e===void 0)return;if(!Array.isArray(e)||e.length>2048){t.push({path:i,message:"聚合应为数组且最多 2048 项"});return}const s=new Set;e.forEach((n,a)=>{const o=`${i}.${a}`;if(!Re(n)){t.push({path:o,message:"聚合应为对象"});return}const r=n.field;typeof r!="string"||!r.trim()||s.has(r)?t.push({path:`${o}.field`,message:"聚合输出字段应非空且唯一"}):s.add(r),n.numeric!==void 0&&n.numeric!=="number"&&n.numeric!=="decimal"&&t.push({path:`${o}.numeric`,message:"数值模式应为 number 或 decimal"}),n.digits!==void 0&&(!Number.isInteger(n.digits)||Number(n.digits)<0||Number(n.digits)>100)&&t.push({path:`${o}.digits`,message:"小数位应为 0–100 的整数"});try{P.createAggregateAccumulator({...n,field:n.valueField??r})}catch(f){t.push({path:o,message:f instanceof Error?f.message:String(f)})}})}function Te(e,i,t){if(e===void 0)return;const s=P.validateComputedFields(e);for(const n of s.errors)t.push({path:i,message:n})}function xe(e,i,t){if(e!==void 0)try{re.validateMatrixOptions(e)}catch(s){t.push({path:i,message:s instanceof Error?s.message:String(s)})}}function Ce(e,i,t){if(e.tree===void 0)return;const s=`${i}.tree`;try{w.validateTreeOptions(e.tree);const n=e.tree;if(e.matrix||e.detail||e.groupBy||Array.isArray(e.groups)&&e.groups.length||e.rowVisibleWhen)throw new Error("树形布局不能同时配置普通分组、矩阵、主从或行可见条件");if(e.rowKey!==void 0&&e.rowKey!==n.idField)throw new Error("树形 rowKey 应与 idField 一致");if(!Array.isArray(e.columns)||!e.columns.some(a=>a&&a.field===n.labelField&&!a.hidden))throw new Error("树形布局需要可见的标签列");Array.isArray(e.computed)&&w.validateTreeComputed(n,e.computed)}catch(n){t.push({path:s,message:n instanceof Error?n.message:String(n)})}}const Pe=new Set(["__proto__","prototype","constructor"]),Fe=new Set(["text","number","boolean","date","decimal"]);function v(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function I(e){return typeof e=="string"&&!!e.trim()&&e.length<=4096&&!Pe.has(e)}function Oe(e,i,t){if(!Array.isArray(e)||!e.length||e.length>2048){t.push({path:i,message:"绑定契约应包含 1–2048 个字段"});return}const s=new Set;e.forEach((n,a)=>{const o=`${i}.${a}`;if(!v(n)||!I(n.field)||s.has(n.field)){t.push({path:o,message:"字段名应安全、非空且唯一"});return}s.add(n.field);for(const r of["label","semanticKey","unit"])n[r]!==void 0&&(typeof n[r]!="string"||String(n[r]).length>4096)&&t.push({path:`${o}.${r}`,message:"应为不超过 4096 位的字符串"});n.type!==void 0&&!Fe.has(String(n.type))&&t.push({path:`${o}.type`,message:"未知绑定字段类型"})})}function L(e,i,t){if(e===void 0)return;if(!v(e)||!v(e.datasets)){t.push({path:i,message:"模板数据契约应声明 datasets"});return}e.source!==void 0&&!I(e.source)&&t.push({path:`${i}.source`,message:"来源应为安全的非空业务标识"});const s=Object.entries(e.datasets);(!s.length||s.length>256)&&t.push({path:`${i}.datasets`,message:"应声明 1–256 个数据集"});for(const[n,a]of s){const o=`${i}.datasets.${n}`;!I(n)||!v(a)?t.push({path:o,message:"数据集应使用安全名称和字段契约"}):Oe(a.fields,`${o}.fields`,t)}}function J(e,i){return new Map(e.datasets[i]?.fields.map(t=>[t.field,t])??[])}function _e(e,i,t,s){const n=e.label||e.field;for(const[a,o,r]of[["semanticKey","semantic","业务含义"],["type","type","类型"],["unit","unit","单位"]])e[a]!==i[a]&&(e[a]!==void 0||i[a]!==void 0)&&s.push({...t,code:o,message:`字段“${n}”的${r}不兼容(${e[a]??"未声明"} → ${i[a]??"未声明"}),请重新绑定`})}function Ie(e,i){const t=[],s=[];if(L(i,"$.target",s),L(e.dataContract,"$.template.dataContract",s),s.length)return{ok:!1,issues:s.map(o=>({...o,code:"contract"}))};const n=e.dataContract;if(!n)return{ok:!1,issues:[{code:"contract",path:"$.template.dataContract",message:"模板未声明数据来源,请核对业务字段并重新绑定"}]};n.source!==i.source&&t.push({code:"source",path:"$.template.dataContract.source",message:`模板来源与当前报表不一致(${n.source??"未声明"} → ${i.source??"未声明"}),请从当前报表创建或重新绑定模板`});const a=new Set;for(const o of w.collectTemplateDatasetBindings(e)){const r=J(n,o.dataset),f=J(i,o.dataset);if(!r.size||!f.size){t.push({code:"dataset",dataset:o.dataset,path:o.path,message:`数据集“${o.dataset}”缺少来源或目标字段契约`});continue}for(const d of o.fields){if(o.generated.has(d.field)||d.summary&&o.summaries.has(d.field))continue;const c=`${o.dataset}\0${d.field}`;if(a.has(c))continue;a.add(c);const m=r.get(d.field),l=f.get(d.field),y={...d,dataset:o.dataset};!m||!l?t.push({...y,code:"field",message:`数据集“${o.dataset}”的字段“${d.field}”未声明,请重新绑定`}):_e(m,l,y,t)}}return{ok:t.length===0,issues:t}}const j="1.0";class M extends Error{constructor(i){super(`模板校验失败:${i.slice(0,3).map(t=>`${t.path}: ${t.message}`).join("; ")}`),this.errors=i,this.name="ReportTemplateError"}}const Le=new Set(["__proto__","prototype","constructor"]),De=new Set(["schemaVersion","id","name","revision","description","template"]),Be=new Set(["left","center","right","justify"]),N=2e5,Ve=64;function u(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function je(e,i,t){const s=Object.getPrototypeOf(e),n=Array.isArray(e);if(n?s!==Array.prototype:s!==Object.prototype&&s!==null)return t.push({path:i,message:"模板对象必须使用普通 JSON 对象原型"}),!1;if(n){const a=Object.keys(e);if(a.length!==e.length||a.some(o=>!/^(0|[1-9]\d*)$/.test(o)||Number(o)>=e.length))return t.push({path:i,message:"模板数组不能包含空位或额外属性"}),!1}return Object.getOwnPropertySymbols(e).length>0?(t.push({path:i,message:"模板不能包含 Symbol 键"}),!1):!0}function Ke(e,i,t,s){return Le.has(e)?(s.push({path:t,message:"模板不能包含可能污染原型的键"}),!1):i.get||i.set||!i.enumerable?(s.push({path:t,message:"模板不能包含访问器或不可枚举字段"}),!1):!0}function He(e){return e===null||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)}function K(e,i){const t=new Set;let s=0,n=0,a=!1;const o=(r,f,d)=>{if(!a){if(++s>N){s===N+1&&i.push({path:f,message:"模板超过 JSON 节点安全上限"});return}if(d>Ve){i.push({path:f,message:"模板嵌套层级过深"});return}if(typeof r=="string"){n+=r.length,n>w.MAX_TEMPLATE_JSON_CHARACTERS&&(a=!0,i.push({path:f,message:"模板文本超过 1000 万字符的安全上限"}));return}if(!He(r)){if(!r||typeof r!="object"){i.push({path:f,message:"模板只允许 JSON 值,不允许函数、undefined 或非有限数字"});return}if(t.has(r)){i.push({path:f,message:"模板不能包含循环引用"});return}if(je(r,f,i)){t.add(r);for(const[c,m]of Object.entries(Object.getOwnPropertyDescriptors(r))){if(Array.isArray(r)&&c==="length")continue;const l=`${f}.${c}`;if(Ke(c,m,l,i)&&o(m.value,l,d+1),s>N||a)break}t.delete(r)}}}};o(e,"$",0)}function h(e,i,t,s,n=!1){const a=e[i];a===void 0&&!n||(typeof a!="string"||n&&!a.trim())&&s.push({path:`${t}.${i}`,message:n?"应为非空字符串":"应为字符串"})}function g(e,i,t,s,n=0,a=!1){const o=e[i];o===void 0&&!a||(typeof o!="number"||!Number.isFinite(o)||o<n)&&s.push({path:`${t}.${i}`,message:`应为大于等于 ${n} 的有限数字`})}function A(e,i,t,s){e[i]!==void 0&&typeof e[i]!="boolean"&&s.push({path:`${t}.${i}`,message:"应为布尔值"})}function E(e,i,t,s=!1){e!==void 0&&!Be.has(e)&&!(s&&e==="auto")&&t.push({path:i,message:`未知对齐方式${s?"(支持 auto)":""}`})}function b(e,i,t){if(e!==void 0){if(!u(e)){t.push({path:i,message:"样式应为对象"});return}E(e.align,`${i}.align`,t),e.verticalAlign!==void 0&&!["top","middle","bottom"].includes(e.verticalAlign)&&t.push({path:`${i}.verticalAlign`,message:"未知垂直对齐方式"});for(const s of["fontSize","fontSizePx","lineWidthPt","lineHeight"])g(e,s,i,t);for(const s of["letterSpacing","rotateDeg"])g(e,s,i,t,-1/0);g(e,"opacity",i,t),typeof e.opacity=="number"&&e.opacity>1&&t.push({path:`${i}.opacity`,message:"透明度不能大于 1"});for(const s of["bold","italic","underline","borderTop","borderRight","borderBottom","borderLeft"])A(e,s,i,t);for(const s of["fontFamily","color","backgroundColor","lineColor","borderColor"])h(e,s,i,t)}}function Je(e,i,t){if(e===void 0)return;if(!Array.isArray(e)){t.push({path:i,message:"参数定义应为数组"});return}const s=new Set,n=t.length;e.forEach((a,o)=>{const r=`${i}.${o}`;if(!u(a)){t.push({path:r,message:"参数定义应为对象"});return}h(a,"field",r,t,!0),typeof a.field=="string"&&(s.has(a.field)&&t.push({path:`${r}.field`,message:"参数名重复"}),s.add(a.field)),a.type!==void 0&&!["text","number","date","month","year","dateRange","select","multiSelect","cascader","numberRange"].includes(a.type)&&t.push({path:`${r}.type`,message:"未知参数类型"});for(const f of["label","defaultValue","placeholder"])h(a,f,r,t);A(a,"required",r,t);for(const f of["minLength","maxLength"]){const d=a[f];d!==void 0&&(typeof d!="number"||!Number.isSafeInteger(d)||d<0)&&t.push({path:`${r}.${f}`,message:"长度边界应为非负整数"})}We(a,r,t),a.options!==void 0&&(Array.isArray(a.options)?a.options.forEach((f,d)=>{const c=`${r}.options.${d}`;if(!u(f))t.push({path:c,message:"选项应为对象"});else for(const m of["label","value"])typeof f[m]!="string"&&t.push({path:`${c}.${m}`,message:"选项标签与值应为字符串(允许空白选项)"})}):t.push({path:`${r}.options`,message:"选项应为数组"}))}),t.length===n&&t.push(...G.validateReportParamDefinitions(e).map(a=>({path:a.path.replace("$.paramDefs",i),message:a.message})))}function We(e,i,t){for(const a of["min","max"]){const o=e[a];if(o===void 0)continue;G.isReportTemporalBound(e.type,o)||["number","numberRange"].includes(e.type)&&typeof o=="number"&&Number.isFinite(o)||t.push({path:`${i}.${a}`,message:"数字使用有限数字边界,日期/月/年使用对应规范字符串边界"})}const s=typeof e.min=="number"&&typeof e.max=="number"&&e.min>e.max,n=typeof e.min=="string"&&typeof e.max=="string"&&e.min>e.max;(s||n)&&t.push({path:i,message:"最小边界不能大于最大边界"}),typeof e.minLength=="number"&&typeof e.maxLength=="number"&&e.minLength>e.maxLength&&t.push({path:i,message:"最小长度不能大于最大长度"})}function se(e,i,t){if(!Array.isArray(e)||e.length===0){t.push({path:i,message:"列表至少需要一列"});return}e.every(s=>u(s)&&s.hidden===!0)&&t.push({path:i,message:"列表至少需要一列可见列"}),e.forEach((s,n)=>{const a=`${i}.${n}`;if(!u(s)){t.push({path:a,message:"列应为对象"});return}if(U(s,a,t),s.visual!==void 0&&!w.validColumnVisual(s.visual)&&t.push({path:`${a}.visual`,message:"列可视化配置无效,请检查类型、数值范围和颜色"}),A(s,"hidden",a,t),_(s.visibleWhen,`${a}.visibleWhen`,t),typeof s.header!="string"&&t.push({path:`${a}.header`,message:"表头应为字符串(允许空白表头)"}),h(s,"field",a,t,!0),g(s,"widthMm",a,t,Number.MIN_VALUE,!0),b(s.style,`${a}.style`,t),b(s.headerStyle,`${a}.headerStyle`,t),E(s.align,`${a}.align`,t,!0),E(s.headerAlign,`${a}.headerAlign`,t),s.semanticRole!==void 0&&!["identifier","dimension","measure","date","text"].includes(s.semanticRole)&&t.push({path:`${a}.semanticRole`,message:"未知列语义"}),s.format!==void 0)if(!u(s.format)||!["number","percent","date"].includes(s.format.kind))t.push({path:`${a}.format`,message:"未知列格式"});else{const o=s.format.digits;o!==void 0&&(typeof o!="number"||!Number.isInteger(o)||o<0||o>100)&&t.push({path:`${a}.format.digits`,message:"小数位应为 0–100 的整数"}),A(s.format,"thousands",`${a}.format`,t),h(s.format,"pattern",`${a}.format`,t)}s.rules!==void 0&&(Array.isArray(s.rules)?s.rules.forEach((o,r)=>{const f=`${a}.rules.${r}`;if(!u(o)||!u(o.when)){t.push({path:f,message:"条件格式缺少 when 对象"});return}_(o.when,`${f}.when`,t),b(o.style,`${f}.style`,t)}):t.push({path:`${a}.rules`,message:"条件格式应为数组"}))})}function ne(e,i,t){if(e!==void 0){if(!u(e)){t.push({path:i,message:"分组应为对象"});return}h(e,"field",i,t,!0);for(const s of["headerTemplate","subtotalLabel"])h(e,s,i,t);for(const s of["headerStyle","subtotalStyle"])b(e[s],`${i}.${s}`,t);A(e,"keepWithNext",i,t),A(e,"repeatHeader",i,t),ie(e.aggregates,`${i}.aggregates`,t),e.subtotal!==void 0&&(!Array.isArray(e.subtotal)||e.subtotal.some(s=>typeof s!="string"))&&t.push({path:`${i}.subtotal`,message:"小计字段应为字符串数组"})}}function Ge(e,i,t){if(!(e===void 0||typeof e=="boolean")){if(!u(e)){t.push({path:i,message:"合计应为布尔值或对象"});return}h(e,"label",i,t),ie(e.aggregates,`${i}.aggregates`,t),b(e.style,`${i}.style`,t),e.fields!==void 0&&(!Array.isArray(e.fields)||e.fields.some(s=>typeof s!="string"))&&t.push({path:`${i}.fields`,message:"合计字段应为字符串数组"})}}function Ue(e,i,t,s){const n={kind:"rect",leftMm:0,topMm:0,widthMm:1,heightMm:1,grid:e};if(D(n,t,s,[]),H(n,t,s),!u(e)||!Array.isArray(e.cells))return;const a=e.cells,o=Array.isArray(i)?i.length:0;if(a.length*o>N){s.push({path:t,message:"表头逻辑网格超过 20 万格安全上限"});return}e.cells.length||s.push({path:`${t}.cells`,message:"表头至少需要一行"}),Array.isArray(e.colWidthsMm)&&e.colWidthsMm.length!==o&&s.push({path:`${t}.colWidthsMm`,message:"表头列宽数量应与列表列数一致"}),Array.isArray(e.rowHeightsMm)&&e.rowHeightsMm.length!==e.cells.length&&s.push({path:`${t}.rowHeightsMm`,message:"表头行高数量应与行数一致"}),ze(a,o,t,s)}function ze(e,i,t,s){const n=new Set;e.forEach((a,o)=>{if(!Array.isArray(a))return;let r=0;a.forEach((f,d)=>{for(;n.has(`${o}:${r}`);)r++;const c=u(f)&&typeof f.colSpan=="number"?f.colSpan:1,m=u(f)&&typeof f.rowSpan=="number"?f.rowSpan:1;(r+c>i||o+m>e.length)&&s.push({path:`${t}.cells.${o}.${d}`,message:"表头合并区域超出表头边界"});for(let l=o;l<Math.min(e.length,o+m);l++)for(let y=r;y<Math.min(i,r+c);y++)n.has(`${l}:${y}`)&&s.push({path:`${t}.cells.${o}.${d}`,message:"表头合并区域重叠"}),n.add(`${l}:${y}`);r+=c})})}function qe(e,i,t){if(Ce(e,i,t),Te(e.computed,`${i}.computed`,t),xe(e.matrix,`${i}.matrix`,t),e.matrix&&(e.detail||e.groupBy||Array.isArray(e.groups)&&e.groups.length||e.grandTotal)&&t.push({path:`${i}.matrix`,message:"矩阵请使用自身 totals 汇总,不能同时配置普通分组、总计或主从明细"}),_(e.rowVisibleWhen,`${i}.rowVisibleWhen`,t),e.groups!==void 0&&(!Array.isArray(e.groups)||e.groups.length>16?t.push({path:`${i}.groups`,message:"分组应为数组,最多 16 级"}):e.groups.forEach((a,o)=>ne(a,`${i}.groups.${o}`,t))),e.detail===void 0)return;const s=e.detail,n=`${i}.detail`;if(!u(s)){t.push({path:n,message:"主从关联应为对象"});return}for(const a of["dataset","parentKey","foreignKey"])h(s,a,n,t,!0);for(const a of["rowKey","revisionField","sourceTokenField"])h(s,a,n,t,s[a]!==void 0);h(s,"label",n,t),A(s,"header",n,t),g(s,"rowHeightMm",n,t,Number.MIN_VALUE),se(s.columns,`${n}.columns`,t),s.unmatched!==void 0&&s.unmatched!=="error"&&s.unmatched!=="ignore"&&t.push({path:`${n}.unmatched`,message:"未关联明细策略应为 error 或 ignore"})}function Xe(e,i,t){for(const s of["leftMm","topMm"])g(e,s,i,t,-1/0,!0);g(e,"widthMm",i,t,Number.MIN_VALUE,!0),h(e,"dataset",i,t,!0),h(e,"title",i,t);for(const s of["rowKey","revisionField","sourceTokenField"])h(e,s,i,t,e[s]!==void 0);e.headerGrid!==void 0&&Ue(e.headerGrid,e.columns,`${i}.headerGrid`,t),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&t.push({path:`${i}.layout`,message:"布局应为 page 或 wide"}),se(e.columns,`${i}.columns`,t);for(const s of["fontSizePt","rowHeightMm"])g(e,s,i,t,Number.MIN_VALUE);g(e,"paddingMm",i,t);for(const s of["header","headerBold","headerEveryPage","border"])A(e,s,i,t);e.cardinality!==void 0&&e.cardinality!=="record"&&t.push({path:`${i}.cardinality`,message:"单记录区域类型应为 record"}),h(e,"headerBackgroundColor",i,t),E(e.align,`${i}.align`,t,!0),E(e.headerAlign,`${i}.headerAlign`,t),b(e.headerStyle,`${i}.headerStyle`,t),qe(e,i,t),ne(e.groupBy,`${i}.groupBy`,t),Ge(e.grandTotal,`${i}.grandTotal`,t)}function W(e,i,t){Array.isArray(e.richParagraphs)&&e.richParagraphs.forEach((s,n)=>{if(!u(s))return;const a=`${i}.richParagraphs.${n}`;E(s.align,`${a}.align`,t);for(const o of["lineHeight","spaceBeforeMm","spaceAfterMm","indentMm"])g(s,o,a,t);Array.isArray(s.segments)&&s.segments.forEach((o,r)=>{const f=`${a}.segments.${r}`;if(!u(o)){t.push({path:f,message:"富文本片段应为对象"});return}o.kind!==void 0&&o.kind!=="text"&&o.kind!=="field"&&t.push({path:`${f}.kind`,message:"未知富文本片段类型"});for(const d of["text","field"])h(o,d,f,t);b(o.style,`${f}.style`,t)})})}function H(e,i,t){b(e.style,`${i}.style`,t);for(const n of["text","rawText","imageData","fallbackText","nid","rkey"])h(e,n,i,t);if(e.lines!==void 0&&(!Array.isArray(e.lines)||e.lines.some(n=>typeof n!="string"))&&t.push({path:`${i}.lines`,message:"文本行应为字符串数组"}),W(e,i,t),!u(e.grid))return;const s=e.grid;g(s,"gapMm",`${i}.grid`,t),g(s,"paddingMm",`${i}.grid`,t);for(const n of["colWidthsMm","rowHeightsMm"]){const a=s[n];a!==void 0&&(!Array.isArray(a)||a.some(o=>typeof o!="number"||!Number.isFinite(o)||o<0))&&t.push({path:`${i}.grid.${n}`,message:"网格尺寸应为有限非负数字数组"})}Array.isArray(s.cells)&&s.cells.forEach((n,a)=>{Array.isArray(n)&&n.forEach((o,r)=>{const f=`${i}.grid.cells.${a}.${r}`;if(o!==null){if(!u(o)){t.push({path:f,message:"网格单元格应为对象或 null"});return}for(const d of["text","rawText","numberFormat"])h(o,d,f,t);for(const d of["colSpan","rowSpan"]){const c=o[d];c!==void 0&&(typeof c!="number"||!Number.isInteger(c)||c<=0)&&t.push({path:`${f}.${d}`,message:"跨度应为正整数"})}o.value!==void 0&&o.value!==null&&!["string","number","boolean"].includes(typeof o.value)&&t.push({path:`${f}.value`,message:"Excel 原始值应为字符串、数字、布尔值或 null"}),b(o.style,`${f}.style`,t),W(o,f,t),o.children!==void 0&&(Array.isArray(o.children)?o.children.forEach((d,c)=>{u(d)&&H(d,`${f}.children.${c}`,t)}):t.push({path:`${f}.children`,message:"嵌套组件应为数组"}))}})})}function Ye(e,i,t){if(!(e.flow===void 0||!Array.isArray(e.components)))try{Z(e.components,e.flow)}catch(s){t.push({path:`${i}.flow`,message:s instanceof Error?s.message:String(s)})}}function ae(e){const i=[],t=[];return K(e,i),i.length?{ok:!1,errors:i,warnings:t}:(u(e)?(e.schemaVersion!==void 0&&e.schemaVersion!==k.RENDER_PLAN_SCHEMA_VERSION&&i.push({path:"$.schemaVersion",message:"不支持的模板 schemaVersion"}),Je(e.params,"$.params",i),L(e.dataContract,"$.dataContract",i),te(e,i),!Array.isArray(e.pages)||e.pages.length===0?i.push({path:"$.pages",message:"模板至少需要一页"}):e.pages.forEach((s,n)=>{const a=`$.pages.${n}`;if(!u(s)){i.push({path:a,message:"页应为对象"});return}g(s,"widthMm",a,i,Number.MIN_VALUE,!0),g(s,"heightMm",a,i,Number.MIN_VALUE,!0),s.layout!==void 0&&s.layout!=="page"&&s.layout!=="wide"&&i.push({path:`${a}.layout`,message:"布局应为 page 或 wide"}),typeof s.heightMm=="number"&&s.heightMm>=5e3&&i.push({path:`${a}.heightMm`,message:"页高应小于 5000mm"});for(const o of["marginTopMm","marginBottomMm","marginLeftMm","marginRightMm"])g(s,o,a,i);typeof s.widthMm=="number"&&Number(s.marginLeftMm??0)+Number(s.marginRightMm??0)>=s.widthMm&&i.push({path:a,message:"横向页边距占满页面"}),typeof s.heightMm=="number"&&Number(s.marginTopMm??0)+Number(s.marginBottomMm??0)>=s.heightMm&&i.push({path:a,message:"纵向页边距占满页面"}),Array.isArray(s.components)?s.components.forEach((o,r)=>{const f=`${a}.components.${r}`;u(o)&&o.kind==="list"?Xe(o,f,i):(D(o,f,i,t),u(o)&&H(o,f,i))}):i.push({path:`${a}.components`,message:"组件应为数组"}),Ye(s,a,i)})):i.push({path:"$",message:"模板应为对象"}),{ok:i.length===0,errors:i,warnings:t})}function oe(e){const i=[],t=[];if(K(e,i),i.length)return{ok:!1,errors:i,warnings:t};if(!u(e))i.push({path:"$",message:"模板文档应为对象"});else{for(const n of Object.keys(e))De.has(n)||i.push({path:`$.${n}`,message:"模板文档存在未知字段;只保存模板与描述,不保存取数或业务数据"});e.schemaVersion!==j&&i.push({path:"$.schemaVersion",message:"不支持的模板文档版本"});for(const n of["id","name"])h(e,n,"$",i,!0);for(const n of["revision","description"])h(e,n,"$",i);const s=ae(e.template);i.push(...s.errors.map(n=>({...n,path:`$.template${n.path.slice(1)}`}))),t.push(...s.warnings.map(n=>({...n,path:`$.template${n.path.slice(1)}`})))}return{ok:i.length===0,errors:i,warnings:t}}function F(e){const i=oe(e);if(!i.ok)throw new M(i.errors)}function Qe(e){const i=[];if(K(e,i),i.length)throw new M(i);const t={...e,schemaVersion:e.schemaVersion??j};return F(t),C(t)}function Ze(e){let i=e;if(typeof e=="string"){if(e.length>w.MAX_TEMPLATE_JSON_CHARACTERS)throw new M([{path:"$",message:"模板 JSON 超过 1000 万字符的导出/导入上限"}]);try{i=JSON.parse(e)}catch{throw new M([{path:"$",message:"模板 JSON 语法无效"}])}}return F(i),C(i)}function et(e){F(e);try{return w.stringifyValidatedTemplate(e)}catch(i){throw i instanceof RangeError?new M([{path:"$",message:i.message}]):i}}function C(e){return JSON.parse(JSON.stringify(e))}function tt(e=[]){const i=new Map,t={get:s=>{const n=i.get(s);return n?C(n):void 0},list:()=>Array.from(i.values(),({template:s,...n})=>({...n})),register:(s,n={})=>{if(F(s),i.has(s.id)&&!n.replace)throw new M([{path:"$.id",message:`模板 ID ${s.id} 已注册;更新需显式 replace:true`}]);i.set(s.id,C(s))},remove:s=>i.delete(s)};for(const s of e)t.register(s);return t}exports.REPORT_TEMPLATE_DOCUMENT_VERSION=j;exports.ReportTemplateError=M;exports.assertRenderPlan=be;exports.createTemplateRegistry=tt;exports.defineReportTemplate=Qe;exports.inspectReportTemplateCompatibility=Ie;exports.parseReportTemplate=Ze;exports.reportFlowGroups=Me;exports.serializeReportTemplate=et;exports.validateComponent=D;exports.validatePage=Y;exports.validateRenderPlan=Q;exports.validateReportPageFlow=Z;exports.validateReportTemplate=ae;exports.validateReportTemplateDocument=oe;exports.validateTemplateRepeat=te;