@agile-team/mach-report 2.16.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +25 -12
  2. package/dist/{ExcelBindingWizard-CP6h2x1f.cjs → ExcelBindingWizard-Czn3C2yE.cjs} +1 -1
  3. package/dist/{ExcelBindingWizard-HhB3hAJE.js → ExcelBindingWizard-DMGZj6I6.js} +3 -3
  4. package/dist/ParamEditor-KzDQvbHY.js +732 -0
  5. package/dist/ParamEditor-oDfD8LgE.cjs +1 -0
  6. package/dist/{ReportBatchPanel-ruxcbfY6.js → ReportBatchPanel-BJK7PvZ4.js} +39 -39
  7. package/dist/ReportBatchPanel-DnmNRssu.cjs +1 -0
  8. package/dist/ReportParamPanel-mQkeN70Q.js +1020 -0
  9. package/dist/ReportParamPanel-sOANVRz-.cjs +1 -0
  10. package/dist/ReportPreview-BxWWTUL5.js +5583 -0
  11. package/dist/ReportPreview-Yf99omi3.cjs +6 -0
  12. package/dist/{ReportTemplateLibrary-DcwrH-63.js → ReportTemplateLibrary-BFjB08Wu.js} +1 -1
  13. package/dist/{ReportTemplateLibrary-BDlNT8JN.cjs → ReportTemplateLibrary-BO42QnWd.cjs} +1 -1
  14. package/dist/RuleEditor-CqxT1a-W.js +2337 -0
  15. package/dist/RuleEditor-D7YWigD9.cjs +1 -0
  16. package/dist/{TemplateOutlinePanel-CGrT5DFN.cjs → TemplateOutlinePanel-B0XX350V.cjs} +1 -1
  17. package/dist/{TemplateOutlinePanel-SXCjaPKR.js → TemplateOutlinePanel-zG0DrsIB.js} +2 -2
  18. package/dist/{TemplateReusePanel-6Z3wRFz8.cjs → TemplateReusePanel-BD0HSKp_.cjs} +1 -1
  19. package/dist/{TemplateReusePanel-lHLOS9Wn.js → TemplateReusePanel-Czwe5GbC.js} +2 -2
  20. package/dist/{TemplateReviewPanel-Dpk7sLcF.cjs → TemplateReviewPanel-CA5sdffM.cjs} +1 -1
  21. package/dist/{TemplateReviewPanel-CJ9PLc48.js → TemplateReviewPanel-NhmQI65C.js} +2 -2
  22. package/dist/analytics.cjs +1 -1
  23. package/dist/analytics.d.cts +163 -42
  24. package/dist/analytics.d.ts +163 -42
  25. package/dist/analytics.js +76 -141
  26. package/dist/artifact-integrity.json +110 -108
  27. package/dist/assets-2eC3mOcV.js +232 -0
  28. package/dist/assets-B0Hxn4l6.cjs +1 -0
  29. package/dist/{auto-uVBjX1j5.cjs → auto-B0EZFIK1.cjs} +1 -1
  30. package/dist/{auto-YR7a4BtF.js → auto-BlchZ1b8.js} +10 -10
  31. package/dist/{batch-WzDIXJAt.js → batch-DGCt44XM.js} +1 -1
  32. package/dist/{batch-z6Aw5GEY.cjs → batch-DYcokH4v.cjs} +1 -1
  33. package/dist/charts-Dlv8j2AG.js +141 -0
  34. package/dist/charts-aCtoswXq.cjs +1 -0
  35. package/dist/codes.cjs +9 -9
  36. package/dist/codes.d.cts +54 -0
  37. package/dist/codes.d.ts +54 -0
  38. package/dist/codes.js +12097 -13668
  39. package/dist/column-visual-BpgQVWwT.js +238 -0
  40. package/dist/column-visual-CtYxnBCP.cjs +1 -0
  41. package/dist/component-tree-6TV7W6Yj.cjs +1 -0
  42. package/dist/component-tree-CvW4lzpv.js +67 -0
  43. package/dist/computed-4TnxzgIh.cjs +1 -0
  44. package/dist/computed-C8NRZQss.js +739 -0
  45. package/dist/data-bar-Ce38juRZ.cjs +1 -0
  46. package/dist/data-bar-PtjXhMgN.js +9 -0
  47. package/dist/dataset-DL83majE.js +161 -0
  48. package/dist/dataset-IrlXbUvh.cjs +1 -0
  49. package/dist/designer--TKECSEc.cjs +2 -0
  50. package/dist/designer-d6hJS41w.js +5683 -0
  51. package/dist/designer.cjs +1 -1
  52. package/dist/designer.d.cts +835 -45
  53. package/dist/designer.d.ts +835 -45
  54. package/dist/designer.js +23 -20
  55. package/dist/{encoding-BYF9ZTl9.cjs → encoding-B--eZpp1.cjs} +1 -1
  56. package/dist/{encoding-BOGq4qYL.js → encoding-mctOLocI.js} +2 -2
  57. package/dist/{font-loader-EKLzOJxf.cjs → font-loader-DBBJ5KE9.cjs} +1 -1
  58. package/dist/{font-loader-CzI1GuBc.js → font-loader-DW8tIaNp.js} +1 -1
  59. package/dist/index-CPh6tqge.js +1575 -0
  60. package/dist/index-CUNw7dL9.cjs +1 -0
  61. package/dist/index.cjs +8 -8
  62. package/dist/index.d.cts +534 -16
  63. package/dist/index.d.ts +534 -16
  64. package/dist/index.js +1393 -955
  65. package/dist/json-snapshot-By4ZVVUt.js +1967 -0
  66. package/dist/json-snapshot-jiXff4lc.cjs +2 -0
  67. package/dist/matrix-0hywp0-F.cjs +1 -0
  68. package/dist/matrix-Dy-tyY7E.js +381 -0
  69. package/dist/param-validation-C-8sRJLq.cjs +1 -0
  70. package/dist/param-validation-CnDEd2l-.js +333 -0
  71. package/dist/{pdf-DJ5S6ukC.js → pdf-CKROKygt.js} +1845 -1845
  72. package/dist/{pdf-ByVCb1i6.cjs → pdf-DqyxJ96U.cjs} +47 -47
  73. package/dist/pdf.cjs +1 -1
  74. package/dist/pdf.d.cts +66 -0
  75. package/dist/pdf.d.ts +66 -0
  76. package/dist/pdf.js +2 -2
  77. package/dist/{plugin-C2j5_mhx.js → plugin-ByjF2kiV.js} +5 -5
  78. package/dist/{plugin-Dr39GBRG.cjs → plugin-DM1M2wlI.cjs} +1 -1
  79. package/dist/prefill-B8H9qwE4.js +371 -0
  80. package/dist/prefill-D7EswyTI.cjs +1 -0
  81. package/dist/{prepared-DqtpvRTn.js → prepared-BE-4jfX5.js} +2 -2
  82. package/dist/{prepared-DdrjLC7L.cjs → prepared-CGVphji3.cjs} +1 -1
  83. package/dist/{protocol-BzwMP4Vw.cjs → protocol-ByRVzzQG.cjs} +1 -1
  84. package/dist/{protocol-kt4Iy6-3.js → protocol-Cr81vFSQ.js} +3 -3
  85. package/dist/{record-bindings-CZWBJ1fU.js → record-bindings-DEJtmo3p.js} +67 -107
  86. package/dist/record-bindings-ehjnCDHt.cjs +1 -0
  87. package/dist/{region-binding-workflow-CWNvIjkV.js → region-binding-workflow-CBg0l_tj.js} +2 -2
  88. package/dist/{region-binding-workflow-CqSMxQ4p.cjs → region-binding-workflow-D05tOYn3.cjs} +1 -1
  89. package/dist/report-encoding-worker.cjs +1 -1
  90. package/dist/report-encoding-worker.js +1 -1
  91. package/dist/{report-params-B1RzkhJj.js → report-params-D9tBuM9B.js} +1 -1
  92. package/dist/{report-params-WDGrA4oP.cjs → report-params-VTg8MoCp.cjs} +1 -1
  93. package/dist/runtime-CDA6d263.cjs +1 -0
  94. package/dist/runtime-CEMvybO7.js +170 -0
  95. package/dist/sbom.cdx.json +1 -1
  96. package/dist/server/node.d.cts +121 -7
  97. package/dist/server/node.d.ts +121 -7
  98. package/dist/server-node.cjs +4 -4
  99. package/dist/server-node.js +3446 -2115
  100. package/dist/server.cjs +1 -1
  101. package/dist/server.d.cts +417 -29
  102. package/dist/server.d.ts +417 -29
  103. package/dist/server.js +787 -544
  104. package/dist/sha256-BDQ1Qk7A.js +158 -0
  105. package/dist/sha256-DgZAKXqI.cjs +1 -0
  106. package/dist/style.css +1 -1
  107. package/dist/template-bindings-Cg5oBLFT.cjs +1 -0
  108. package/dist/template-bindings-TKnXM7ll.js +62 -0
  109. package/dist/{template-catalog-BtR2JmCL.js → template-catalog-CmbWOJqy.js} +16 -16
  110. package/dist/template-catalog-Utu4GP09.cjs +1 -0
  111. package/dist/{template-fragments-BVsbxs4a.cjs → template-fragments-C_zSHJAa.cjs} +1 -1
  112. package/dist/{template-fragments-By0aZC1D.js → template-fragments-DWgo9tlZ.js} +2 -2
  113. package/dist/{template-outline-BwRV_eRo.cjs → template-outline-DWkzZXVC.cjs} +1 -1
  114. package/dist/{template-outline-cnWfT_LK.js → template-outline-DiADphlq.js} +1 -1
  115. package/dist/{template-registry-Cw3vRTX2.js → template-registry-BIhIHOab.js} +319 -314
  116. package/dist/template-registry-DzWswQI5.cjs +1 -0
  117. package/dist/vue/async.d.cts +636 -35
  118. package/dist/vue/async.d.ts +636 -35
  119. package/dist/vue/index.d.cts +746 -67
  120. package/dist/vue/index.d.ts +746 -67
  121. package/dist/vue-async.cjs +1 -1
  122. package/dist/vue-async.js +3 -3
  123. package/dist/vue.cjs +1 -1
  124. package/dist/vue.js +94 -89
  125. package/dist/{workbook-session-Cbts-22R.cjs → workbook-session-B94EwVa_.cjs} +1 -1
  126. package/dist/{workbook-session-BeSO8PFB.js → workbook-session-BoScoOg-.js} +2 -2
  127. package/dist/worker.cjs +1 -1
  128. package/dist/worker.d.cts +75 -7
  129. package/dist/worker.d.ts +75 -7
  130. package/dist/worker.js +4 -4
  131. package/dist/xlsx.cjs +4 -4
  132. package/dist/xlsx.d.cts +208 -15
  133. package/dist/xlsx.d.ts +208 -15
  134. package/dist/xlsx.js +288 -252
  135. package/package.json +1 -1
  136. package/dist/ParamEditor-CUQLgoxa.cjs +0 -1
  137. package/dist/ParamEditor-OKesP_nO.js +0 -594
  138. package/dist/ReportBatchPanel-cZCAMAwH.cjs +0 -1
  139. package/dist/ReportPreview-BcDKCLiK.js +0 -4834
  140. package/dist/ReportPreview-Bk9nLfO9.cjs +0 -6
  141. package/dist/RuleEditor-BX5S8RSF.cjs +0 -1
  142. package/dist/RuleEditor-CGl9XY2s.js +0 -2037
  143. package/dist/assets-CqIbfbTr.js +0 -126
  144. package/dist/assets-e4YSke8n.cjs +0 -1
  145. package/dist/capabilities-DDwXr_cA.js +0 -103
  146. package/dist/capabilities-DNLyZdNw.cjs +0 -1
  147. package/dist/component-tree-Ca6YYfHq.js +0 -61
  148. package/dist/component-tree-DkGLEfZC.cjs +0 -1
  149. package/dist/computed-C-4C2S5h.js +0 -521
  150. package/dist/computed-CGV2a809.cjs +0 -1
  151. package/dist/config-Dg_o8e7m.cjs +0 -1
  152. package/dist/config-XQ4qrQ7Q.js +0 -844
  153. package/dist/dataset-BkRmwgeJ.cjs +0 -1
  154. package/dist/dataset-H5pFuQGU.js +0 -121
  155. package/dist/designer-BfQSahxq.js +0 -5163
  156. package/dist/designer-CPPdeM5_.cjs +0 -2
  157. package/dist/diagnostic-notification-B9K9We3h.cjs +0 -1
  158. package/dist/diagnostic-notification-qGAYZdkB.js +0 -7
  159. package/dist/drill-CsdjgkRM.cjs +0 -1
  160. package/dist/drill-DIGsZfyB.js +0 -145
  161. package/dist/json-snapshot-D6ioHth9.js +0 -1702
  162. package/dist/json-snapshot-DknkjvxP.cjs +0 -2
  163. package/dist/matrix-CGRGkn5s.js +0 -112
  164. package/dist/matrix-gEO7ZM_u.cjs +0 -1
  165. package/dist/param-validation-C3HlcLLO.cjs +0 -1
  166. package/dist/param-validation-Do7Eg8Zv.js +0 -181
  167. package/dist/record-bindings-DUX1VMlR.cjs +0 -1
  168. package/dist/runtime-BjKBI530.js +0 -168
  169. package/dist/runtime-CBFEPKEs.cjs +0 -1
  170. package/dist/sha256-BshdOkCC.cjs +0 -1
  171. package/dist/sha256-DTG-Gq8i.js +0 -157
  172. package/dist/template-bindings-C2SpvsMU.js +0 -58
  173. package/dist/template-bindings-CEtWyiLX.cjs +0 -1
  174. package/dist/template-catalog-C2NLdrwB.cjs +0 -1
  175. package/dist/template-registry-C62vpv4a.cjs +0 -1
  176. package/dist/tree-BX380Rr7.cjs +0 -1
  177. package/dist/tree-CjVZLRw7.js +0 -172
@@ -1,2 +0,0 @@
1
- "use strict";const Y=require("./component-tree-DkGLEfZC.cjs"),C=require("./style-C22Pbv3T.cjs"),D=require("./textwrap-BI-yJ6Wt.cjs"),R=require("./record-bindings-DUX1VMlR.cjs"),ge=require("./computed-CGV2a809.cjs"),Ne=require("./matrix-gEO7ZM_u.cjs"),Q=require("./tree-BX380Rr7.cjs"),L=require("./template-registry-C62vpv4a.cjs"),Tt=require("./report-params-WDGrA4oP.cjs"),$e=require("./param-validation-C3HlcLLO.cjs"),he=require("./grid-geometry-CZ_cYB6O.cjs"),Ke=require("./number-format-CZ2T_5kF.cjs"),Le=require("./dataset-BkRmwgeJ.cjs");function Et(e,t,r){const o=new Set,n=e.cells.map((a,s)=>{const i=[];let c=0;for(const d of a){for(;o.has(`${s}:${c}`);)c++;const l=d?.colSpan??1,f=d?.rowSpan??1;let u=0;for(let m=c;m<c+l;m++){t.has(m)&&u++;for(let h=s+1;h<s+f;h++)o.add(`${h}:${m}`)}u&&i.push(d?{...d,colSpan:u}:null),c+=l}return i});return{...e,cells:n,colWidthsMm:r}}function je(e){if(!e.columns.some(o=>o.hidden))return e;const t=new Set,r=e.columns.filter((o,n)=>o.hidden?!1:(t.add(n),!0));if(!r.length)throw new Error("列表至少需要一列可见列");return{...e,columns:r,...e.headerGrid?{headerGrid:Et(e.headerGrid,t,r.map(o=>o.widthMm))}:{}}}function*Pt(e){const{page:t}=e;L.validateReportPageFlow(t.components,t.flow);let r=0,o=0;for(const n of L.reportFlowGroups(t.components,t.flow)){e.active();const a=n.band,s=n.components.some(l=>l.kind==="list"&&l.cardinality!=="record"),i=s?0:n.components.reduce((l,f)=>Math.max(l,f.topMm-a.topMm+(f.kind==="list"?e.height(f):f.heightMm)),a.heightMm);let c=Math.max(e.top(),o+a.topMm-r);if(!s&&i>e.bottom()-e.top()+.001)throw new Error(`静态区域 ${a.componentIds.join(",")} 高度超出单页可用范围`);!s&&c+i>e.bottom()+.001&&(e.nextPage(),yield*e.takePages(),e.active(),c=e.top());let d=c+i;for(const l of n.components){const f=c+l.topMm-a.topMm;l.kind==="list"?(yield*e.list(l,f,u=>{d=s?u:Math.max(d,u)}),e.active()):e.append({...l,topMm:f})}o=d,r=a.topMm+a.heightMm}}function Ct(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))}function Z(e){return e.pages.some(t=>t.components.some(r=>r.kind==="list"&&Ct(r)))}const kt=512,Ie=256*1024;function $t(){const e=new Map;let t=0,r;return(o,n,a,s)=>{s!==r&&(e.clear(),t=0,r=s);const i=JSON.stringify([o,n,a.fontSizePt,a.fontFamily,a.bold,a.italic,a.letterSpacingPt]),c=e.get(i);if(c)return e.delete(i),e.set(i,c),c.lines.slice();const d=D.wrapText(o,n,a,s),l=i.length+d.reduce((f,u)=>f+u.length,0);if(l<=Ie){for(;e.size>=kt||t+l>Ie;){const f=e.keys().next().value;t-=e.get(f).units,e.delete(f)}e.set(i,{lines:d.slice(),units:l}),t+=l}return d}}class K extends Error{constructor(t,r){super(`报表页数超出上限 ${t}(至少 ${r} 页)`),this.limit=t,this.actual=r,this.code="page-limit",this.name="PaginatePageLimitError"}}class B extends Error{constructor(t,r){super(`报表单元格数量超出上限 ${t}(至少 ${r} 格)`),this.limit=t,this.actual=r,this.code="cell-limit",this.name="PaginateCellLimitError"}}const Be=1e4,Oe=25e4;function pe(e){if(e?.aborted)throw e.reason??new DOMException("标签生成已取消","AbortError")}function De(e,t,r){const o=typeof e.copies=="object"?R.readRecordScalar(t,e.copies.field,r):e.copies??1;if(typeof o!="number"||!Number.isSafeInteger(o)||o<1||o>1e3)throw new R.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}]`,"每条记录复制数必须是 1..1000 的数值型整数",r.rowIndex,typeof e.copies=="object"?e.copies.field:void 0);return o}function He(e,t,r){if(e.rowKey===void 0)return;const o=R.readRecordScalar(t,e.rowKey,r);if(typeof o=="string"&&o.trim()||typeof o=="number"&&Number.isFinite(o))return o;throw new R.ReportBindingError(`$.datasets.${r.dataset}[${r.rowIndex}].${e.rowKey}`,"业务主键必须是非空字符串或有限数字",r.rowIndex,e.rowKey)}function It(e){const t=r=>1+(r.grid?.cells.reduce((o,n)=>o+1+n.length+n.reduce((a,s)=>a+(s?.children?.reduce((i,c)=>i+t(c),0)??0),0),0)??0);return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function Ot(e,t,r){const o=e.repeat,n=Object.prototype.hasOwnProperty.call(t,o.dataset)?t[o.dataset]:void 0;if(!Array.isArray(n))throw new R.ReportBindingError(`$.datasets.${o.dataset}`,"逐记录标签数据集缺失,应提供对象数组(允许空数组)");const a=new Set,s=r.maxPages??Be,i=It(e);let c=0,d=0;for(const[l,f]of n.entries()){if(pe(r.signal),!f||typeof f!="object"||Array.isArray(f))throw new R.ReportBindingError(`$.datasets.${o.dataset}[${l}]`,"标签记录应为对象",l);const u={rowIndex:l,dataset:o.dataset},m=He(o,f,u);if(m!==void 0){const g=JSON.stringify([typeof m,m]);if(a.has(g))throw new R.ReportBindingError(`$.datasets.${o.dataset}[${l}].${o.rowKey}`,"业务主键重复;请先确认记录来源,避免重复打印标签",l,o.rowKey);a.add(g)}const h=De(o,f,u);if(c+=h*e.pages.length,d+=h*i,c>s)throw new K(s,c);if(d>Oe)throw new R.ReportBindingError("$.repeat",`标签组件总量(含网格行、槽位及嵌套组件)超过安全预算 ${Oe},请分批生成`,l)}return n}function Ft(e,t,r){if(!e.binding)return e;const{binding:o,...n}=e,a=R.resolveComponentBinding(o,t.row,t);if(e.kind==="image"){if(!a)return;if(!R.isLabelImageData(a))throw new R.ReportBindingError(`${r}.binding`,"图片字段只接受 PNG/JPEG base64 data URL;业务 URL 应由宿主安全加载后转换",t.rowIndex,o.field);return{...n,imageData:a}}return e.kind==="barcode"||e.kind==="qrcode"?(delete n.imageData,{...n,code:{...n.code,value:a},fallbackText:a}):(delete n.lines,delete n.richParagraphs,{...n,text:a})}function At(e,t,r){if(e.kind!=="text"||e.grid||e.richParagraphs?.length)return e;const o=e.style??{},n=C.resolveFontSize(o).fontSizePt,a=e.text??e.lines?.join(`
2
- `)??"";if(a.length>16384)throw new R.ReportBindingError(r,"标签文本超过 16384 字符预算,请缩小字段内容",t.rowIndex);const s=t.wrapText(a,e.widthMm,{fontSizePt:n,bold:o.bold,italic:o.italic,fontFamily:o.fontFamily,letterSpacingPt:o.letterSpacing},t.options.measurer??D.heuristicMeasurer),i=s.length*n*C.resolveLineHeight(o)*25.4/72;if(i>e.heightMm+.05)throw new R.ReportBindingError(r,`标签文字需要约 ${i.toFixed(2)}mm 高,超出 ${e.heightMm}mm;请增大文本区域、减少内容或调整字号`,t.rowIndex,e.binding?.field);return{...e,lines:s}}function Ge(e,t,r){pe(t.options.signal);const o=Ft(e,t,r);if(!o)return;let n=o.grid;return n&&(n={...n,cells:n.cells.map((a,s)=>a.map((i,c)=>i?.children?.length?{...i,children:i.children.flatMap((d,l)=>{const f=Ge(d,t,`${r}.grid.cells.${s}.${c}.children.${l}`);return f?[f]:[]})}:i))}),At(n===o.grid?o:{...o,grid:n},t,r)}function Nt(e,t,r,o,n,a){return{...e,components:e.components.flatMap((s,i)=>{const c=Ge(s,r,`$.pages.${t}.components.${i}`);return c?[{...c,meta:{...c.meta,labelSource:{pageIndex:t,componentIndex:i}}}]:[]}),meta:{...e.meta,record:{dataset:r.dataset,rowIndex:r.rowIndex,...a===void 0?{}:{rowKey:a},copyIndex:o,copyCount:n,templatePageIndex:t}}}}function*Kt(e,t,r){const o=[];if(L.validateTemplateRepeat(e,o),o.length)throw new R.ReportBindingError(o[0].path,o[0].message);if(!e.repeat){for(const[i,c]of e.pages.entries())yield{page:c,pageIndex:i};return}const n=e.repeat,a=Ot(e,t,r),s=$t();for(const[i,c]of a.entries()){const d={row:c,rowIndex:i,dataset:n.dataset,options:r,wrapText:s},l=De(n,c,d),f=He(n,c,d);for(let u=0;u<l;u++)for(const[m,h]of e.pages.entries())pe(r.signal),yield{page:Nt(h,m,d,u,l,f),pageIndex:m}}}function Lt(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 U(e,t){const r=t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm);return e.components.reduce((o,n)=>n.kind!=="list"&&n.pageAnchor==="footer"?Math.min(o,n.topMm):o,r)}function _(e){return e.components.reduce((t,r)=>r.kind!=="list"&&r.pageAnchor==="header"?Math.max(t,r.topMm+r.heightMm):t,0)}function Ve(e,t){let r=e.textMetrics.get(t);if(!r){const o=C.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:o,fontFamily:t.fontFamily??C.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:o*(t.lineHeight??C.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function jt(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function we(e,t){const r=e.fontSizePt??C.DEFAULT_FONT_PT,o=e.paddingMm??1,n=e.columns.map(g=>g.align??g.style?.align??e.align??"left"),a=e.columns.map((g,w)=>({...C.mergeComponentStyles({fontSize:r,verticalAlign:"middle"},g.style),align:n[w]==="auto"?"left":n[w]})),s=a.map((g,w)=>n[w]==="auto"?{left:g,center:{...g,align:"center"},right:{...g,align:"right"}}:void 0),i=e.columns.map((g,w)=>g.rules?.map(y=>{const v=s[w];if(v)return{left:C.mergeComponentStyles(v.left,y.style),center:C.mergeComponentStyles(v.center,y.style),right:C.mergeComponentStyles(v.right,y.style)};const T=C.mergeComponentStyles(a[w],y.style);return{left:T,center:T,right:T}})),c=e.columns.map(g=>R.resolveListHeaderStyle(e,g)),d=e.columns.map(g=>g.header);let l=e.rowHeightMm??0;for(let g=0;g<d.length;g++){const w=c[g],y=C.resolveFontSize(w).fontSizePt,v=D.wrapText(d[g],e.columns[g].widthMm-o*2,{fontSizePt:y,fontFamily:w.fontFamily??C.DEFAULT_FONT_FAMILY,italic:w.italic,bold:w.bold,letterSpacingPt:w.letterSpacing},t),T=y*(w.lineHeight??C.LINE_HEIGHT)*25.4/72;l=Math.max(l,Math.max(v.length,1)*T+o*2)}const f=d.map((g,w)=>({text:g,style:c[w]})),u=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},m=e.columns.map(g=>g.widthMm),h=Bt(e.headerGrid,m,{cells:[f],colWidthsMm:m,rowHeightsMm:[l],paddingMm:o});return{fontSizePt:r,paddingMm:o,cellStyles:a,autoStyles:s,ruleStyles:i,textMetrics:new WeakMap,numberFormats:e.columns.map(g=>R.toExcelNumberFormat(g.format)),derivedFields:new Set(e.computed?.map(g=>g.field)),borderStyle:u,headerHeightMm:h.rowHeightsMm.reduce((g,w)=>g+w,0),headerGrid:h,colWidthsMm:m,columns:e.columns}}function Bt(e,t,r){if(!e)return r;if(!e.cells.length)throw new Error("自定义列表表头至少需要一行");const o=e.rowHeightsMm??e.cells.map(()=>r.rowHeightsMm[0]);if(o.length!==e.cells.length||o.some(n=>!Number.isFinite(n)||n<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:o}}function Dt(e,t,r){const o=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:o&&(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 W(e,t,r){const o=e.columns,n=e.tree?.rows.get(t);let a=e.rowHeightFloorMm;const s=new Array(o.length);for(let i=0;i<o.length;i++){const c=o[i],d=c.visibleWhen&&!R.evalStyleRule(t,c.visibleWhen)?null:t[c.field],l=e.autoStyles[i]?R.resolveListAutoAlignment(d,c.format,c.semanticRole):"left";let f=e.autoStyles[i]?.[l]??e.cellStyles[i];if(c.rules)for(let v=0;v<c.rules.length;v++){const T=c.rules[v];if(R.evalStyleRule(t,T.when)){f=e.ruleStyles[i][v][l];break}}const u=c.format?R.formatValue(d,c.format):R.listCellText(d),m=Ht(e,c,n);f=Gt(e,c,f,n);const h=Ve(e,f),g=D.wrapText(u,Math.max(1,c.widthMm-e.paddingMm*2-m),h.measureOptions,r);a=Math.max(a,g.length*h.lineMm+e.paddingMm*2);const w=jt(d),y={text:u,style:f};w!==void 0&&(y.value=w),Dt(y,c,e.numberFormats[i]),Vt(y,c,e,n,m),e.derivedFields.has(c.field)&&(y.derived=!0,y.editable=!1),c.visibleWhen&&d===null&&!R.evalStyleRule(t,c.visibleWhen)&&(y.editable=!1),s[i]=y}return{grid:{cells:[s],colWidthsMm:e.colWidthsMm,rowHeightsMm:[a],paddingMm:e.paddingMm},heightMm:a}}function Ht(e,t,r){return!r||t.field!==e.tree.list.tree.labelField?0:R.listTreeIndent(e.tree.list,t,r,e.paddingMm)}function Gt(e,t,r,o){return!o||t.field!==e.tree.list.tree.labelField||r.align==="left"?r:{...r,align:"left"}}function Vt(e,t,r,o,n=0){o&&(n&&(e.indentMm=n),R.applyListTreeMetadata(e,t,o,r.tree.list))}function _e(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*We(e,t,r=0){const o=t[r];if(!o){for(const a of e)yield{kind:"row",row:a};return}const n=new Map;for(const a of e){const s=_e(a[o.field]),i=n.get(s);i?i.push(a):n.set(s,[a])}for(const a of n.values())yield{kind:"groupHeader",label:(o.headerTemplate??"{value}").replace(/\{value\}/g,R.listCellText(a[0][o.field])),firstRow:a[0],group:o,depth:r,rows:a},yield*We(a,t,r+1),(o.subtotal?.length||o.aggregates?.length)&&(yield{kind:"subtotal",label:o.subtotalLabel??"小计",rows:a,group:o,depth:r}),yield{kind:"groupEnd",depth:r}}function Je(e,t,r,o=[]){const n=[...r.filter(a=>!o.some(s=>s.field===a)).map(a=>({field:a,op:"sum"})),...o];return new Map(n.map(a=>{const s=e.find(c=>c.field===a.field)?.format??{kind:"number",thousands:!0},i=ge.aggregateRows(t,{...a,field:a.valueField??a.field});return[a.field,{text:R.formatValue(i,s),...i===null?{}:{value:i},...typeof i=="number"?{numberFormat:R.toExcelNumberFormat(s)}:{}}]}))}function qe(e,t){const r=e.findIndex(o=>t.includes(o.field));return r<0?1:r}function V(e,t,r,o,n,a){const s=[],i=Math.max(0,Math.min(a,e.columns.length)),c=C.mergeComponentStyles({fontSize:e.fontSizePt},n);i&&s.push({text:r,colSpan:i,style:{bold:!0,...c}});for(let u=i;u<e.columns.length;u++){const m=e.columns[u],h=o.get(m.field),g=e.autoStyles[u]?.[R.resolveListAutoAlignment(h?.value,m.format)]??e.cellStyles[u];s.push({...h,text:h?.text??"",style:C.mergeComponentStyles(g,n)})}const d={text:r,colSpan:e.columns.length,style:{bold:!0,...c}},l=i?[s]:[[d],s],f=l.map(u=>_t(e,u,t));return{grid:{cells:l,colWidthsMm:e.colWidthsMm,rowHeightsMm:f,paddingMm:e.paddingMm},heightMm:f.reduce((u,m)=>u+m,0)}}function _t(e,t,r){let o=e.rowHeightFloorMm,n=0;for(const a of t){let s=0;const i=n+(a.colSpan??1);for(;n<i;n++)s+=e.colWidthsMm[n]??0;const c=Ve(e,a.style),d=D.wrapText(a.text??"",s-e.paddingMm*2,c.measureOptions,r);o=Math.max(o,d.length*c.lineMm+e.paddingMm*2)}return o}function Wt(e,t,r){const{templatePage:o,current:n,warnings:a,nextId:s,pushCurrent:i}=r,c=()=>U(o,n),d=Math.max(n.marginTopMm,_(o)),l=o.layout==="wide"?_(o):d,f={id:r.tableId,columnKeys:e.columns.map(p=>p.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}},u=new Map,m=new Map,h={kind:"rect",leftMm:e.leftMm,topMm:0,widthMm:e.widthMm,heightMm:t.headerHeightMm,grid:t.headerGrid,nid:s("listh"),table:{...f,role:"header",rowIndex:-1},style:t.borderStyle,...e.meta?{meta:e.meta}:{}},g=p=>n.components.push({...h,topMm:p});if(r.flow&&e.header!==!1&&t.headerHeightMm>c()-d+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的表头高度超出单页可用范围`);let w=Math.max(r.startTop??e.topMm,d);e.header!==!1&&(g(w),w+=t.headerHeightMm+r.mmPerRow);function y(){const p=Math.max(r.flow||o.layout==="wide"?0:e.topMm,l);return(e.header!==!1&&e.headerEveryPage!==!1?p+t.headerHeightMm:l)+[...m.values()].reduce((x,P)=>x+P.heightMm,0)}function v(){const p=o.layout==="wide"?0:n.marginBottomMm;return Math.min(o.heightMm-p,U(o,n))-y()}function T(p){if(w+p<=c())return;i(),n.components=[],n.heightMm=o.heightMm,o.layout==="wide"&&(n.marginTopMm=0,n.marginBottomMm=0);const M=Math.max(r.flow||o.layout==="wide"?0:e.topMm,l);e.header!==!1&&e.headerEveryPage!==!1?(g(M),w=M+t.headerHeightMm):w=l;for(const x of m.values())N(x,"listgr","group-header")}function S(p,M,x,P){const k=v();if(r.flow&&p.heightMm>k+.001)throw new Error(`流式列表 ${e.id??e.dataset} 的单行高度超出单页可用范围`);p.heightMm>k&&a.push(`列表 ${e.id??e.dataset} 行高 ${p.heightMm.toFixed(2)}mm 超出单页可用高度 ${k.toFixed(2)}mm,预览与打印可能截断内容`),T(p.heightMm),N(p,M,x,P)}function N(p,M,x,P){const k=p.table?.id??f.id,A=x==="header"?-1:u.get(k)??0;x!=="header"&&u.set(k,A+p.grid.cells.length),n.components.push({kind:"rect",leftMm:e.leftMm,topMm:w,widthMm:e.widthMm,heightMm:p.heightMm,grid:p.grid,nid:s(M),table:{...f,...p.table,role:x,rowIndex:A,...P?{source:P}:{}},style:t.borderStyle,...e.meta?{meta:e.meta}:{}}),w+=p.heightMm}function F(p){p<=v()&&T(p)}return{keepTogether:F,placeGridRow:S,setGroupHeader:(p,M)=>{M?m.set(p,M):m.delete(p)},bottom:()=>w}}function Jt(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 o=e.revisionField?t[e.revisionField]:void 0,n=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(o!==void 0&&typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o)))throw new Error("业务修订号应为字符串或有限数字");if(n!==void 0&&typeof n!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...o===void 0?{}:{revision:o},...n===void 0?{}:{sourceToken:n}}}function ee(e,t){const r=new Map;if(!e.rowKey)return r;const o=new Set;for(const n of t){const a=Jt(e,n),s=JSON.stringify(a.rowKey);if(o.has(s))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(a.rowKey)}`);o.add(s),r.set(n,a)}return r}function qt(e,t,r,o,n){if(!e.grandTotal)return;const a=typeof e.grandTotal=="object"?e.grandTotal:void 0,s=te(e)[0],i=a?.fields??s?.subtotal??[],c=a?.aggregates??s?.aggregates??[];if(i.length===0&&c.length===0){o.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const d=V(r,o.measurer,a?.label??"合计",Je(e.columns,t,i,c),a?.style??{},qe(e.columns,[...i,...c.map(l=>l.field)]));n.placeGridRow(d,"listgt","grand-total")}function J(e){if(e?.aborted){const t=new Error("报表排版已取消");throw t.name="AbortError",t}}function te(e){const t=e.groups??(e.groupBy?[e.groupBy]:[]);if(t.length>16)throw new Error("列表最多支持 16 级分组");return t}function ye(e){const t=je(e),r=t.columns.reduce((n,a)=>n+a.widthMm,0),o=r>t.widthMm?t.widthMm/r:1;return o===1?t:{...t,columns:t.columns.map(n=>({...n,widthMm:n.widthMm*o}))}}function zt(e,t,r){const o=e.detail;if(!o)return;const n=new Set;for(const d of t){const l=le(d[o.parentKey]);if(n.has(l))throw new Error("主从明细的主表关联键重复");n.add(l)}const a=r.datasets[o.dataset]??[],s=new Map,i=[];for(const d of a){const l=d[o.foreignKey];if(!ze(l)&&o.unmatched==="ignore")continue;const f=le(l);if(!n.has(f)){if(o.unmatched!=="ignore")throw new Error(`明细数据集 ${o.dataset} 存在未关联的业务键`);continue}const u=s.get(f);u?u.push(d):s.set(f,[d]),i.push(d)}const c=ye({...e,id:`${e.id??e.dataset}:detail`,dataset:o.dataset,rowKey:o.rowKey,revisionField:o.revisionField,sourceTokenField:o.sourceTokenField,computed:void 0,columns:o.columns,headerGrid:void 0,rowHeightMm:o.rowHeightMm??e.rowHeightMm,detail:void 0});return{list:c,inter:{...we(c,r.measurer),rowHeightFloorMm:c.rowHeightMm??0},rows:s,sources:ee(c,i)}}function ze(e){return typeof e=="string"&&!!e.trim()||typeof e=="number"&&Number.isFinite(e)}function le(e){if(!ze(e))throw new Error("主从关联键必须是非空字符串或有限数字");return _e(e)}function*Ut(e,t,r,o,n){if(!r)return;const a=r.rows.get(le(t[e.detail.parentKey]))??[];if(!a.length)return;const s={id:`${o.tableId}:detail`,columnKeys:r.list.columns.map(i=>i.field),title:e.detail.label};e.detail.label&&n.placeGridRow({...V(r.inter,o.measurer,e.detail.label,new Map,{},r.list.columns.length),table:s},"listdl","group-header"),e.detail.header!==!1&&n.placeGridRow({grid:r.inter.headerGrid,heightMm:r.inter.headerHeightMm,table:s},"listdh","header"),yield*o.takePages();for(const i of a)J(o.signal),n.placeGridRow({...W(r.inter,i,o.measurer),table:s},"listdr","body",r.sources.get(i)),yield*o.takePages()}function Xt(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=Ne.createMatrixTable(t,e.matrix),o=r.columns.map((a,s)=>({...a,widthMm:s===0?e.matrix.rowWidthMm??40:e.matrix.columnWidthMm??28,editable:!1,align:s===0?"center":"right"})),n={...e,columns:o,headerGrid:void 0,rowKey:void 0,revisionField:void 0,sourceTokenField:void 0};return e.layout==="wide"&&(n.widthMm=o.reduce((a,s)=>a+s.widthMm,0)),{list:n,rows:r.rows}}function Ue(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("树形布局需要可见的标签列");Q.validateTreeComputed(e.tree,e.computed)}function Yt(e,t,r){Ue(e);const o=Q.createTreeTable(t,e.tree,{signal:r.signal,computed:e.computed?.length?{fields:e.computed,formula:r.formula}:void 0}),n={...e,rowKey:e.tree.idField},a=ee(n,o.entries.map(c=>c.original)),s=new Map,i=new WeakMap;for(const c of o.entries)s.set(c.row,a.get(c.original)),i.set(c.row,c);return{list:n,rows:o.rows,sources:s,treeRows:i,totalRows:o.leaves}}function Qt(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 Xe(e,t,r){const o=r.prepared.get(e);if(o)return o;const n=Qt(e,t);if(n)return r.prepared.set(e,n),n;if(e.tree){const c=Yt(e,t,r);return r.prepared.set(e,c),c}let a=e.computed?.length?ge.computeDataset(t,{fields:e.computed,signal:r.signal,formula:r.formula}).rows:t;const s=a===t?void 0:new Map(a.map((c,d)=>[c,t[d]]));e.rowVisibleWhen&&(a=a.filter(c=>R.evalStyleRule(c,e.rowVisibleWhen)));const i=Xt(e,a);if(!e.matrix){const c=ee(e,s?a.map(d=>s.get(d)):a);i.sources=s?new Map(a.map(d=>[d,c.get(s.get(d))])):c}return r.prepared.set(e,i),i}function Zt(e,t,r,o){if(!o.flow)return;const{current:n,templatePage:a}=o,s=Math.max(n.marginTopMm,_(a)),i=Math.max(o.startTop??e.topMm,s),c=(e.header===!1?0:t.headerHeightMm)+(r[0]?W(t,r[0],o.measurer).heightMm:0);i+c<=U(a,n)+.001||i<=s+.001||(o.pushCurrent(),n.components=[],n.heightMm=a.heightMm,a.layout==="wide"&&(n.marginTopMm=0,n.marginBottomMm=0),o.startTop=Math.max(n.marginTopMm,_(a)))}function*er(e,t,r){const o=Xe(e,t,r),n=o.rows;e=o.list,e.layout==="wide"&&(r.current.widthMm=Math.max(r.current.widthMm,e.leftMm+e.widthMm+r.current.marginRightMm));const a=o.sources??ee(e,n),s=ye(e),i=te(s),c={...we(s,r.measurer),rowHeightFloorMm:s.rowHeightMm??0,...o.treeRows?{tree:{list:s,rows:o.treeRows}}:{}};Zt(s,c,n,r);const d=Wt(s,c,r),l=zt(s,n,r);let f;for(const u of We(n,i)){if(J(r.signal),u.kind==="row")d.placeGridRow(f??W(c,u.row,r.measurer),"listr","body",a.get(u.row)),f=void 0,yield*r.takePages(),yield*Ut(s,u.row,l,r,d);else if(u.kind==="groupHeader"){const m=V(c,r.measurer,u.label,new Map,u.group.headerStyle??{},s.columns.length);f??=W(c,u.firstRow,r.measurer);const h=i.slice(u.depth+1).reduce((g,w)=>g+V(c,r.measurer,(w.headerTemplate??"{value}").replace(/\{value\}/g,R.listCellText(u.firstRow[w.field])),new Map,w.headerStyle??{},s.columns.length).heightMm,0);u.group.keepWithNext!==!1&&d.keepTogether(m.heightMm+h+f.heightMm),d.placeGridRow(m,"listg","group-header"),u.group.repeatHeader&&d.setGroupHeader(u.depth,m)}else if(u.kind==="subtotal"){const m=u.group.subtotal??[],h=u.group.aggregates??[],g=V(c,r.measurer,u.label,Je(s.columns,u.rows,m,h),u.group.subtotalStyle??{},qe(s.columns,[...m,...h.map(w=>w.field)]));d.placeGridRow(g,"listst","subtotal")}else d.setGroupHeader(u.depth);yield*r.takePages()}qt(s,o.totalRows??n,c,r,d),r.finished?.(d.bottom()),yield*r.takePages()}function re(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 oe(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(o=>({...o,...o.text===void 0?{}:{text:t(o.text)}}))}))}:{},...e.grid?{grid:{...e.grid,cells:e.grid.cells.map(r=>r.map(o=>o?{...o,...o.text===void 0?{}:{text:t(o.text)},...o.children?{children:o.children.map(n=>oe(n,t))}:{}}:null))}}:{}}}function tr(e){let t=!1;for(const r of e.pages)for(const o of r.components)re(o)&&oe(o,n=>(n.includes("{totalPages}")&&(t=!0),n));return t}function rr(e,t,r,o,n,a){const s={pageWidthMm:t.widthMm,pageHeightMm:t.heightMm,...e.layout===void 0?{}:{layout:e.layout},marginTopMm:t.marginTopMm,marginBottomMm:t.marginBottomMm,marginLeftMm:t.marginLeftMm,marginRightMm:t.marginRightMm,components:t.components,...e.meta?{meta:e.meta}:{}},i=c=>{const d=c.replace(/\{page\}/g,String(o));return a===void 0?d:d.replace(/\{totalPages\}/g,String(a))};for(const c of r)s.components.push(oe(c,i));if(e.layout==="wide"){const c=s.components.reduce((d,l)=>Math.max(d,l.topMm+l.heightMm),0);s.marginBottomMm=n?e.marginBottomMm??0:0,s.pageHeightMm=Math.max(1,c+s.marginBottomMm)}return s}function be(e){return e.cells.reduce((t,r)=>t+r.reduce((o,n)=>o+(n?1+(n.children?.reduce((a,s)=>a+Ye(s),0)??0):0),0),0)}function Ye(e){return e.grid?be(e.grid):0}function Me(e){for(const t of["maxPages","maxCells","knownTotalPages"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<1))throw new RangeError(`${t} 应为正安全整数`)}function or(e,t){const r=Xe(e,t.datasets[e.dataset]??[],t),o=ye(r.list),n={...we(o,t.measurer),rowHeightFloorMm:o.rowHeightMm??0};return(o.header===!1?0:n.headerHeightMm)+r.rows.reduce((a,s)=>a+W(n,s,t.measurer).heightMm,0)}function*nr(e){const{templatePage:t,current:r}=e,o=new Map(t.components.map((a,s)=>[a,s])),n=(a,s,i)=>{const c=e.datasets[a.dataset];return Array.isArray(c)||e.warnings.push(`数据集 ${a.dataset} 未提供数据,列表 ${a.id??""} 输出为空`),er(a,Array.isArray(c)?c:[],{...e,tableId:`${e.tableId}:${o.get(a)}`,startTop:s,finished:i,flow:!!t.flow})};if(t.flow){yield*Pt({page:t,active:()=>J(e.signal),top:()=>Math.max(r.marginTopMm,_(t)),bottom:()=>U(t,r),append:a=>{r.components.push(a)},nextPage:()=>{e.pushCurrent(),r.components=[],r.heightMm=t.heightMm,t.layout==="wide"&&(r.marginTopMm=0,r.marginBottomMm=0)},takePages:e.takePages,height:a=>or(a,e),list:n});return}for(const a of t.components)re(a)||(a.kind==="list"?yield*n(a):r.components.push(a))}function*X(e,t,r,o,n,a=new WeakMap){let s=0,i=0,c=0;const d=l=>`${l}_${(++s).toString(36)}`;for(const{pageIndex:l,page:f}of Kt(e,t,r)){J(r.signal);const u=Lt(f),m=f.components.filter(re);let h=[];const g=(y=!1)=>{if(J(r.signal),r.maxPages!==void 0&&i>=r.maxPages)throw new K(r.maxPages,i+1);if(r.maxCells!==void 0&&(c+=[...u.components,...m].reduce((v,T)=>v+Ye(T),0),c>r.maxCells))throw new B(r.maxCells,c);h.push(rr(f,u,m,++i,y,n))},w=()=>{const y=h;return h=[],y};yield*nr({templatePage:f,current:u,warnings:o,nextId:d,pushCurrent:g,takePages:w,datasets:t,signal:r.signal,formula:r.formula,prepared:a,measurer:r.measurer??D.heuristicMeasurer,mmPerRow:r.mmPerRow??0,tableId:`table:${l}`}),g(!0),yield*w()}}function ar(e,t,r={}){Me(r);let o=0;for(const n of X(e,t,{...r,onWarning:void 0},[]))o++;return o}function*Qe(e,t,r={}){Me(r);const o=tr(e),n=new WeakMap;let a=r.knownTotalPages;if(o&&a===void 0){a=0;for(const c of X(e,t,r,[],void 0,n))a++}const s=[];let i=0;for(const c of X(e,t,r,s,a,n)){for(;i<s.length;i++)r.onWarning?.(s[i]);yield c}}function ve(e,t,r={}){const o=typeof r=="number"?{mmPerRow:r}:r;Me(o);const n=[],a=[...X(e,t,o,n,o.knownTotalPages)];for(const s of a)s.components=s.components.map(i=>re(i)?oe(i,c=>c.replace(/\{totalPages\}/g,String(a.length))):i);return n.forEach(s=>o.onWarning?.(s)),{plan:{schemaVersion:Y.RENDER_PLAN_SCHEMA_VERSION,...Z(e)?{requiresRecalculation:!0}:{},pages:a},warnings:n}}function sr(e){const t=e.columns.find(a=>!a.hidden)?.field;if(!t)return{groups:0,total:0};const r=te(e),o=(a=[],s=[])=>a.includes(t)||s.some(i=>i.field===t),n=typeof e.grandTotal=="object"?e.grandTotal:void 0;return{groups:r.filter(a=>o(a.subtotal,a.aggregates)).length,total:Number(o(n?.fields??r[0]?.subtotal,n?.aggregates??r[0]?.aggregates))}}function ir(e,t,r){Ue(e);const o=Q.flattenTreeInput(t[e.dataset]??[],e.tree,r),n=e.columns.filter(s=>!s.hidden).length,a=e.header===!1?0:e.headerGrid?be(e.headerGrid):n;return o.length*n+a+ +!!e.grandTotal*2*n}function cr(e,t,r={}){if(e.tree)return ir(e,t,r.signal);if(e.matrix){let c=t[e.dataset]??[];e.computed?.length&&(c=ge.computeDataset(c,{fields:e.computed,...r}).rows),e.rowVisibleWhen&&(c=c.filter(l=>R.evalStyleRule(l,e.rowVisibleWhen)));const d=Ne.estimateMatrixTable(c,e.matrix);return d.cells+d.columnCount}const o=t[e.dataset]?.length??0,n=e.columns.filter(c=>!c.hidden).length,a=te(e).length,s=sr(e);let i=(o*(1+2*a+s.groups)+ +!!e.grandTotal*(1+s.total))*n;if(i+=e.header===!1?0:e.headerGrid?be(e.headerGrid):n,e.cardinality==="record"&&o===0&&(i+=n),e.detail){const c=t[e.detail.dataset]?.length??0,d=e.detail.columns.filter(l=>!l.hidden).length;i+=(c+o*(+(e.detail.header!==!1)+ +!!e.detail.label))*d}if(!Number.isSafeInteger(i))throw new RangeError("报表单元格估算超出安全整数预算");return i}function Ze(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function et(e,t,r){const o=e.grid;if(!o)return null;const n=o.cells[t];if(!n)return null;const s=he.resolveGridLayout(o,e.widthMm,e.heightMm).cells.filter(c=>c.ri===t).findIndex(c=>c.ci===r),i=n[s];return i?{cell:i,sourceColumnIndex:s}:null}function lr(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function dr(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 ur(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 fr(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 mr(e,t,r){if(e.derived)return;if(e.source)return{...e.source};const o=t.table?.source,n=t.table?.columnKeys[r.columnIndex];if(!(!o||o.rowKey===void 0||n===void 0))return{...o,rowKey:o.rowKey,field:n}}function tt(e,t,r){const o=lr(r),n=ur(r,e);return{address:{...t},cell:r,component:e,value:o,valueType:dr(r,o),table:fr(e,t),source:mr(r,e,t),editable:n===void 0,readOnlyReason:n}}function ne(e,t){if(!Ze(t))return null;const r=e.pages[t.pageIndex]?.components[t.componentIndex];if(!r)return null;const o=et(r,t.rowIndex,t.columnIndex);return o?tt(r,t,o.cell):null}function j(e){const t=new Map;return r=>{if(!Ze(r))return null;const o=e.pages[r.pageIndex]?.components[r.componentIndex];if(!o?.grid)return null;let n=t.get(o);if(!n){const s=new Map;n=new Map;for(const i of he.resolveGridLayout(o.grid,o.widthMm,o.heightMm).cells){const c=s.get(i.ri)??0;s.set(i.ri,c+1);const d=o.grid.cells[i.ri]?.[c];d&&n.set(`${i.ri}:${i.ci}`,d)}t.set(o,n)}const a=n.get(`${r.rowIndex}:${r.columnIndex}`);return a?tt(o,r,a):null}}class b extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function gr(e,t){let r=e.trim();const o=t&&r.endsWith("%");if(o&&(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 b("number");return Number(r)/(o?100:1)}function hr(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new b("number");const r=typeof e=="number"?e:gr(e,Ke.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new b("number");return r}function pr(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 b("boolean")}function Se(e,t){return e.valueType==="number"?hr(t,e):e.valueType==="boolean"?pr(t):t===null?null:String(t)}function wr(e,t){const r=t.cell.text,n=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(a=>a.includes(r??""));return n?n[e?0:1]:String(e)}function H(e,t){return t===null?"":typeof t=="boolean"?wr(t,e):typeof t=="number"?Ke.formatExcelNumber(t,e.cell.numberFormat):String(t)}function yr(e,t,r){const o=ne(e,t);if(!o)throw new b("missing");return q(o,r)}function q(e,t){if(!e.editable)throw new b("readonly");const r=Se(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:r,text:H(e,r)}}function br(e,t){const r=e.table,o=t.table;return!r||!o||r.columnKey===void 0?!1:r.id===o.id&&r.rowIndex===o.rowIndex&&r.role===o.role&&r.columnKey===o.columnKey}function rt(e,t,r){const o=e.grid,{rowIndex:n,columnIndex:a}=t.address,s=et(e,n,a),i=[...o.cells],c=[...i[n]],d=H(t,r.value),l={...s.cell,value:r.value,text:d,rawText:d};return c[s.sourceColumnIndex]=l,i[n]=c,{...e,grid:{...o,cells:i}}}function Mr(e,t){const r=e.table?.columnKeys,o=t.table?.columnKey;return r&&o!==void 0?r.flatMap((n,a)=>n===o?[a]:[]):[]}function vr(e,t,r,o,n,a){const s=t.table,i=n.table;if(!s||!i||s.id!==i.id||s.role!==i.role||!t.grid)return t;const c=i.rowIndex-s.rowIndex;if(c<0||c>=t.grid.cells.length)return t;let d=t;for(const l of Mr(t,n)){const f=ne(e,{pageIndex:r,componentIndex:o,rowIndex:c,columnIndex:l});f?.editable&&br(n,f)&&(d=rt(d,f,a))}return d}function Sr(e,t,r,o,n,a){const s=n.address;return n.table?.columnKey!==void 0?vr(e,t,r,o,n,a):s.pageIndex===r&&s.componentIndex===o?rt(t,n,a):t}function xe(e,t){const r=t.source;if(!r)return!1;const o=e.source;return!o||["sourceScope","datasetId","rowKey","field","revision","sourceToken"].some(n=>!Object.is(o[n],r[n]))}function xr(e,t){const r=ne(e,t.address);if(!r)throw new b("missing");if(!r.editable)throw new b("readonly");if(xe(r,t))throw new b("conflict");if(!Object.is(r.value,t.previousValue)||(r.cell.text??"")!==t.previousText)throw new b("conflict");const o=Se(r,t.value),n={...t,value:o,text:H(r,o)};if(Object.is(o,r.value)&&n.text===r.cell.text)return e;const a=e.pages.map((s,i)=>{const c=s.components.map((d,l)=>Sr(e,d,i,l,r,n));return c.every((d,l)=>d===s.components[l])?s:{...s,components:c}});return{...e,pages:a}}function ot(e){const t=[];for(const r of e.template.pages)for(const o of r.components)o.kind==="list"&&(t.push(o.tree?{...o,rowKey:o.tree.idField}:o),o.detail&&t.push({...o.detail,relation:{detail:o.detail,parentRows:e.datasets[o.dataset]??[]}}));return t}function G(e){return JSON.stringify([e.sourceScope,e.datasetId])}function Fe(e){return JSON.stringify([e.sourceScope,e.datasetId,e.rowKey])}function nt(e){const t=new Map,r=new Set;return e.forEach((o,n)=>{for(const a of ot(o)){if(!a.rowKey)continue;const s=a.relation,i=s?new Set(s.parentRows.map(c=>JSON.stringify(c[s.detail.parentKey]))):void 0;(o.datasets[a.dataset]??[]).forEach((c,d)=>{if(s&&!i.has(JSON.stringify(c[s.detail.foreignKey])))return;const l=c[a.rowKey];if(typeof l!="string"&&typeof l!="number")return;const f=`${n}:${a.dataset}:${d}:${a.rowKey}`;if(r.has(f))return;r.add(f);const u=Fe({sourceScope:o.sourceScope,datasetId:a.dataset,rowKey:l}),m=t.get(u)??[];m.push({partIndex:n,dataset:a.dataset,rowIndex:d,row:c,binding:a}),t.set(u,m)})}}),o=>{const n=t.get(Fe(o));if(!n?.length)throw new b("missing");if(new Set(n.map(a=>`${a.partIndex}:${a.dataset}`)).size!==n.length)throw new b("conflict");return n}}function at(e,t){const r=e.map(n=>({...n,datasets:{...n.datasets}})),o=new Set;for(const{row:n,field:a,value:s}of t){const i=r[n.partIndex],c=`${n.partIndex}:${n.dataset}`;o.has(c)||(i.datasets[n.dataset]=[...i.datasets[n.dataset]],o.add(c)),i.datasets[n.dataset][n.rowIndex]={...i.datasets[n.dataset][n.rowIndex],[a]:s}}return r}function Rr(e,t,r){const o=[],n=new Set;return e.forEach((a,s)=>{for(const i of ot(a))t.has(G({sourceScope:a.sourceScope,datasetId:i.dataset}))&&(a.datasets[i.dataset]??[]).forEach((c,d)=>{const l={partIndex:s,dataset:i.dataset,rowIndex:d,row:c,binding:i};for(const[f,u]of[[i.revisionField,r.revision],[i.sourceTokenField,r.sourceToken]]){if(!f||u===void 0)continue;const m=`${s}:${i.dataset}:${d}:${f}`;n.has(m)||(n.add(m),o.push({row:l,field:f,value:u}))}})}),o}function st(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const o=new Set(t.edits.flatMap(n=>n.source?[G(n.source)]:[]));return Re(e,new Map([...o].map(n=>[n,r])))}function Re(e,t){if(!t.size)return e;function r(a){const s=a.datasetId&&t.get(G({...a,datasetId:a.datasetId}));return!s||(s.revision===void 0||Object.is(s.revision,a.revision))&&(s.sourceToken===void 0||s.sourceToken===a.sourceToken)?a:{...a,...s.revision!==void 0?{revision:s.revision}:{},...s.sourceToken!==void 0?{sourceToken:s.sourceToken}:{}}}function o(a){const s=a.map(i=>{const c=i.table?.source?r(i.table.source):void 0,d=i.table&&c!==i.table.source?{...i.table,source:c}:i.table,l=i.grid?.cells.map(u=>{const m=u.map(h=>{if(!h)return h;const g=h.source?r(h.source):void 0,w=h.children?o(h.children):void 0;return g===h.source&&w===h.children?h:{...h,source:g,children:w}});return m.some((h,g)=>h!==u[g])?m:u}),f=i.grid&&l?.some((u,m)=>u!==i.grid.cells[m])?{...i.grid,cells:l}:i.grid;return d!==i.table||f!==i.grid?{...i,table:d,grid:f}:i});return s.some((i,c)=>i!==a[c])?s:a}const n=e.pages.map(a=>{const s=o(a.components);return s!==a.components?{...a,components:s}:a});return n.some((a,s)=>a!==e.pages[s])?{...e,pages:n}:e}function Tr(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function Ae(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):Tr(e.address)}function Er(e,t){if(!t.length)return e;const r=new Map(t.map(c=>[Ae(c),c])),o=new Set(t.flatMap(c=>c.table?[c.table.id]:[])),n=new Set(t.map(c=>`${c.address.pageIndex}:${c.address.componentIndex}`)),a=j(e);function s(c,d,l){const f=c.grid;if(!f||!n.has(`${d}:${l}`)&&!o.has(c.table?.id??""))return c;const u=new Map,m=new Map;for(const h of he.resolveGridLayout(f,c.widthMm,c.heightMm).cells){const g=m.get(h.ri)??0;m.set(h.ri,g+1);const w=a({pageIndex:d,componentIndex:l,rowIndex:h.ri,columnIndex:h.ci}),y=w&&r.get(Ae(w));if(!y||!w.editable)continue;const v=u.get(h.ri)??[...f.cells[h.ri]],T=H(w,y.value);Object.is(w.value,y.value)&&T===w.cell.text||(v[g]={...h.cell,value:y.value,text:T,rawText:T},u.set(h.ri,v))}return u.size?{...c,grid:{...f,cells:f.cells.map((h,g)=>u.get(g)??h)}}:c}const i=e.pages.map((c,d)=>{const l=c.components.map((f,u)=>s(f,d,u));return l.every((f,u)=>f===c.components[u])?c:{...c,components:l}});return i.every((c,d)=>c===e.pages[d])?e:{...e,pages:i}}function I(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 o=e.address;return JSON.stringify([o.pageIndex,o.componentIndex,o.rowIndex,o.columnIndex])}function Pr(e,t,r){if(typeof r!="string"||!r.trim()||!Array.isArray(t))throw new b("missing");if(t.length>1e4)throw new b("limit");const o=new Set,n=j(e),a=t.map(({address:s,value:i})=>{const c=n(s);if(!c)throw new b("missing");const d=q(c,i),l=I(d);if(o.has(l))throw new b("duplicate");return o.add(l),d});return{requestId:r,edits:a}}function Cr(e,t){if(t.edits.length>1e4)throw new b("limit");const r=j(e),o=new Set,n=t.edits.map(a=>{const s=r(a.address);if(!s)throw new b("missing");const i=I(a);if(o.has(i))throw new b("duplicate");if(o.add(i),xe(s,a)||!Object.is(s.value,a.previousValue)||(s.cell.text??"")!==a.previousText)throw new b("conflict");return q(s,a.value)});return Er(e,n)}function kr(e){const t=new Map;for(const r of e){const o=I(r),n=t.get(o),a=n?{...r,previousValue:n.previousValue,previousText:n.previousText}:{...r};Object.is(a.previousValue,a.value)?t.delete(o):t.set(o,a)}return[...t.values()]}function it(e){const t=new Map,r=j(e);return e.pages.forEach((o,n)=>o.components.forEach((a,s)=>{if(!(!a.grid||a.table?.role!=="body"))for(let i=0;i<a.grid.cells.length;i++)for(let c=0;c<a.table.columnKeys.length;c++){const d=r({pageIndex:n,componentIndex:s,rowIndex:i,columnIndex:c});d?.source&&d.editable&&t.set(I(d),d)}})),t}function $r(e,t,r){const o=it(e),n=j(e);return t.map(a=>{const s=a.source?o.get(I(a)):n(a.address);if(!s||I(s)!==I(a))throw new b("missing");return{address:{...s.address},value:a[r]}})}function ct(e,t){if(++e.nodes>1e6||t>128)throw new b("limit")}function Te(e,t){const r=Object.getOwnPropertyDescriptor(e,t);if(!r||r.get||r.set)throw new b("conflict");return r.value}function lt(e){if(Object.getOwnPropertyDescriptor(e,"toJSON"))throw new b("conflict");const t=Object.getPrototypeOf(e);if(!(e instanceof Date)&&!Array.isArray(e)&&t!==Object.prototype&&t!==null)throw new b("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 b("conflict");if(e instanceof Date||Array.isArray(e)&&!/^(0|[1-9]\d*)$/.test(r))throw new b("conflict")}}function dt(e,t,r,o,n){if(ct(o,n),typeof e=="function"||typeof e=="symbol")throw new b("conflict");if(e===null||typeof e!="object")return;if(lt(e),r.has(e))throw new b("conflict");r.add(e);const a=Object.keys(e),s=a.map(i=>Te(e,i));t.push({object:e,prototype:Object.getPrototypeOf(e),keys:a,values:s,...e instanceof Date?{date:Date.prototype.getTime.call(e)}:{},...Array.isArray(e)?{length:e.length}:{}});for(const i of s)dt(i,t,r,o,n+1);r.delete(e)}function Ir(e){const{object:t,keys:r,values:o}=e;if(lt(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 n=Object.keys(t);return n.length===r.length&&r.every((a,s)=>n[s]===a&&Object.is(Te(t,a),o[s]))}function Or(e){const t=[];return dt(e,t,new Set,{nodes:0},0),()=>{try{return t.every(Ir)}catch{return!1}}}function de(e,t,r){return ct(t,r),e===null||typeof e!="object"?e:e instanceof Date?new Date(Date.prototype.getTime.call(e)):Array.isArray(e)?e.map(o=>de(o,t,r+1)):Object.fromEntries(Object.keys(e).map(o=>[o,de(Te(e,o),t,r+1)]))}function Fr(e){return de(e,{nodes:0},0)}async function ut(e,t,r={}){const o=[],n={...r,knownTotalPages:void 0};for(const a of Qe(e,t,n))o.push(a),o.length%8===0&&await new Promise(s=>setTimeout(s,0));if(r.signal?.aborted){const a=new Error("报表重算已取消");throw a.name="AbortError",a}return{schemaVersion:Y.RENDER_PLAN_SCHEMA_VERSION,...Z(e)?{requiresRecalculation:!0}:{},pages:o}}const ue=new WeakMap;function Ar(e){return ue.get(e)}function z(e){if(e?.aborted){const t=new Error("报表重算已取消");throw t.name="AbortError",t}}function ft(e,t){return e[t]===void 0?"":e[t]}function Nr(e,t){if(t.edits.length>1e4)throw new b("limit");const r=j(e),o=new Set,n=[],a=t.edits.map(s=>{const i=r(s.address);if(!i?.source)throw new b("missing");const c=I(s);if(o.has(c))throw new b("duplicate");if(o.add(c),xe(i,s)||!Object.is(i.value,s.previousValue)||(i.cell.text??"")!==s.previousText)throw new b("conflict");return n.push(i),q(i,s.value)});return{batch:{requestId:t.requestId,edits:a},contexts:n}}function Kr(e,t){const r=nt(e);return t.flatMap(o=>{if(!o.source)throw new b("missing");return r(o.source).map(n=>{if(!Object.is(ft(n.row,o.source.field),o.previousValue))throw new b("conflict");if(n.binding.rowKey===o.source.field)throw new b("readonly");return{row:n,field:o.source.field,value:o.value}})})}function ce(e,t,r){const o={...e,value:t,source:{...e.source,...r?.revision===void 0?{}:{revision:r.revision},...r?.sourceToken===void 0?{}:{sourceToken:r.sourceToken}}};return o.cell={...e.cell,value:o.value,text:H(o,o.value)},o}function Lr(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return[...e];const o=new Set(t.edits.flatMap(n=>n.source?[G(n.source)]:[]));return at(e,Rr(e,o,r))}function jr(e,t,r){const o=new Set(t.edits.map(n=>G(n.source)));for(const n of o)e.set(n,{...e.get(n),...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}});return o}function Ee(e,t){let r=t.parts;const o=t.rebuild;let n=Or(r),a=e,s;const i=new Map,c=new Map;function d(u){if(u!==a)throw new b("conflict");if(s)return s;if(!n?.())throw new b("conflict");return Fr(r)}async function l(u,m,h,g={}){z(g.signal),m={requestId:m.requestId,edits:m.edits.map(S=>({...S,address:{...S.address},source:S.source?{...S.source}:void 0,table:S.table?{...S.table}:void 0}))},h=h.map(S=>({...S,address:{...S.address},source:S.source?{...S.source}:void 0,table:S.table?{...S.table}:void 0,cell:{...S.cell}})),await new Promise(S=>setTimeout(S,0)),z(g.signal);const w=d(u),y=at(w,Kr(w,m.edits)),v=Re(await o(y,g.signal),c);z(g.signal);let T=!1;return{plan:v,commit(S){if(z(g.signal),T||a!==u)throw new b("conflict");if(S?.conflicts?.length)throw new b("conflict");const N=Lr(y,m,S),F=st(v,m,S);if(S){const O=jr(c,m,S);for(const[p,M]of i)O.has(G(M.source))&&i.set(p,ce(M,M.value,S))}return h.forEach((O,p)=>i.set(I(O),ce(O,m.edits[p].value,S))),T=!0,s=N,r=void 0,n=void 0,a=F,ue.set(a,f),a}}}const f={get plan(){return a},async prepare(u,m,h){const g=Nr(u,m);return l(u,g.batch,g.contexts,h)},async prepareHistory(u,m,h,g,w){if(!g.trim()||m.length>1e4)throw new b("limit");const y=d(u),v=nt(y),T=it(u),S=new Set,F=m.map(M=>{if(!M.source)throw new b("missing");const x=I(M);if(S.has(x))throw new b("duplicate");S.add(x);const P=T.get(x)??i.get(x);if(!P?.source)throw new b("missing");const k=v(P.source)[0];return ce(P,ft(k.row,P.source.field))}).map((M,x)=>({context:M,edit:q(M,m[x][h])})).filter(({edit:M})=>!Object.is(M.previousValue,M.value)),O={requestId:g,edits:F.map(({edit:M})=>M)},p=F.map(({context:M})=>M);return{batch:O,contexts:p,prepared:await l(u,O,p,w)}}};return ue.set(e,f),f}function Br(e){const t=ve(e.template,e.datasets,e.pagination).plan;return Ee(t,{parts:[{template:e.template,datasets:e.datasets}],rebuild:(r,o)=>ut(r[0].template,r[0].datasets,{...e.pagination,signal:o})})}let Dr=0;function mt(){return`report-${Date.now()}-${++Dr}`}function fe(e,t,r){if(!r?.aborted)try{const o=e?.({...t});o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}function gt(e){const t=e.taskId??mt(),r=(o,n,a)=>{fe(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:n,...a===void 0?{}:{reportId:a}},e.signal)};return{taskId:t,progress(o,n,a){fe(e.onEvent,{taskId:t,...e.correlationId===void 0?{}:{correlationId:e.correlationId},stage:o,status:"started",completed:n,total:a},e.signal)},async run(o,n,a){r(o,"started",a);try{const s=await n();return r(o,"completed",a),s}catch(s){throw r(o,"failed",a),s}},runSync(o,n,a){r(o,"started",a);try{const s=n();return r(o,"completed",a),s}catch(s){throw r(o,"failed",a),s}}}}function ht(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e,r=o=>typeof o=="string"&&o.trim().length>0&&o.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 pt(e){return e==="missing-source"||e==="not-applicable"||e==="not-calculable"}function wt(e){return e.target!==void 0&&!ht(e.target)?!1:e.valueState===void 0||pt(e.valueState)&&e.target!==void 0}function Pe(e,t,r={}){const o=new Map;for(const a of e.pages)for(const s of a.components){if(s.kind!=="list"||s.tree?.input!=="nested")continue;const i=o.get(s.dataset);if(i&&(i.childrenField??"children")!==(s.tree.childrenField??"children"))throw new Error("同一数据集的嵌套树应使用相同 childrenField");o.set(s.dataset,s.tree)}if(!o.size)return t;const n={...t};for(const[a,s]of o){const i=Math.min(s.maxRows??1e5,r.maxRows??1/0);n[a]=Q.flattenTreeInput(t[a]??[],{...s,maxRows:i},r.signal)}return n}function Hr(e,t,r={}){return Object.values(Pe(e,t,r)).reduce((o,n)=>o+n.length,0)}function Gr(e,t,r){const o=Le.datasetJsonSchema(r),n=e?.pages.flatMap(i=>i.components).find(i=>i.kind==="list"&&i.dataset===t&&i.tree?.input==="nested");if(!n||n.kind!=="list"||!n.tree)return o;const a=o.items,s=n.tree.childrenField??"children";return{...o,items:{$ref:"#/$defs/treeNode"},$defs:{treeNode:{...a,properties:{...a.properties,[s]:{anyOf:[{type:"null"},{type:"array",items:{$ref:"#/$defs/treeNode"}}]}}}}}}function Ce(e,t){return JSON.stringify([e,t])}function yt(e,t,r){return r===void 0?Ce(e,t):JSON.stringify(["shared",r])}function bt(e,t,r){return e.map(o=>{const n=o.table?{...o.table,id:r(o.table.id),...o.table.source?{source:{...o.table.source,sourceScope:t}}:{}}:void 0,a=o.grid?.cells.map(s=>s.map(i=>!i||!i.source&&!i.children?i:{...i,...i.source?{source:{...i.source,sourceScope:t}}:{},...i.children?{children:bt(i.children,t,r)}:{}}));return n||a?{...o,...n?{table:n}:{},...a?{grid:{...o.grid,cells:a}}:{}}:o})}function Vr(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...o}=e;return{...o,load:async n=>{const a=await t(n);$(n.signal);try{return r(a,n)}catch(s){throw new E("validate",`报表 ${n.reportId} 数据映射失败`,s)}}}}class E extends Error{constructor(t,r,o){super(r),this.name="ReportSourceError",this.code=t,this.cause=o}}function ae(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function $(e){if(e?.aborted)throw ae(e)}function me(e,t){return t?new Promise((r,o)=>{const n=()=>t.removeEventListener("abort",a),a=()=>{n(),o(ae(t))};t.addEventListener("abort",a,{once:!0}),t.aborted&&a(),Promise.resolve(e).then(s=>{n(),r(s)},s=>{n(),o(s)})}):Promise.resolve(e)}function _r(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new E("validate",`报表 ${t} 的数据集应为对象`);for(const[r,o]of Object.entries(e))if(!Array.isArray(o)||o.some(n=>!n||typeof n!="object"||Array.isArray(n)))throw new E("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function Wr(e,t,r){const{reportId:o,signal:n}=t;try{const a=await me(e(t),n);$(n);const s=L.validateReportTemplate(a);if(!s.ok)throw new E("validate",`报表 ${o} 模板校验失败:${s.errors.slice(0,3).map(i=>`${i.path}: ${i.message}`).join("; ")}`);return r.push(...s.warnings.map(i=>`${o}: ${i.path}: ${i.message}`)),a}catch(a){throw n?.aborted?ae(n):a instanceof E?a:a instanceof L.ReportTemplateError?new E("validate",`报表 ${o} 模板校验失败:${a.message}`,a):new E("fetch",`报表 ${o} 模板加载失败:${a instanceof Error?a.message:String(a)}`,a)}}async function Jr(e,t,r,o){const n=t.signal;let a;try{if(e.load)a=await me(e.load(t),n);else if(e.provider){const s=await me(e.provider.query(t),n);$(n),qr(s,r),a=s.datasets,o?.(r,s)}else a=e.datasets??{}}catch(s){throw n?.aborted?ae(n):s instanceof E?s:new E("fetch",`报表 ${r} 取数失败:${s instanceof Error?s.message:String(s)}`,s)}return $(n),a}function qr(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new E("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new E("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 E("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`);if(e.diagnostics?.some(r=>!wt(r)))throw new E("validate",`报表 ${t} Provider 数据说明缺少有效的字段身份或值状态`)}function zr(e,t,r,o,n){try{t=Pe(o,t,{maxRows:e.dataValidation?.maxRows,signal:n})}catch(a){throw new E("validate",`报表 ${r} 树形数据无效:${a instanceof Error?a.message:String(a)}`,a)}for(const[a,s]of Object.entries(e.dataSchema??{})){let i;try{i=Le.validateDatasetRows(Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0,s,{...e.dataValidation,path:`$.datasets.${a}`})}catch(c){throw new E("config",`报表 ${r} 数据集 ${a} 字段契约配置无效`,c)}if(!i.ok)throw new E("validate",`报表 ${r} 数据集 ${a} 不符合字段契约:${i.issues[0]?.message}`,{issues:i.issues})}}function Mt(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 vt(e){const t=r=>r.grid?.cells.reduce((o,n)=>o+n.reduce((a,s)=>a+(s?1+(s.children?.reduce((i,c)=>i+t(c),0)??0):0),0),0)??0;return e.pages.reduce((r,o)=>r+o.components.reduce((n,a)=>n+t(a),0),0)}function St(e,t,r,o){return{...e,signal:o??e?.signal,...t===void 0?{}:{maxPages:Math.max(1,Math.min(t,e?.maxPages??t))},...r===void 0?{}:{maxCells:Math.max(1,Math.min(r,e?.maxCells??r))}}}function Ur(e,t,r,o,n,a){const s=n.maxPages===void 0?void 0:n.maxPages-n.usedPages,i=n.maxCells===void 0?void 0:n.maxCells-n.usedCells;try{if(s!==void 0&&s<1&&e.pages.length&&!Mt(e,t))throw new K(0,1);const c=St(r.pagination,s,i,a),d=ve(e,t,c),l=vt(d.plan);if(i!==void 0&&l>i)throw new B(i,l);return{...d,cells:l}}catch(c){let d=c;throw c instanceof K&&n.maxPages!==void 0&&c.limit===s&&(d=new K(n.maxPages,n.usedPages+c.actual)),c instanceof B&&n.maxCells!==void 0&&(d=new B(n.maxCells,n.usedCells+c.actual)),new E("validate",`报表 ${o} 排版失败:${d instanceof Error?d.message:String(d)}`,d)}}function xt(e,t,r,o,n){const a=new Map,s=i=>{let c=a.get(i);return c===void 0&&(c=JSON.stringify([r,o,i]),a.set(i,c)),c};for(const i of t.pages)e.push({...i,meta:{...i.meta,reportScope:Ce(r,o)},components:bt(i.components,n??yt(r,o),s)})}async function Xr(e,t,r,o,n){const a=[];let s=0;for(const[d,l]of e.entries()){$(n);const f=o.maxPages===void 0?void 0:o.maxPages-a.length,u=o.maxCells===void 0?void 0:o.maxCells-s;if(f!==void 0&&f<1&&l.template.pages.length&&!Mt(l.template,l.datasets))throw new K(o.maxPages,a.length+1);const m=await ut(l.template,l.datasets,St(t[d]?.pagination,f,u,n));if(s+=vt(m),o.maxCells!==void 0&&s>o.maxCells)throw new B(o.maxCells,s);xt(a,m,d,r[d],l.sourceScope)}const i={schemaVersion:Y.RENDER_PLAN_SCHEMA_VERSION,...e.some(d=>Z(d.template))?{requiresRecalculation:!0}:{},pages:a},c=L.validateRenderPlan(i);if(!c.ok)throw new E("validate",`重算渲染计划校验失败:${c.errors[0]?.message}`);return i}function Yr(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new E("config","maxPages 应为正安全整数");if(t.maxCells!==void 0&&(!Number.isSafeInteger(t.maxCells)||t.maxCells<1))throw new E("config","maxCells 应为正安全整数");function r(n){const a=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(!a)throw new E("config",`未注册报表 ${n}`);if(a.sourceScope!==void 0&&(typeof a.sourceScope!="string"||!a.sourceScope.trim()||a.sourceScope.length>512))throw new E("config","sourceScope 应为不超过 512 字符的非空字符串");return a}return Object.assign(async({reportIds:n,params:a,signal:s,onWarning:i,onQueryResult:c,...d})=>{$(s);const l=gt({...d,signal:s}),f=[...n],u={...a};if(f.length===0)throw new E("config","缺少报表 ID");const m=f.map(r),h=l.runSync("validate",()=>m.map(p=>$e.assertReportParams(p.params??(typeof p.template=="function"?[]:p.template.params)??[],u))),g=[],w=[];let y=0;const v=[];for(const[p,M]of m.entries()){$(s);const x=f[p],P={reportId:x,params:h[p],signal:s},k=typeof M.template=="function"?await l.run("query",()=>Wr(M.template,P,v),x):M.template;P.params=l.runSync("validate",()=>$e.assertReportParams(M.params??k.params??[],P.params),x);const A=await l.run("query",()=>Jr(M,P,x,(ie,Rt)=>c?.(ie,Rt,p)),x);l.runSync("validate",()=>{_r(A,x),t.onDatasets?.(x,A,k),zr(M,A,x,k,s)},x),$(s);const se=l.runSync("layout",()=>Ur(k,A,M,x,{maxPages:t.maxPages,usedPages:g.length,maxCells:t.maxCells,usedCells:y},s),x);y+=se.cells;const ke=yt(p,x,M.sourceScope);w.push({template:k,datasets:A,sourceScope:ke}),xt(g,se.plan,p,x,ke),v.push(...se.warnings.map(ie=>`${x}: ${ie}`))}$(s);const T={schemaVersion:Y.RENDER_PLAN_SCHEMA_VERSION,...w.some(p=>Z(p.template))?{requiresRecalculation:!0}:{},pages:g},S=l.runSync("validate",()=>{const p=L.validateRenderPlan(T);if(!p.ok)throw new E("validate",`渲染计划校验失败:${p.errors.slice(0,3).map(M=>`${M.path}: ${M.message}`).join("; ")}`);return p});v.push(...S.warnings.map(p=>`${p.path}: ${p.message}`));const N=m.map(p=>({...p,pagination:{...p.pagination}})),F={maxPages:t.maxPages,maxCells:t.maxCells};try{Ee(T,{parts:w,rebuild:(p,M)=>Xr(p,N,f,F,M)})}catch{v.push("来源数据无法建立本地重算口径;当前预览仅支持计划内编辑,请使用可序列化模板数据启用规则重算")}const O=i??t.onWarning??(p=>console.warn("[mach-report]",p));for(const p of v)$(s),O(p);return $(s),T},{getParamDefs:n=>Tt.getReportParamDefs(e,n)})}function Qr(e,t){const r=t.maxNodes??1e6;if(![t.maxBytes,r].every(l=>Number.isSafeInteger(l)&&l>0))throw t.error("budget","快照预算应为正安全整数");let o=0,n=0;const a=new Set;function s(l){if(n+=l,n>t.maxBytes)throw t.error("budget","快照超过字节预算")}function i(l,f){if(++o>r||f>64)throw t.error("budget","快照节点或深度超过预算");if(o%1024===0&&t.check?.(),typeof l=="string")return s(l.length+2),l;if(l===null||typeof l=="boolean"||typeof l=="number"&&Number.isFinite(l))return s(String(l).length),l;if(!l||typeof l!="object"||a.has(l))throw t.error("input","快照应为无循环的有限 JSON 值");return c(l,f)}function c(l,f){const u=Array.isArray(l),m=Object.getPrototypeOf(l);if(m!==(u?Array.prototype:Object.prototype)&&!(m===null&&!u)||Object.getOwnPropertySymbols(l).length)throw t.error("input","快照应为普通 JSON 对象");const h=Object.getOwnPropertyNames(l).filter(y=>!(u&&y==="length"));if(u&&(h.length!==l.length||h.some((y,v)=>y!==String(v))))throw t.error("input","快照数组应为连续数组");a.add(l),s(2);const g=Object.create(null);let w=0;for(const y of h){const v=Object.getOwnPropertyDescriptor(l,y);if(v.get||v.set||!v.enumerable||["__proto__","constructor","prototype"].includes(y))throw t.error("input","快照不允许访问器或危险键");v.value===void 0&&!u||(s((w++?1:0)+(u?0:y.length+3)),g[y]=i(v.value===void 0?null:v.value,f+1))}return a.delete(l),u?h.map(y=>g[y]):g}t.check?.();const d=JSON.stringify(i(e,0));if(new TextEncoder().encode(d).byteLength>t.maxBytes)throw t.error("budget","快照超过字节预算");return JSON.parse(d)}exports.DEFAULT_LABEL_PAGE_LIMIT=Be;exports.PaginateCellLimitError=B;exports.PaginatePageLimitError=K;exports.ReportCellEditError=b;exports.ReportSourceError=E;exports.applyReportCellEdit=xr;exports.applyReportCellEditBatch=Cr;exports.applyReportEditResult=st;exports.applyReportSourceMetadata=Re;exports.countTemplatePages=ar;exports.createReportCellEdit=yr;exports.createReportCellEditBatch=Pr;exports.createReportCellResolver=j;exports.createReportEditSession=Br;exports.createReportSource=Yr;exports.createReportTaskReporter=gt;exports.defineReport=Vr;exports.estimateListLayoutCells=cr;exports.formatReportCellEdit=H;exports.getReportCellContext=ne;exports.getReportEditSession=Ar;exports.hasValidDataExplanation=wt;exports.isReportDataTarget=ht;exports.isReportValueState=pt;exports.notifyReportTaskEvent=fe;exports.paginateTemplate=ve;exports.paginateTemplatePages=Qe;exports.parseReportCellInput=Se;exports.projectListColumns=je;exports.registerReportEditSession=Ee;exports.relocateReportCellEdits=$r;exports.reportCellEditKey=I;exports.reportOccurrenceScope=Ce;exports.reportTaskId=mt;exports.snapshotReportJson=Qr;exports.summarizeReportCellEdits=kr;exports.templateDatasetJsonSchema=Gr;exports.templateDatasetRowCount=Hr;exports.templateValidationDatasets=Pe;
@@ -1,112 +0,0 @@
1
- import { c as h } from "./computed-C-4C2S5h.js";
2
- function y(l, e) {
3
- const r = () => e.measures.map((c) => h(c)), t = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = e.totals ? r() : void 0, n = (c, s) => c?.forEach((o) => o.add(s));
4
- for (const c of l) {
5
- const s = e.row(c), o = e.column(c);
6
- f.has(o.key) || f.set(o.key, o.label);
7
- let u = t.get(s.key);
8
- u || (u = { label: s.label, cells: /* @__PURE__ */ new Map(), ...e.totals ? { totals: r() } : {} }, t.set(s.key, u)), e.check(t.size, f.size);
9
- let w = u.cells.get(o.key);
10
- if (w || (w = r(), u.cells.set(o.key, w)), n(w, c), !e.totals) continue;
11
- let d = i.get(o.key);
12
- d || (d = r(), i.set(o.key, d)), n(u.totals, c), n(d, c), n(a, c);
13
- }
14
- return { groups: t, columns: f, columnTotals: i, totals: a };
15
- }
16
- function m(l, e) {
17
- const r = e.map(
18
- (t) => Object.prototype.hasOwnProperty.call(l, t) ? l[t] : null
19
- );
20
- if (r.some(
21
- (t) => t != null && typeof t != "string" && typeof t != "boolean" && !(typeof t == "number" && Number.isFinite(t))
22
- ))
23
- throw new Error("矩阵维度必须是有限 JSON 标量");
24
- return {
25
- key: JSON.stringify(r.map((t) => [typeof t, t ?? null])),
26
- label: r.map((t) => t == null ? "" : String(t)).join(" / ")
27
- };
28
- }
29
- function g(l) {
30
- for (const e of [
31
- "maxRows",
32
- "maxColumns",
33
- "maxInputRows",
34
- "maxCells"
35
- ])
36
- if (l[e] !== void 0 && (!Number.isSafeInteger(l[e]) || l[e] < 1))
37
- throw new Error("矩阵预算应为正安全整数");
38
- for (const e of ["columnWidthMm", "rowWidthMm"])
39
- if (l[e] !== void 0 && (!Number.isFinite(l[e]) || l[e] <= 0))
40
- throw new Error("矩阵列宽应为正数");
41
- }
42
- function b(l) {
43
- if (!l || !Array.isArray(l.rowFields) || !Array.isArray(l.columnFields) || !Array.isArray(l.measures))
44
- throw new Error("矩阵需要行维度、列维度和度量数组");
45
- for (const r of [l.rowFields, l.columnFields])
46
- if (r.some((t) => typeof t != "string" || !t.trim()) || new Set(r).size !== r.length)
47
- throw new Error("矩阵维度字段应非空且唯一");
48
- if (g(l), !l.rowFields.length || !l.columnFields.length || l.rowFields.length > 16 || l.columnFields.length > 16)
49
- throw new Error("矩阵需要 1–16 个行/列维度");
50
- if (!l.measures.length || l.measures.length > 32)
51
- throw new Error("矩阵需要 1–32 个度量");
52
- if (l.measures.map((r) => {
53
- if (!r || typeof r != "object") throw new Error("矩阵度量应为对象");
54
- if (h({
55
- ...r,
56
- field: r.valueField ?? r.field
57
- }), r.label !== void 0 && typeof r.label != "string")
58
- throw new Error("矩阵度量标签应为字符串");
59
- return r.field;
60
- }).some((r) => typeof r != "string" || !r.trim()))
61
- throw new Error("矩阵度量字段应非空");
62
- }
63
- function k(l, e) {
64
- if (b(e), !Array.isArray(l) || l.length > (e.maxInputRows ?? 1e5))
65
- throw new Error("矩阵输入超出预算");
66
- const r = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
67
- for (const a of l) {
68
- if (!a || typeof a != "object" || Array.isArray(a))
69
- throw new Error("矩阵数据行应为对象");
70
- if (r.add(m(a, e.rowFields).key), t.add(m(a, e.columnFields).key), r.size > (e.maxRows ?? 1e3) || t.size > (e.maxColumns ?? 200))
71
- throw new Error("矩阵维度数量超出预算");
72
- if ((r.size + +!!e.totals) * ((t.size + +!!e.totals) * e.measures.length + 1) > (e.maxCells ?? 2e6))
73
- throw new Error("矩阵输出超出 maxCells 预算");
74
- }
75
- const f = r.size + +(!!e.totals && l.length > 0), i = (t.size + +!!e.totals) * e.measures.length + 1;
76
- return { rowCount: f, columnCount: i, cells: f * i };
77
- }
78
- function E(l, e) {
79
- k(l, e);
80
- const r = y(l, {
81
- row: (a) => m(a, e.rowFields),
82
- column: (a) => m(a, e.columnFields),
83
- measures: e.measures.map((a) => ({ ...a, field: a.valueField ?? a.field })),
84
- totals: e.totals,
85
- check: () => {
86
- }
87
- // Cardinality/budgets were checked before allocating accumulators.
88
- }), t = [...r.groups.values()].map((a) => ({ rowLabel: a.label })), f = [{ field: "rowLabel", header: e.rowHeader ?? e.rowFields.join(" / "), semanticRole: "dimension" }], i = { rowLabel: "合计" };
89
- return e.measures.forEach((a, n) => {
90
- const c = [...r.columns.entries()].map(([s, o], u) => ({ key: s, label: o, field: `c${u}_${n}` }));
91
- e.totals && c.push({ key: "", label: "合计", field: `total_${n}` });
92
- for (const s of c) {
93
- const o = s.field === `total_${n}`;
94
- f.push({
95
- field: s.field,
96
- header: `${s.label} · ${a.label ?? `${a.field} (${a.op})`}`,
97
- semanticRole: "measure",
98
- ...a.digits === void 0 ? {} : { format: { kind: "number", digits: a.digits } }
99
- });
100
- let u = 0;
101
- for (const w of r.groups.values())
102
- t[u++][s.field] = (o ? w.totals?.[n] : w.cells.get(s.key)?.[n])?.value() ?? (a.op === "count" ? 0 : null);
103
- i[s.field] = (o ? r.totals?.[n] : r.columnTotals.get(s.key)?.[n])?.value() ?? (a.op === "count" ? 0 : null);
104
- }
105
- }), e.totals && l.length && t.push(i), { rows: t, columns: f };
106
- }
107
- export {
108
- y as a,
109
- E as c,
110
- k as e,
111
- b as v
112
- };
@@ -1 +0,0 @@
1
- "use strict";const h=require("./computed-CGV2a809.cjs");function g(r,e){const l=()=>e.measures.map(c=>h.createAggregateAccumulator(c)),t=new Map,u=new Map,i=new Map,a=e.totals?l():void 0,n=(c,s)=>c?.forEach(o=>o.add(s));for(const c of r){const s=e.row(c),o=e.column(c);u.has(o.key)||u.set(o.key,o.label);let f=t.get(s.key);f||(f={label:s.label,cells:new Map,...e.totals?{totals:l()}:{}},t.set(s.key,f)),e.check(t.size,u.size);let w=f.cells.get(o.key);if(w||(w=l(),f.cells.set(o.key,w)),n(w,c),!e.totals)continue;let d=i.get(o.key);d||(d=l(),i.set(o.key,d)),n(f.totals,c),n(d,c),n(a,c)}return{groups:t,columns:u,columnTotals:i,totals:a}}function m(r,e){const l=e.map(t=>Object.prototype.hasOwnProperty.call(r,t)?r[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 k(r){for(const e of["maxRows","maxColumns","maxInputRows","maxCells"])if(r[e]!==void 0&&(!Number.isSafeInteger(r[e])||r[e]<1))throw new Error("矩阵预算应为正安全整数");for(const e of["columnWidthMm","rowWidthMm"])if(r[e]!==void 0&&(!Number.isFinite(r[e])||r[e]<=0))throw new Error("矩阵列宽应为正数")}function y(r){if(!r||!Array.isArray(r.rowFields)||!Array.isArray(r.columnFields)||!Array.isArray(r.measures))throw new Error("矩阵需要行维度、列维度和度量数组");for(const l of[r.rowFields,r.columnFields])if(l.some(t=>typeof t!="string"||!t.trim())||new Set(l).size!==l.length)throw new Error("矩阵维度字段应非空且唯一");if(k(r),!r.rowFields.length||!r.columnFields.length||r.rowFields.length>16||r.columnFields.length>16)throw new Error("矩阵需要 1–16 个行/列维度");if(!r.measures.length||r.measures.length>32)throw new Error("矩阵需要 1–32 个度量");if(r.measures.map(l=>{if(!l||typeof l!="object")throw new Error("矩阵度量应为对象");if(h.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("矩阵度量字段应非空")}function b(r,e){if(y(e),!Array.isArray(r)||r.length>(e.maxInputRows??1e5))throw new Error("矩阵输入超出预算");const l=new Set,t=new Set;for(const a of r){if(!a||typeof a!="object"||Array.isArray(a))throw new Error("矩阵数据行应为对象");if(l.add(m(a,e.rowFields).key),t.add(m(a,e.columnFields).key),l.size>(e.maxRows??1e3)||t.size>(e.maxColumns??200))throw new Error("矩阵维度数量超出预算");if((l.size+ +!!e.totals)*((t.size+ +!!e.totals)*e.measures.length+1)>(e.maxCells??2e6))throw new Error("矩阵输出超出 maxCells 预算")}const u=l.size+ +(!!e.totals&&r.length>0),i=(t.size+ +!!e.totals)*e.measures.length+1;return{rowCount:u,columnCount:i,cells:u*i}}function x(r,e){b(r,e);const l=g(r,{row:a=>m(a,e.rowFields),column:a=>m(a,e.columnFields),measures:e.measures.map(a=>({...a,field:a.valueField??a.field})),totals:e.totals,check:()=>{}}),t=[...l.groups.values()].map(a=>({rowLabel:a.label})),u=[{field:"rowLabel",header:e.rowHeader??e.rowFields.join(" / "),semanticRole:"dimension"}],i={rowLabel:"合计"};return e.measures.forEach((a,n)=>{const c=[...l.columns.entries()].map(([s,o],f)=>({key:s,label:o,field:`c${f}_${n}`}));e.totals&&c.push({key:"",label:"合计",field:`total_${n}`});for(const s of c){const o=s.field===`total_${n}`;u.push({field:s.field,header:`${s.label} · ${a.label??`${a.field} (${a.op})`}`,semanticRole:"measure",...a.digits===void 0?{}:{format:{kind:"number",digits:a.digits}}});let f=0;for(const w of l.groups.values())t[f++][s.field]=(o?w.totals?.[n]:w.cells.get(s.key)?.[n])?.value()??(a.op==="count"?0:null);i[s.field]=(o?l.totals?.[n]:l.columnTotals.get(s.key)?.[n])?.value()??(a.op==="count"?0:null)}}),e.totals&&r.length&&t.push(i),{rows:t,columns:u}}exports.accumulatePivotRows=g;exports.createMatrixTable=x;exports.estimateMatrixTable=b;exports.validateMatrixOptions=y;
@@ -1 +0,0 @@
1
- "use strict";function v(e){const t=[];return e.optionsSource!==void 0&&((e.type!=="select"||typeof e.optionsSource!="string"||!/^[\w][\w.:-]{0,127}$/.test(e.optionsSource))&&t.push("远程选项来源应为 select 的有效来源键(最多 128 字符)"),e.options!==void 0&&t.push("远程选项来源与静态选项不能同时配置")),e.dependsOn!==void 0&&(!e.optionsSource||!Array.isArray(e.dependsOn)||e.dependsOn.length>32||e.dependsOn.some(n=>typeof n!="string"||!n)||new Set(e.dependsOn).size!==e.dependsOn.length)&&t.push("联动依赖应为远程选项的最多 32 个唯一参数名"),t}function Y(e){const t=new Map(e.map((i,s)=>[i.field,{def:i,index:s,degree:0,children:[]}])),n=[];for(const i of t.values())for(const s of i.def.dependsOn??[]){const o=t.get(s);if(!o){n.push({index:i.index,message:`联动依赖参数 ${s} 未声明`});continue}i.degree++,o.children.push(i.def.field)}const r=[...t.values()].filter(i=>i.degree===0);for(let i=0;i<r.length;i++)for(const s of r[i].children){const o=t.get(s);--o.degree===0&&r.push(o)}for(const i of t.values())i.degree>0&&n.push({index:i.index,message:"联动依赖不能形成循环"});return n}function p(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e)||e.startsWith("0000-"))return!1;const t=new Date(`${e}T00:00:00.000Z`);return Number.isFinite(t.getTime())&&t.toISOString().slice(0,10)===e}function m(e){return e.length===4&&/^\d{4}$/.test(e)&&e!=="0000"}function f(e){return e.length===7&&/^\d{4}-(?:0[1-9]|1[0-2])$/.test(e)&&m(e.slice(0,4))}function c(e){const[t,n,r]=e.split("/");if(!(r!==void 0||!t||!n||!p(t)||!p(n)||t>n))return{start:t,end:n}}function D(e){const t=`${e.start}/${e.end}`;if(!c(t))throw new RangeError("日期范围必须为完整且有序的 YYYY-MM-DD/YYYY-MM-DD");return t}function b(e,t){return typeof t!="string"?!1:e==="month"?f(t):e==="year"?m(t):(e==="date"||e==="dateRange")&&p(t)}function L(e,t){if(e==="date"&&!p(t))return"应为有效的 YYYY-MM-DD 日期";if(e==="month"&&!f(t))return"应为有效的 YYYY-MM 月份";if(e==="year"&&!m(t))return"应为 0001 至 9999 的四位年份";if(e==="dateRange"&&!c(t))return"应为完整且有序的 YYYY-MM-DD/YYYY-MM-DD 日期范围"}class y extends Error{constructor(t){super(t.map(n=>`${n.field}: ${n.message}`).join("; ")),this.issues=t,this.code="params",this.name="ReportParamValidationError"}}function x(e){return/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(e)&&Number.isFinite(Number(e))}function R(e,t){if(e.type==="number"&&!x(t))return[["type","应为有限数字"]];const n=L(e.type,t);if(n)return[["type",n]];const r=[];e.type==="select"&&e.options&&!e.options.some(s=>s.value===t)&&r.push(["option","不在允许的选项中"]);const i=Array.from(t).length;return e.minLength!==void 0&&i<e.minLength&&r.push(["minLength",`至少 ${e.minLength} 个字符`]),e.maxLength!==void 0&&i>e.maxLength&&r.push(["maxLength",`最多 ${e.maxLength} 个字符`]),r.push(...O(e,t)),r}function O(e,t){const n=e.type==="dateRange"?c(t):void 0,r=n?.start??(e.type==="number"?Number(t):t),i=n?.end??r,s=[];return e.min!==void 0&&r<e.min&&s.push(["minimum",`不能小于 ${e.min}`]),e.max!==void 0&&i>e.max&&s.push(["maximum",`不能大于 ${e.max}`]),s}function S(e){const t=[];for(const i of["min","max"]){const s=e[i];if(s===void 0)continue;b(e.type,s)||e.type==="number"&&typeof s=="number"&&Number.isFinite(s)||t.push(`${i} 应为数字的有限边界或日期/月/年的规范字符串边界`)}const n=typeof e.min=="number"&&typeof e.max=="number"&&e.min>e.max,r=typeof e.min=="string"&&typeof e.max=="string"&&e.min>e.max;return(n||r)&&t.push("最小边界不能大于最大边界"),[...t,...w(e)]}function w(e){const t=[];e.type==="number"&&(e.minLength!==void 0||e.maxLength!==void 0)&&t.push("number 参数使用 min/max 而不是文本长度约束");for(const n of["minLength","maxLength"]){const r=e[n];r!==void 0&&(!Number.isSafeInteger(r)||r<0)&&t.push(`${n} 应为非负整数`)}return typeof e.minLength=="number"&&typeof e.maxLength=="number"&&e.minLength>e.maxLength&&t.push("最小长度不能大于最大长度"),t}function d(e){if(!Array.isArray(e))return[{code:"definition",field:"",path:"$.paramDefs",message:"参数定义应为数组"}];const t=new Set,n=e.flatMap((r,i)=>{const s=r&&typeof r.field=="string"?r.field:"";return P(r,t).map(a=>({code:"definition",field:s,path:`$.paramDefs.${i}`,message:a}))});return n.length?n:Y(e).map(({index:r,message:i})=>({code:"definition",field:e[r].field,path:`$.paramDefs.${r}`,message:i}))}function M(e){return Array.isArray(e)&&e.every(t=>!!t&&typeof t=="object"&&typeof t.value=="string"&&typeof t.label=="string")}function V(e){const t=[];return e.type!==void 0&&!["text","number","date","month","year","dateRange","select"].includes(e.type)&&t.push("未知参数类型"),e.label!==void 0&&typeof e.label!="string"&&t.push("参数标签应为字符串"),e.placeholder!==void 0&&typeof e.placeholder!="string"&&t.push("提示文字应为字符串"),e.required!==void 0&&typeof e.required!="boolean"&&t.push("required 应为布尔值"),e.defaultValue!==void 0&&typeof e.defaultValue!="string"&&t.push("默认值应为字符串"),e.options!==void 0&&!M(e.options)&&t.push("选项应为包含字符串 label/value 的数组"),[...t,...v(e)]}function P(e,t){if(!e||typeof e!="object"||Array.isArray(e))return["参数定义项应为对象"];const n=V(e);return typeof e.field!="string"||!e.field.trim()||t.has(e.field)?n.push("参数名应为非空且不重复的字符串"):t.add(e.field),n.length||(n.push(...S(e)),n.length)||(e.options&&new Set(e.options.map(r=>r.value)).size!==e.options.length&&n.push("选项值不能重复"),e.defaultValue!==void 0&&(e.required&&!e.defaultValue.trim()?n.push("必填参数的默认值不能为空"):e.defaultValue.trim()&&n.push(...R(e,e.defaultValue).map(([,r])=>`默认值${r}`)))),n}function j(e,t,n){for(const[r,i]of Object.entries(e))(typeof i=="string"||typeof i=="number"&&Number.isFinite(i))&&(Object.defineProperty(t,r,{value:String(i),writable:!0,enumerable:!0,configurable:!0}),Object.defineProperty(n,r,{value:i,writable:!0,enumerable:!0,configurable:!0}))}function g(e){return e==null||typeof e=="string"&&!e.trim()}function $(e,t={}){const n=Object.create(null),r=Object.create(null),i=d(e);if((!t||typeof t!="object"||Array.isArray(t))&&i.push({code:"type",field:"",path:"$.params",message:"参数应为对象"}),i.length)return{ok:!1,values:n,typedValues:r,issues:i};j(t,n,r);for(const s of e){const o=Object.prototype.hasOwnProperty.call(t,s.field)&&t[s.field]!==void 0?t[s.field]:s.defaultValue,a=(l,h)=>i.push({code:l,path:`$.params.${s.field}`,field:s.field,message:h});if(g(o)){s.required&&a("required","此参数为必填项"),typeof o=="string"&&(n[s.field]=o),delete r[s.field];continue}if(typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o))){a("type","参数应为字符串或有限数字");continue}const u=String(o);n[s.field]=u,R(s,u).forEach(([l,h])=>a(l,h)),r[s.field]=s.type==="number"&&x(u)?Number(u):u}return i.push(...I(e,n)),{ok:i.length===0,values:n,typedValues:r,issues:i}}function I(e,t){return e.flatMap(n=>!g(t[n.field])&&n.dependsOn?.some(r=>g(t[r]))?[{code:"dependency",path:`$.params.${n.field}`,field:n.field,message:"请先填写联动依赖的上级参数"}]:[])}function N(e,t={}){const n=$(e,t);if(!n.ok)throw new y(n.issues);return n.values}function A(e){const t={},n="(?![\\s\\S])";return e.type==="date"&&(t.format="date"),e.type==="month"&&(t.pattern=`^(?!0000)[0-9]{4}-(0[1-9]|1[0-2])${n}`),e.type==="year"&&(t.pattern=`^(?!0000)[0-9]{4}${n}`),e.type==="dateRange"&&(t.pattern=`^[0-9]{4}-[0-9]{2}-[0-9]{2}/[0-9]{4}-[0-9]{2}-[0-9]{2}${n}`),e.type==="dateRange"&&(t["x-report-date-range"]={separator:"/",ordered:!0,calendarDates:!0}),t}function q(e){const t={type:e.type==="number"?"number":"string",title:e.label??e.field,...A(e)};return e.required&&e.type!=="number"&&!t.pattern&&(t.pattern="\\S"),e.type==="select"&&e.options&&(t.enum=e.options.map(n=>n.value)),Object.assign(t,E(e)),e.defaultValue!==void 0&&(e.type!=="number"||e.defaultValue.trim())&&(t.default=e.type==="number"?Number(e.defaultValue):e.defaultValue),e.minLength!==void 0&&(t.minLength=e.minLength),e.maxLength!==void 0&&(t.maxLength=e.maxLength),typeof e.min=="number"&&(t.minimum=e.min),typeof e.max=="number"&&(t.maximum=e.max),typeof e.min=="string"&&(t["x-report-minimum"]=e.min),typeof e.max=="string"&&(t["x-report-maximum"]=e.max),t}function E(e){return{...e.optionsSource?{"x-report-options-source":e.optionsSource}:{},...e.dependsOn?.length?{"x-report-depends-on":[...e.dependsOn]}:{}}}function k(e){const t=d(e);if(t.length)throw new y(t);return{$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:Object.fromEntries(e.map(n=>[n.field,q(n)])),required:e.filter(n=>n.required).map(n=>n.field),additionalProperties:!0}}exports.ReportParamValidationError=y;exports.assertReportParams=N;exports.formatReportDateRange=D;exports.isReportDate=p;exports.isReportMonth=f;exports.isReportTemporalBound=b;exports.isReportYear=m;exports.parseReportDateRange=c;exports.reportParamsJsonSchema=k;exports.validateReportParamDefinitions=d;exports.validateReportParams=$;
@@ -1,181 +0,0 @@
1
- function $(e) {
2
- const t = [];
3
- return e.optionsSource !== void 0 && ((e.type !== "select" || typeof e.optionsSource != "string" || !/^[\w][\w.:-]{0,127}$/.test(e.optionsSource)) && t.push("远程选项来源应为 select 的有效来源键(最多 128 字符)"), e.options !== void 0 && t.push("远程选项来源与静态选项不能同时配置")), e.dependsOn !== void 0 && (!e.optionsSource || !Array.isArray(e.dependsOn) || e.dependsOn.length > 32 || e.dependsOn.some((n) => typeof n != "string" || !n) || new Set(e.dependsOn).size !== e.dependsOn.length) && t.push("联动依赖应为远程选项的最多 32 个唯一参数名"), t;
4
- }
5
- function v(e) {
6
- const t = new Map(e.map((i, s) => [i.field, { def: i, index: s, degree: 0, children: [] }])), n = [];
7
- for (const i of t.values()) for (const s of i.def.dependsOn ?? []) {
8
- const o = t.get(s);
9
- if (!o) {
10
- n.push({ index: i.index, message: `联动依赖参数 ${s} 未声明` });
11
- continue;
12
- }
13
- i.degree++, o.children.push(i.def.field);
14
- }
15
- const r = [...t.values()].filter((i) => i.degree === 0);
16
- for (let i = 0; i < r.length; i++) for (const s of r[i].children) {
17
- const o = t.get(s);
18
- --o.degree === 0 && r.push(o);
19
- }
20
- for (const i of t.values()) i.degree > 0 && n.push({ index: i.index, message: "联动依赖不能形成循环" });
21
- return n;
22
- }
23
- function p(e) {
24
- if (!/^\d{4}-\d{2}-\d{2}$/.test(e) || e.startsWith("0000-")) return !1;
25
- const t = /* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);
26
- return Number.isFinite(t.getTime()) && t.toISOString().slice(0, 10) === e;
27
- }
28
- function h(e) {
29
- return e.length === 4 && /^\d{4}$/.test(e) && e !== "0000";
30
- }
31
- function f(e) {
32
- return e.length === 7 && /^\d{4}-(?:0[1-9]|1[0-2])$/.test(e) && h(e.slice(0, 4));
33
- }
34
- function g(e) {
35
- const [t, n, r] = e.split("/");
36
- if (!(r !== void 0 || !t || !n || !p(t) || !p(n) || t > n))
37
- return { start: t, end: n };
38
- }
39
- function E(e) {
40
- const t = `${e.start}/${e.end}`;
41
- if (!g(t)) throw new RangeError("日期范围必须为完整且有序的 YYYY-MM-DD/YYYY-MM-DD");
42
- return t;
43
- }
44
- function Y(e, t) {
45
- return typeof t != "string" ? !1 : e === "month" ? f(t) : e === "year" ? h(t) : (e === "date" || e === "dateRange") && p(t);
46
- }
47
- function L(e, t) {
48
- if (e === "date" && !p(t)) return "应为有效的 YYYY-MM-DD 日期";
49
- if (e === "month" && !f(t)) return "应为有效的 YYYY-MM 月份";
50
- if (e === "year" && !h(t)) return "应为 0001 至 9999 的四位年份";
51
- if (e === "dateRange" && !g(t)) return "应为完整且有序的 YYYY-MM-DD/YYYY-MM-DD 日期范围";
52
- }
53
- class y extends Error {
54
- constructor(t) {
55
- super(t.map((n) => `${n.field}: ${n.message}`).join("; ")), this.issues = t, this.code = "params", this.name = "ReportParamValidationError";
56
- }
57
- }
58
- function d(e) {
59
- return /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(e) && Number.isFinite(Number(e));
60
- }
61
- function b(e, t) {
62
- if (e.type === "number" && !d(t)) return [["type", "应为有限数字"]];
63
- const n = L(e.type, t);
64
- if (n) return [["type", n]];
65
- const r = [];
66
- e.type === "select" && e.options && !e.options.some((s) => s.value === t) && r.push(["option", "不在允许的选项中"]);
67
- const i = Array.from(t).length;
68
- return e.minLength !== void 0 && i < e.minLength && r.push(["minLength", `至少 ${e.minLength} 个字符`]), e.maxLength !== void 0 && i > e.maxLength && r.push(["maxLength", `最多 ${e.maxLength} 个字符`]), r.push(...D(e, t)), r;
69
- }
70
- function D(e, t) {
71
- const n = e.type === "dateRange" ? g(t) : void 0, r = n?.start ?? (e.type === "number" ? Number(t) : t), i = n?.end ?? r, s = [];
72
- return e.min !== void 0 && r < e.min && s.push(["minimum", `不能小于 ${e.min}`]), e.max !== void 0 && i > e.max && s.push(["maximum", `不能大于 ${e.max}`]), s;
73
- }
74
- function O(e) {
75
- const t = [];
76
- for (const i of ["min", "max"]) {
77
- const s = e[i];
78
- if (s === void 0) continue;
79
- Y(e.type, s) || e.type === "number" && typeof s == "number" && Number.isFinite(s) || t.push(`${i} 应为数字的有限边界或日期/月/年的规范字符串边界`);
80
- }
81
- const n = typeof e.min == "number" && typeof e.max == "number" && e.min > e.max, r = typeof e.min == "string" && typeof e.max == "string" && e.min > e.max;
82
- return (n || r) && t.push("最小边界不能大于最大边界"), [...t, ...R(e)];
83
- }
84
- function R(e) {
85
- const t = [];
86
- e.type === "number" && (e.minLength !== void 0 || e.maxLength !== void 0) && t.push("number 参数使用 min/max 而不是文本长度约束");
87
- for (const n of ["minLength", "maxLength"]) {
88
- const r = e[n];
89
- r !== void 0 && (!Number.isSafeInteger(r) || r < 0) && t.push(`${n} 应为非负整数`);
90
- }
91
- return typeof e.minLength == "number" && typeof e.maxLength == "number" && e.minLength > e.maxLength && t.push("最小长度不能大于最大长度"), t;
92
- }
93
- function x(e) {
94
- if (!Array.isArray(e)) return [{ code: "definition", field: "", path: "$.paramDefs", message: "参数定义应为数组" }];
95
- const t = /* @__PURE__ */ new Set(), n = e.flatMap((r, i) => {
96
- const s = r && typeof r.field == "string" ? r.field : "";
97
- return M(r, t).map((a) => ({ code: "definition", field: s, path: `$.paramDefs.${i}`, message: a }));
98
- });
99
- return n.length ? n : v(e).map(({ index: r, message: i }) => ({ code: "definition", field: e[r].field, path: `$.paramDefs.${r}`, message: i }));
100
- }
101
- function S(e) {
102
- return Array.isArray(e) && e.every((t) => !!t && typeof t == "object" && typeof t.value == "string" && typeof t.label == "string");
103
- }
104
- function w(e) {
105
- const t = [];
106
- return e.type !== void 0 && !["text", "number", "date", "month", "year", "dateRange", "select"].includes(e.type) && t.push("未知参数类型"), e.label !== void 0 && typeof e.label != "string" && t.push("参数标签应为字符串"), e.placeholder !== void 0 && typeof e.placeholder != "string" && t.push("提示文字应为字符串"), e.required !== void 0 && typeof e.required != "boolean" && t.push("required 应为布尔值"), e.defaultValue !== void 0 && typeof e.defaultValue != "string" && t.push("默认值应为字符串"), e.options !== void 0 && !S(e.options) && t.push("选项应为包含字符串 label/value 的数组"), [...t, ...$(e)];
107
- }
108
- function M(e, t) {
109
- if (!e || typeof e != "object" || Array.isArray(e)) return ["参数定义项应为对象"];
110
- const n = w(e);
111
- return typeof e.field != "string" || !e.field.trim() || t.has(e.field) ? n.push("参数名应为非空且不重复的字符串") : t.add(e.field), n.length || (n.push(...O(e)), n.length) || (e.options && new Set(e.options.map((r) => r.value)).size !== e.options.length && n.push("选项值不能重复"), e.defaultValue !== void 0 && (e.required && !e.defaultValue.trim() ? n.push("必填参数的默认值不能为空") : e.defaultValue.trim() && n.push(...b(e, e.defaultValue).map(([, r]) => `默认值${r}`)))), n;
112
- }
113
- function V(e, t, n) {
114
- for (const [r, i] of Object.entries(e))
115
- (typeof i == "string" || typeof i == "number" && Number.isFinite(i)) && (Object.defineProperty(t, r, { value: String(i), writable: !0, enumerable: !0, configurable: !0 }), Object.defineProperty(n, r, { value: i, writable: !0, enumerable: !0, configurable: !0 }));
116
- }
117
- function l(e) {
118
- return e == null || typeof e == "string" && !e.trim();
119
- }
120
- function j(e, t = {}) {
121
- const n = /* @__PURE__ */ Object.create(null), r = /* @__PURE__ */ Object.create(null), i = x(e);
122
- if ((!t || typeof t != "object" || Array.isArray(t)) && i.push({ code: "type", field: "", path: "$.params", message: "参数应为对象" }), i.length) return { ok: !1, values: n, typedValues: r, issues: i };
123
- V(t, n, r);
124
- for (const s of e) {
125
- const o = Object.prototype.hasOwnProperty.call(t, s.field) && t[s.field] !== void 0 ? t[s.field] : s.defaultValue, a = (m, c) => i.push({ code: m, path: `$.params.${s.field}`, field: s.field, message: c });
126
- if (l(o)) {
127
- s.required && a("required", "此参数为必填项"), typeof o == "string" && (n[s.field] = o), delete r[s.field];
128
- continue;
129
- }
130
- if (typeof o != "string" && !(typeof o == "number" && Number.isFinite(o))) {
131
- a("type", "参数应为字符串或有限数字");
132
- continue;
133
- }
134
- const u = String(o);
135
- n[s.field] = u, b(s, u).forEach(([m, c]) => a(m, c)), r[s.field] = s.type === "number" && d(u) ? Number(u) : u;
136
- }
137
- return i.push(...I(e, n)), { ok: i.length === 0, values: n, typedValues: r, issues: i };
138
- }
139
- function I(e, t) {
140
- return e.flatMap((n) => !l(t[n.field]) && n.dependsOn?.some((r) => l(t[r])) ? [{ code: "dependency", path: `$.params.${n.field}`, field: n.field, message: "请先填写联动依赖的上级参数" }] : []);
141
- }
142
- function k(e, t = {}) {
143
- const n = j(e, t);
144
- if (!n.ok) throw new y(n.issues);
145
- return n.values;
146
- }
147
- function N(e) {
148
- const t = {}, n = "(?![\\s\\S])";
149
- return e.type === "date" && (t.format = "date"), e.type === "month" && (t.pattern = `^(?!0000)[0-9]{4}-(0[1-9]|1[0-2])${n}`), e.type === "year" && (t.pattern = `^(?!0000)[0-9]{4}${n}`), e.type === "dateRange" && (t.pattern = `^[0-9]{4}-[0-9]{2}-[0-9]{2}/[0-9]{4}-[0-9]{2}-[0-9]{2}${n}`), e.type === "dateRange" && (t["x-report-date-range"] = { separator: "/", ordered: !0, calendarDates: !0 }), t;
150
- }
151
- function P(e) {
152
- const t = { type: e.type === "number" ? "number" : "string", title: e.label ?? e.field, ...N(e) };
153
- return e.required && e.type !== "number" && !t.pattern && (t.pattern = "\\S"), e.type === "select" && e.options && (t.enum = e.options.map((n) => n.value)), Object.assign(t, A(e)), e.defaultValue !== void 0 && (e.type !== "number" || e.defaultValue.trim()) && (t.default = e.type === "number" ? Number(e.defaultValue) : e.defaultValue), e.minLength !== void 0 && (t.minLength = e.minLength), e.maxLength !== void 0 && (t.maxLength = e.maxLength), typeof e.min == "number" && (t.minimum = e.min), typeof e.max == "number" && (t.maximum = e.max), typeof e.min == "string" && (t["x-report-minimum"] = e.min), typeof e.max == "string" && (t["x-report-maximum"] = e.max), t;
154
- }
155
- function A(e) {
156
- return { ...e.optionsSource ? { "x-report-options-source": e.optionsSource } : {}, ...e.dependsOn?.length ? { "x-report-depends-on": [...e.dependsOn] } : {} };
157
- }
158
- function F(e) {
159
- const t = x(e);
160
- if (t.length) throw new y(t);
161
- return {
162
- $schema: "https://json-schema.org/draft/2020-12/schema",
163
- type: "object",
164
- properties: Object.fromEntries(e.map((n) => [n.field, P(n)])),
165
- required: e.filter((n) => n.required).map((n) => n.field),
166
- additionalProperties: !0
167
- };
168
- }
169
- export {
170
- y as R,
171
- k as a,
172
- f as b,
173
- h as c,
174
- j as d,
175
- Y as e,
176
- E as f,
177
- p as i,
178
- g as p,
179
- F as r,
180
- x as v
181
- };
@@ -1 +0,0 @@
1
- "use strict";const l=require("./style-C22Pbv3T.cjs"),u=require("./computed-CGV2a809.cjs");function y(e){if(!e||e.kind==="date")return;const t=e.digits;if(!(t!==void 0&&(!Number.isInteger(t)||t<0||t>100))){if(e.kind==="percent"){const r=t??2;return`0${r?`.${"0".repeat(r)}`:""}%`}return t===void 0?e.thousands?"#,##0.###############":void 0:`${e.thousands?"#,##0":"0"}${t?`.${"0".repeat(t)}`:""}`}}function S(e){const t=/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());if(t){const n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return Number.isNaN(n.getTime())?null:n}const r=new Date(e);return Number.isNaN(r.getTime())?null:r}function c(e,t){return e.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t})}function L(e,t){const r=n=>String(n).padStart(2,"0");return t.replace(/YYYY/g,String(e.getFullYear())).replace(/MM/g,r(e.getMonth()+1)).replace(/DD/g,r(e.getDate())).replace(/hh/g,r(e.getHours())).replace(/mm/g,r(e.getMinutes())).replace(/ss/g,r(e.getSeconds()))}function x(e,t,r){return r!=null?t?c(e,r):e.toFixed(r):t?c(e):String(e)}function g(e){const t=typeof e=="number"?e:Number(String(e).replace(/,/g,""));return Number.isFinite(t)?t:null}function b(e,t){if(e==null||e===""||!t)return String(e??"");switch(t.kind){case"number":{if(typeof e=="string")try{return u.formatDecimal(e,t.digits,t.thousands===!0)}catch{return e}const r=g(e);return r==null?String(e):x(r,t.thousands===!0,t.digits)}case"percent":{if(typeof e=="string")try{return u.formatDecimal(e,t.digits??2,!0,!0)}catch{return e}const r=g(e);return r==null?String(e):`${c(r*100,t.digits??2)}%`}case"date":{const r=t.pattern??"YYYY-MM-DD",n=e instanceof Date?e:S(String(e));return n?L(n,r):String(e)}default:return String(e)}}function p(e,t){const r=e[t.field];if(r==null||r==="")return!1;if(typeof t.value=="number"||t.numeric!==void 0){let a;try{a=u.compareDecimal(u.parseDecimal(r),u.parseDecimal(t.value))}catch{return!1}if(!Number.isFinite(a))return!1;switch(t.op){case">":return a>0;case">=":return a>=0;case"<":return a<0;case"<=":return a<=0;case"==":return a===0;case"!=":return a!==0}}const n=String(r),i=String(t.value);switch(t.op){case"==":return n===i;case"!=":return n!==i;case">":return n>i;case">=":return n>=i;case"<":return n<i;case"<=":return n<=i}return!1}function h(e,t,r,n=e.paddingMm??1){return t.field!==e.tree.labelField?0:Math.min(r.depth*(e.tree.indentMm??3),Math.max(0,t.widthMm-n*2-4))}function D(e,t,r,n){const i=n.tree;(i.input==="nested"||[i.idField,i.parentField].includes(t.field))&&(e.editable=!1),r.hasChildren&&i.parentValues==="leaf-aggregate"&&i.aggregates?.some(a=>a.field===t.field)&&(e.derived=!0,e.editable=!1)}function N(e,t,r){return r==="identifier"||r==="dimension"||r==="date"?"center":r==="measure"?"right":r==="text"?"left":t?.kind==="number"||t?.kind==="percent"?"right":t?.kind==="date"||e instanceof Date||typeof e=="boolean"?"center":typeof e=="number"&&Number.isFinite(e)?"right":"left"}function T(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number")return String(e);if(typeof e=="boolean")return e?"是":"否";if(e instanceof Date)return e.toISOString().slice(0,10);try{return JSON.stringify(e)}catch{return String(e)}}function C(e,t){let r=l.mergeComponentStyles({fontSize:e.fontSizePt??l.DEFAULT_FONT_PT,bold:e.headerBold??!0,align:"center",verticalAlign:"middle",backgroundColor:e.headerBackgroundColor},t.style);return e.headerAlign!==void 0&&(r.align=e.headerAlign),r=l.mergeComponentStyles(r,e.headerStyle),t.headerAlign!==void 0&&(r.align=t.headerAlign),l.mergeComponentStyles(r,t.headerStyle)}function M(e,t,r){(r===null||typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r))&&(e.value=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);const i=y(t.format);(typeof e.value=="number"||e.value==null)&&i!==void 0&&(e.numberFormat=i)}function F(e,t,r){const n=!!t.visibleWhen&&!p(r,t.visibleWhen),i=n?null:r[t.field],a=t.align??t.style?.align??e.align??"left";let s=l.mergeComponentStyles({fontSize:e.fontSizePt??l.DEFAULT_FONT_PT,verticalAlign:"middle"},t.style);s.align=a==="auto"?N(i,t.format,t.semanticRole):a;const o=t.rules?.find(f=>p(r,f.when));o&&(s=l.mergeComponentStyles(s,o.style));const d={text:t.format?b(i,t.format):T(i),style:s};return M(d,t,i),e.computed?.some(f=>f.field===t.field)&&(d.derived=!0,d.editable=!1),n&&(d.editable=!1),d}function A(e,t,r){const n=F(e,t,r.row),i=h(e,t,r);return t.field===e.tree.labelField&&(n.style={...n.style,align:"left"}),i&&(n.indentMm=i),D(n,t,r,e),n}function k(e){return typeof e=="string"&&/^data:image\/(png|jpe?g);base64,[A-Za-z0-9+/\r\n]+=*$/.test(e)}class m extends Error{constructor(t,r,n,i){super(`${t}: ${r}`),this.path=t,this.rowIndex=n,this.field=i,this.code="report-binding",this.name="ReportBindingError"}}function $(e,t,r={}){const n=r.rowIndex??0,a=`$.datasets.${r.dataset??"label"}[${n}].${t}`,s=Object.getOwnPropertyDescriptor(e,t);if(!s||s.get||s.set)throw new m(a,"字段必须是记录的自有数据字段,不能缺失、使用访问器或从原型继承",n,t);const o=s.value;if(o==null||typeof o=="string"||typeof o=="boolean"||typeof o=="number"&&Number.isFinite(o))return o;throw new m(a,"绑定值应为字符串、有限数字、布尔值或空值",n,t)}function w(e,t,r={}){const n=$(t,e.field,r);return n==null||n===""?e.emptyText??"":`${e.prefix??""}${b(n,e.format)}${e.suffix??""}`}exports.ReportBindingError=m;exports.applyListTreeMetadata=D;exports.evalStyleRule=p;exports.formatValue=b;exports.isLabelImageData=k;exports.listCellText=T;exports.listTreeIndent=h;exports.parseDateLocal=S;exports.readRecordScalar=$;exports.resolveComponentBinding=w;exports.resolveListAutoAlignment=N;exports.resolveListHeaderStyle=C;exports.resolveListSampleCell=F;exports.resolveTreeListSampleCell=A;exports.toExcelNumberFormat=y;exports.toNumber=g;