@agile-team/mach-report 2.25.0 → 2.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +4 -2
  2. package/dist/{ExcelBindingWizard-NQ_v396s.js → ExcelBindingWizard-bs3F4dD8.js} +3 -3
  3. package/dist/{ExcelBindingWizard-BgJG-T6k.cjs → ExcelBindingWizard-jSdjBtWw.cjs} +1 -1
  4. package/dist/{ParamEditor-Z-3yodp5.js → ParamEditor-B7YVD28E.js} +1 -1
  5. package/dist/{ParamEditor-DEP38mBp.cjs → ParamEditor-CGfaweYX.cjs} +1 -1
  6. package/dist/{ReportBatchPanel-D33LjMrA.cjs → ReportBatchPanel-BRJt0TXp.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-DG8FV-5X.js → ReportBatchPanel-BTKHtLTW.js} +1 -1
  8. package/dist/{ReportLabelStudio-Bz-xAayk.cjs → ReportLabelStudio-BvK_WBke.cjs} +1 -1
  9. package/dist/{ReportLabelStudio-BZp23_hA.js → ReportLabelStudio-CZwqyO3t.js} +2 -2
  10. package/dist/{ReportPreview-CilFAS9U.js → ReportPreview-CnxaDTCO.js} +4 -4
  11. package/dist/{ReportPreview-dOOzPts2.cjs → ReportPreview-DqFBcsJQ.cjs} +2 -2
  12. package/dist/{ReportTemplateLibrary-DpSGgvFa.js → ReportTemplateLibrary-C7sB0Jay.js} +1 -1
  13. package/dist/{ReportTemplateLibrary-uG1gENaW.cjs → ReportTemplateLibrary-ClwxhnC0.cjs} +1 -1
  14. package/dist/{RuleEditor-BONALh1Q.js → RuleEditor-CsDGFaWz.js} +3 -3
  15. package/dist/{RuleEditor-bLXiRcxL.cjs → RuleEditor-D-OdaGdR.cjs} +1 -1
  16. package/dist/{TemplateOutlinePanel-JGBKeF3e.js → TemplateOutlinePanel-CXOT7d1r.js} +1 -1
  17. package/dist/{TemplateOutlinePanel-C3nfHuaR.cjs → TemplateOutlinePanel-DAqR9zQi.cjs} +1 -1
  18. package/dist/{TemplateReusePanel-DXQUO6nQ.js → TemplateReusePanel-Dcfx3Hba.js} +2 -2
  19. package/dist/{TemplateReusePanel-BKhgp6kg.cjs → TemplateReusePanel-ygIi-Ajz.cjs} +1 -1
  20. package/dist/{TemplateReviewPanel-DhL7Hapy.js → TemplateReviewPanel-COU8FqPq.js} +1 -1
  21. package/dist/{TemplateReviewPanel-5RWFUUEf.cjs → TemplateReviewPanel-DyGULVxr.cjs} +1 -1
  22. package/dist/analytics.cjs +1 -1
  23. package/dist/analytics.js +2 -2
  24. package/dist/artifact-integrity.json +71 -71
  25. package/dist/{auto-umW_ozwr.js → auto-D7x7QsWD.js} +4 -4
  26. package/dist/{auto-D-eDZa_V.cjs → auto-mPK9W0y5.cjs} +1 -1
  27. package/dist/{designer-CCyj5WYS.js → designer-B597ZdC0.js} +4 -4
  28. package/dist/{designer-Cj7fn4Hh.cjs → designer-DFIdv_n7.cjs} +1 -1
  29. package/dist/designer.cjs +1 -1
  30. package/dist/designer.js +1 -1
  31. package/dist/{encoding-CEkBtlUP.js → encoding-Amq3XrtU.js} +2 -2
  32. package/dist/{encoding-Cipno7dq.cjs → encoding-DRVXs5xm.cjs} +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +8 -8
  35. package/dist/{json-snapshot-x0JpllWL.js → json-snapshot-CBVWZvyC.js} +661 -614
  36. package/dist/json-snapshot-DCFEtfFw.cjs +2 -0
  37. package/dist/matrix-DUYPRL7t.cjs +1 -0
  38. package/dist/{matrix-C6e_r_vp.js → matrix-b6T291xo.js} +120 -104
  39. package/dist/{plugin-CttO46hc.js → plugin-BdCplNe1.js} +1 -1
  40. package/dist/{plugin-B_k23hut.cjs → plugin-DHe8y5pD.cjs} +1 -1
  41. package/dist/{prefill-BkF9Fw_p.js → prefill-Buy4NJ15.js} +1 -1
  42. package/dist/{prefill-BvkuwooY.cjs → prefill-Cw4ZYGXZ.cjs} +1 -1
  43. package/dist/{prepared-CSywIEAZ.cjs → prepared-BlNeOjoO.cjs} +1 -1
  44. package/dist/{prepared-Cyuh61fJ.js → prepared-CBJ7BkK0.js} +1 -1
  45. package/dist/{protocol-BwbJNVZl.cjs → protocol-BU_4sXP0.cjs} +1 -1
  46. package/dist/{protocol-DwtxjXzO.js → protocol-CB19KXGr.js} +2 -2
  47. package/dist/{region-binding-workflow-D8I4QWRh.js → region-binding-workflow-EYxvUYJ-.js} +1 -1
  48. package/dist/{region-binding-workflow-COD8nISZ.cjs → region-binding-workflow-NdkMSFCh.cjs} +1 -1
  49. package/dist/report-encoding-worker.cjs +1 -1
  50. package/dist/report-encoding-worker.js +1 -1
  51. package/dist/{runtime-BE30icyB.js → runtime-B5d_lQNQ.js} +3 -3
  52. package/dist/{runtime-DRSuy_SQ.cjs → runtime-BRx8Agqr.cjs} +1 -1
  53. package/dist/sbom.cdx.json +1 -1
  54. package/dist/server-node.cjs +5 -5
  55. package/dist/server-node.js +1686 -1622
  56. package/dist/server.cjs +1 -1
  57. package/dist/server.js +6 -6
  58. package/dist/{template-catalog-D_gl93va.js → template-catalog-CM6U_RlD.js} +2 -2
  59. package/dist/{template-catalog-C0riwrx7.cjs → template-catalog-Cj66M84u.cjs} +1 -1
  60. package/dist/{template-fragments-D94ZZmPc.js → template-fragments-BDxdCuMD.js} +1 -1
  61. package/dist/{template-fragments-CgzPdFKB.cjs → template-fragments-DbKdxI1z.cjs} +1 -1
  62. package/dist/template-registry-B-AK1oam.cjs +1 -0
  63. package/dist/{template-registry-DZOtRY7t.js → template-registry-DeVgwEZj.js} +143 -142
  64. package/dist/vue-async.cjs +1 -1
  65. package/dist/vue-async.js +3 -3
  66. package/dist/vue.cjs +1 -1
  67. package/dist/vue.js +4 -4
  68. package/dist/{workbook-session-SzfILBJJ.js → workbook-session-B6hRjTyX.js} +1 -1
  69. package/dist/{workbook-session-DR2j6Hxm.cjs → workbook-session-BclW7KKH.cjs} +1 -1
  70. package/dist/worker.cjs +1 -1
  71. package/dist/worker.js +4 -4
  72. package/dist/xlsx.cjs +1 -1
  73. package/dist/xlsx.js +3 -3
  74. package/package.json +1 -1
  75. package/dist/json-snapshot-DQdkA_At.cjs +0 -2
  76. package/dist/matrix-B8QWbsGM.cjs +0 -1
  77. package/dist/template-registry-BMScUmM4.cjs +0 -1
@@ -1,4 +1,4 @@
1
- import { t as P, E as O, l as V, O as Z, P as T } from "./json-snapshot-x0JpllWL.js";
1
+ import { t as P, E as O, l as V, O as Z, P as T } from "./json-snapshot-CBVWZvyC.js";
2
2
  import { r as B } from "./diagnostic-collector-gB07PHy2.js";
3
3
  import { d as $, p as S, a as H, k as q, h as J } from "./computed-f3pOqWLX.js";
4
4
  function I(e) {
@@ -1 +1 @@
1
- "use strict";const g=require("./json-snapshot-DQdkA_At.cjs"),N=require("./diagnostic-collector-wASg6Fzs.cjs"),y=require("./computed-DK6BruFz.cjs");function R(e){return Number.isFinite(e)?Math.max(0,e):0}function B(e,t=0){const r=e.length,o=R(t),n=new Array(r+1);n[0]=0;for(let i=0;i<r;i++)n[i+1]=n[i]+R(e[i]??0)+o;const c=n[r];function s(i){let a=0,u=r-1,p=0;for(;a<=u;){const f=a+u>>>1;n[f]<=i?(p=f,a=f+1):u=f-1}return p}function d(i,a,u=1){if(r===0)return{start:0,end:-1,padTopPx:0,padBottomPx:0};const p=Math.floor(R(u)),f=R(a),m=s(f),w=Math.max(0,m-p),I=f+R(i);let h=m,D=r-1,z=r-1;for(;h<=D;){const S=h+D>>>1;n[S+1]<I?h=S+1:(z=S,D=S-1)}const E=Math.min(r-1,z+p);return{start:w,end:E,padTopPx:n[w],padBottomPx:Math.max(0,c-n[E+1])}}return{totalHeightPx:c,pageAt:s,offsetAt:i=>n[Math.max(0,Math.min(r,Math.floor(i)))]??0,window:d}}class v extends Error{constructor(t){super(`Report drill: ${t}`),this.code=t,this.name="ReportDrillError"}}function x(e){return typeof e=="string"&&e.trim().length>0&&e.length<=256}function V(e){if(typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean")return String(e);if(typeof e=="string"&&e.length>0&&e.length<=4096)return e;throw new v("missing-value")}function $(e,t){return Object.getOwnPropertyDescriptor(e,t)?.value}function A(e){if(!Array.isArray(e)||e.length>64)throw new v("config");const t=new Set;for(const r of e){if(!r||!x(r.id)||!x(r.label)||!r.target||!x(r.target.field)||t.has(r.id))throw new v("config");t.add(r.id);const o=r.target;if(o.datasetId!==void 0&&!x(o.datasetId)||o.reportScope!==void 0&&!x(o.reportScope))throw new v("config");if(o.roles!==void 0&&(!Array.isArray(o.roles)||o.roles.length>16||o.roles.some(n=>!x(n))))throw new v("config");G(r.params)}}function G(e){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length>32)throw new v("config");for(const[t,r]of Object.entries(e)){if(!x(t)||["__proto__","constructor","prototype"].includes(t)||!r||typeof r!="object")throw new v("config");if("value"in r)try{V(r.value)}catch{throw new v("config")}else if(!["value","rowKey","query","field"].includes(r.from)||(r.from==="query"||r.from==="field")&&!x(r.field))throw new v("config")}}}function T(e,t,r){const{target:o}=r,n=t.source?.datasetId??t.component.table?.source?.datasetId;return(t.source?.field??t.table?.columnKey)===o.field&&(o.datasetId===void 0||n===o.datasetId)&&(o.reportScope===void 0||e.pages[t.address.pageIndex]?.meta?.reportScope===o.reportScope)&&(o.roles?o.roles.includes(t.table?.role??""):t.table?.role!=="header")}function U(e,t,r){A(r);const o=g.getReportCellContext(e,t);return o?r.filter(n=>T(e,o,n)):[]}function W(e,t,r,o){if("value"in e)return e.value;switch(e.from){case"value":return r.value;case"rowKey":return r.source?.rowKey;case"query":return $(o,e.field);case"field":{const n=r.component.table?.columnKeys.indexOf(e.field)??-1;return n<0?void 0:g.getReportCellContext(t,{...r.address,columnIndex:n})?.value}}}function Z(e,t,r,o={}){A([r]);const n=g.getReportCellContext(e,t);if(!n||!T(e,n,r))throw new v("target");const c=Object.fromEntries(Object.entries(r.params??{}).map(([i,a])=>[i,V(W(a,e,n,o))])),s=Object.entries(o);if(s.length>128||s.some(([i,a])=>!x(i)||typeof a!="string"||a.length>4096))throw new v("config");const d=e.pages[t.pageIndex]?.meta?.reportScope;return Object.freeze({actionId:r.id,params:Object.freeze(c),returnState:Object.freeze({params:Object.freeze(Object.fromEntries(s)),address:Object.freeze({...t}),...typeof d=="string"?{reportScope:d}:{},...n.source?{source:Object.freeze({sourceScope:n.source.sourceScope,datasetId:n.source.datasetId,rowKey:n.source.rowKey,field:n.source.field})}:{}})})}function H(e,t){if(!t.source)return e.pages[t.address.pageIndex]?.meta?.reportScope===t.reportScope&&g.getReportCellContext(e,t.address)?{...t.address}:null;const r=g.createReportCellResolver(e),o=g.reportCellEditKey({address:t.address,source:t.source});for(const[n,c]of e.pages.entries())if(!(t.reportScope!==void 0&&c.meta?.reportScope!==t.reportScope)){for(const[s,d]of c.components.entries())if(d.grid)for(const i of N.resolveGridLayout(d.grid,d.widthMm,d.heightMm).cells){const a={pageIndex:n,componentIndex:s,rowIndex:i.ri,columnIndex:i.ci},u=r(a);if(u?.source&&g.reportCellEditKey(u)===o)return a}}return null}class l extends Error{constructor(t,r){super(r),this.code=t,this.name="ReportDataError"}}function b(e,t,r){const o=e??t;if(!Number.isSafeInteger(o)||o<1||o>r)throw new l("limit","Invalid report data budget");return o}function k(e){if(typeof e=="string"&&e.length>0&&e.length<=2048)return`s:${e}`;if(typeof e=="number"&&Number.isSafeInteger(e))return`n:${Object.is(e,-0)?0:e}`;throw new l("identity","A stable string or safe integer business key is required")}function O(e){if(typeof e.datasetId!="string"||!e.datasetId.trim()||e.datasetId.length>2048)throw new l("identity","A dataset identity is required");if(e.sourceScope!==void 0&&(typeof e.sourceScope!="string"||!e.sourceScope.trim()||e.sourceScope.length>2048))throw new l("identity","Invalid source scope")}function j(e,t=256){if(!Array.isArray(e)||!e.length||e.length>t)throw new l("limit","A bounded explicit field allowlist is required");const r=new Set;for(const o of e){if(typeof o!="string"||!o.trim()||o.length>2048||["__proto__","constructor","prototype"].includes(o))throw new l("identity","Invalid report field");if(r.has(o))throw new l("duplicate","Duplicate report field");r.add(o)}}function C(e,t){const r=Object.getOwnPropertyDescriptor(e.values,t);if(!r)return;if(!("value"in r))throw new l("value","Report values must be plain scalar data");const o=r.value;if(o===null||typeof o=="boolean"||typeof o=="string"||typeof o=="number"&&Number.isFinite(o))return o;throw new l("value","Report values must be finite scalar data")}function J(e){if(!e||typeof e!="object"||![Object.prototype,null].includes(Object.getPrototypeOf(e)))throw new l("value","Report records must be plain data");const t=Object.getOwnPropertyDescriptor(e,"rowKey"),r=Object.getOwnPropertyDescriptor(e,"values");if(!t||!("value"in t)||!r||!("value"in r)||!r.value||typeof r.value!="object"||![Object.prototype,null].includes(Object.getPrototypeOf(r.value)))throw new l("value","Report records require own scalar keys and plain values");return{rowKey:t.value,values:r.value}}function q(e,t,r={}){const o=b(r.maxRows,5e4,1e5),n=b(r.maxCells,1e6,2e6);if(!Array.isArray(e)||Object.getPrototypeOf(e)!==Array.prototype||e.length>o||e.length*t.length>n)throw new l("limit","Report data exceeds its budget");const c=new Map;for(let s=0;s<e.length;s++){const d=Object.getOwnPropertyDescriptor(e,s);if(!d||!("value"in d))throw new l("value","Sparse or accessor report records are unsupported");const i=J(d.value),a=k(i.rowKey);if(c.has(a))throw new l("duplicate","Duplicate business row key");const u=Object.create(null);for(const p of t){const f=C(i,p);f!==void 0&&(u[p]=f)}c.set(a,{rowKey:i.rowKey,values:u})}return c}function P(e){return e==null||e===""}function F(e,t){return P(e)?t.missing==="zero"?y.parseDecimal(0):void 0:y.parseDecimal(e)}function Q(e){return{coefficient:-e.coefficient,scale:e.scale}}function X(e,t,r,o){const n=F(e,r),c=Object.is(e,t)?n:F(t,r);if(!n||!c)return{equal:L(e,t,r),ratioUnavailable:"missing"};const s=y.addDecimal(c,Q(n)),d={...s,coefficient:s.coefficient<0n?-s.coefficient:s.coefficient},i=y.compareDecimal(d,r.toleranceValue)<=0;return i&&!o?{equal:i}:n.coefficient===0n?{equal:i,delta:y.printDecimal(s),...s.coefficient===0n&&r.zeroDenominator==="zero-if-equal"?{changeRatio:"0"}:{ratioUnavailable:"zero-denominator"}}:{equal:i,delta:y.printDecimal(s),changeRatio:y.printDecimal(y.divideDecimal(s,n,r.ratioDigits??12))}}function L(e,t,r){return r.missing==="empty-equivalent"&&P(e)&&P(t)||Object.is(e,t)}function Y(e){j(e.fields.map(t=>t.field),b(e.maxFields,256,1024));for(const t of e.fields){if(t.type!==void 0&&!["decimal","value"].includes(t.type))throw new l("value","Invalid comparison field type");if(t.missing&&!["distinct","empty-equivalent","zero"].includes(t.missing))throw new l("value","Invalid missing-value policy");if(t.zeroDenominator&&!["omit","zero-if-equal"].includes(t.zeroDenominator))throw new l("value","Invalid zero-denominator policy");if(t.missing==="zero"&&t.type!=="decimal")throw new l("value","Zero missing-value policy requires a decimal field");if(t.tolerance!==void 0&&(t.type!=="decimal"||y.compareDecimal(y.parseDecimal(t.tolerance),y.parseDecimal(0))<0))throw new l("value","Tolerance requires a non-negative decimal");if(t.ratioDigits!==void 0&&(!Number.isInteger(t.ratioDigits)||t.ratioDigits<0||t.ratioDigits>100))throw new l("value","Invalid ratio precision")}return e.fields.map(t=>({...t,toleranceValue:y.parseDecimal(t.tolerance??"0")}))}function M(e,t,r,o,n){let c=!1;for(const s of r){const d=e?C(e,s.field):void 0,i=t?C(t,s.field):void 0,a=s.type==="decimal"?X(d,i,s,!e||!t):{equal:L(d,i,s)};if(e&&t&&a.equal)continue;if(c=!0,o.length>=n)throw new l("limit","Report differences exceed their budget");const{equal:u,...p}=a;o.push({rowKey:(t??e).rowKey,kind:e?t?"changed":"removed":"added",field:s.field,label:s.label??s.field,before:d,after:i,...p})}return c}function ee(e,t,r){O(e),O(t);const o=Y(r);if(e.datasetId!==t.datasetId||e.sourceScope!==t.sourceScope)throw new l("identity","Comparison requires the same business dataset and source scope");const n=r.fields.map(u=>u.field),c=q(e.rows,n,r),s=q(t.rows,n,r),d=b(r.maxDifferences,2e4,1e5),i=[],a={added:0,removed:0,changed:0,unchanged:0,cells:0};for(const[u,p]of c){const f=s.get(u),m=M(p,f,o,i,d);f?m?a.changed++:a.unchanged++:a.removed++}for(const[u,p]of s)c.has(u)||(M(void 0,p,o,i,d),a.added++);return a.cells=i.length,{sourceScope:t.sourceScope,datasetId:t.datasetId,differences:i,counts:a}}function K(e,t){O(t),j(t.fields,b(t.maxFields,256,1024));const r=b(t.maxCells,1e6,2e6),o=new Set(t.fields),n=new Map,c=g.createReportCellResolver(e);let s=0;for(const[d,i]of e.pages.entries())for(const[a,u]of i.components.entries()){if(!u.grid)continue;for(const f of u.grid.cells)if(s+=f.length,s>r)throw new l("limit","Report cell scan exceeds its budget");const p=N.resolveGridLayout(u.grid,u.widthMm,u.heightMm).cells;for(const f of p){const m=c({pageIndex:d,componentIndex:a,rowIndex:f.ri,columnIndex:f.ci}),w=m?.source;if(!m||!w||w.datasetId!==t.datasetId||w.sourceScope!==t.sourceScope||!o.has(w.field))continue;k(w.rowKey);const I=g.reportCellEditKey(m),h=n.get(I);h?(!Object.is(h.context.value,m.value)||h.context.source?.revision!==w.revision||h.context.source?.sourceToken!==w.sourceToken||h.context.editable!==m.editable)&&(h.ambiguous=!0):n.set(I,{context:m,ambiguous:!1})}}return n}function te(e,t){const r=K(e,t),o=new Map,n=b(t.maxRows,5e4,1e5);for(const{context:c,ambiguous:s}of r.values()){if(s)throw new l("conflict","Repeated report cells disagree for the same business field");const d=c.source,i=k(d.rowKey);let a=o.get(i);if(!a){if(o.size>=n)throw new l("limit","Report row extraction exceeds its budget");a={rowKey:d.rowKey,values:Object.create(null)},o.set(i,a)}a.values[d.field]=c.value}return{sourceScope:t.sourceScope,datasetId:t.datasetId,rows:[...o.values()]}}function _(e){return e==null||e===""}function re(e,t,r){if(!t){e.reason="missing-target";return}const{context:o,ambiguous:n}=t;if(e.before=o.value,n){e.status="conflict",e.reason="ambiguous";return}if(!o.editable||r.canEdit?.(o)===!1){e.reason="readonly";return}if(_(e.after)){e.reason="missing-source";return}if(Object.is(o.value,e.after)){e.status="matched",e.reason="unchanged";return}if(r.mode!=="replace"&&!_(o.value)){e.reason="occupied";return}try{const c=g.editFromContext(o,e.after);if(Object.is(c.value,c.previousValue)){e.status="matched",e.reason="unchanged";return}return e.after=c.value,e.status="changed",c}catch{e.status="conflict",e.reason="invalid";return}}function oe(e,t){if(O(t),t.mode!==void 0&&t.mode!=="empty"&&t.mode!=="replace")throw new l("value","Invalid prefill policy");const r=b(t.maxFields,256,1024),o=t.fields.map(f=>f.field),n=[...new Set(t.fields.map(f=>f.sourceField??f.field))];j(o,r),j(n,r);const c=q(t.rows,n,t),s=K(e,{...t,fields:o}),d=b(t.maxChanges,1e4,1e4),i=b(t.maxCells,1e6,2e6);if(c.size*o.length>i)throw new l("limit","Prefill review exceeds its budget");const a=[],u=[],p={matched:0,changed:0,skipped:0,conflict:0};for(const f of c.values())for(const m of t.fields){const w={sourceScope:t.sourceScope,datasetId:t.datasetId,rowKey:f.rowKey,field:m.field},I={source:w,label:m.label??m.field,status:"skipped",after:C(f,m.sourceField??m.field)},h=g.reportCellEditKey({address:{pageIndex:0,componentIndex:0,rowIndex:0,columnIndex:0},source:w}),D=re(I,s.get(h),t);if(D){if(u.length>=d)throw new l("limit","Prefill changes exceed the atomic edit budget");u.push(D)}p[I.status]++,a.push(I)}return{sourceScope:t.sourceScope,datasetId:t.datasetId,items:a,counts:p,edits:u}}function ne(e,t,r){if(t.counts.conflict>0)throw new l("conflict","Resolve prefill conflicts before applying");if(t.edits.length>1e4)throw new l("limit","Prefill changes exceed the atomic edit budget");if(!t.edits.length)return[];const o=[...new Set(t.edits.map(s=>s.source.field))],n=K(e,{sourceScope:t.sourceScope,datasetId:t.datasetId,fields:o}),c=new Set;return t.edits.map(s=>{if(!s.source||s.source.datasetId!==t.datasetId||s.source.sourceScope!==t.sourceScope)throw new l("identity","Prefill identity changed");const d=g.reportCellEditKey(s),i=n.get(d);if(c.has(d))throw new l("duplicate","Duplicate prefill target");if(c.add(d),!i||i.ambiguous||g.sourceChanged(i.context,s)||!Object.is(i.context.value,s.previousValue))throw new l("conflict","Prefill target changed; reload the preview");if(!i.context.editable||r?.(i.context)===!1)throw new l("conflict","Prefill target is read-only");return{address:{...i.context.address},value:g.editFromContext(i.context,s.value).value}})}exports.ReportDataError=l;exports.ReportDrillError=v;exports.compareReportData=ee;exports.createPageWindowIndex=B;exports.createReportDrillRequest=Z;exports.createReportPrefill=oe;exports.dataLimit=b;exports.indexReportDataCells=K;exports.matchReportDrillActions=U;exports.reportDataSnapshotFromPlan=te;exports.reportPrefillInputs=ne;exports.resolveReportDrillReturn=H;exports.validateReportDrillActions=A;
1
+ "use strict";const g=require("./json-snapshot-DCFEtfFw.cjs"),N=require("./diagnostic-collector-wASg6Fzs.cjs"),y=require("./computed-DK6BruFz.cjs");function R(e){return Number.isFinite(e)?Math.max(0,e):0}function B(e,t=0){const r=e.length,o=R(t),n=new Array(r+1);n[0]=0;for(let i=0;i<r;i++)n[i+1]=n[i]+R(e[i]??0)+o;const c=n[r];function s(i){let a=0,u=r-1,p=0;for(;a<=u;){const f=a+u>>>1;n[f]<=i?(p=f,a=f+1):u=f-1}return p}function d(i,a,u=1){if(r===0)return{start:0,end:-1,padTopPx:0,padBottomPx:0};const p=Math.floor(R(u)),f=R(a),m=s(f),w=Math.max(0,m-p),I=f+R(i);let h=m,D=r-1,z=r-1;for(;h<=D;){const S=h+D>>>1;n[S+1]<I?h=S+1:(z=S,D=S-1)}const E=Math.min(r-1,z+p);return{start:w,end:E,padTopPx:n[w],padBottomPx:Math.max(0,c-n[E+1])}}return{totalHeightPx:c,pageAt:s,offsetAt:i=>n[Math.max(0,Math.min(r,Math.floor(i)))]??0,window:d}}class v extends Error{constructor(t){super(`Report drill: ${t}`),this.code=t,this.name="ReportDrillError"}}function x(e){return typeof e=="string"&&e.trim().length>0&&e.length<=256}function V(e){if(typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean")return String(e);if(typeof e=="string"&&e.length>0&&e.length<=4096)return e;throw new v("missing-value")}function $(e,t){return Object.getOwnPropertyDescriptor(e,t)?.value}function A(e){if(!Array.isArray(e)||e.length>64)throw new v("config");const t=new Set;for(const r of e){if(!r||!x(r.id)||!x(r.label)||!r.target||!x(r.target.field)||t.has(r.id))throw new v("config");t.add(r.id);const o=r.target;if(o.datasetId!==void 0&&!x(o.datasetId)||o.reportScope!==void 0&&!x(o.reportScope))throw new v("config");if(o.roles!==void 0&&(!Array.isArray(o.roles)||o.roles.length>16||o.roles.some(n=>!x(n))))throw new v("config");G(r.params)}}function G(e){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length>32)throw new v("config");for(const[t,r]of Object.entries(e)){if(!x(t)||["__proto__","constructor","prototype"].includes(t)||!r||typeof r!="object")throw new v("config");if("value"in r)try{V(r.value)}catch{throw new v("config")}else if(!["value","rowKey","query","field"].includes(r.from)||(r.from==="query"||r.from==="field")&&!x(r.field))throw new v("config")}}}function T(e,t,r){const{target:o}=r,n=t.source?.datasetId??t.component.table?.source?.datasetId;return(t.source?.field??t.table?.columnKey)===o.field&&(o.datasetId===void 0||n===o.datasetId)&&(o.reportScope===void 0||e.pages[t.address.pageIndex]?.meta?.reportScope===o.reportScope)&&(o.roles?o.roles.includes(t.table?.role??""):t.table?.role!=="header")}function U(e,t,r){A(r);const o=g.getReportCellContext(e,t);return o?r.filter(n=>T(e,o,n)):[]}function W(e,t,r,o){if("value"in e)return e.value;switch(e.from){case"value":return r.value;case"rowKey":return r.source?.rowKey;case"query":return $(o,e.field);case"field":{const n=r.component.table?.columnKeys.indexOf(e.field)??-1;return n<0?void 0:g.getReportCellContext(t,{...r.address,columnIndex:n})?.value}}}function Z(e,t,r,o={}){A([r]);const n=g.getReportCellContext(e,t);if(!n||!T(e,n,r))throw new v("target");const c=Object.fromEntries(Object.entries(r.params??{}).map(([i,a])=>[i,V(W(a,e,n,o))])),s=Object.entries(o);if(s.length>128||s.some(([i,a])=>!x(i)||typeof a!="string"||a.length>4096))throw new v("config");const d=e.pages[t.pageIndex]?.meta?.reportScope;return Object.freeze({actionId:r.id,params:Object.freeze(c),returnState:Object.freeze({params:Object.freeze(Object.fromEntries(s)),address:Object.freeze({...t}),...typeof d=="string"?{reportScope:d}:{},...n.source?{source:Object.freeze({sourceScope:n.source.sourceScope,datasetId:n.source.datasetId,rowKey:n.source.rowKey,field:n.source.field})}:{}})})}function H(e,t){if(!t.source)return e.pages[t.address.pageIndex]?.meta?.reportScope===t.reportScope&&g.getReportCellContext(e,t.address)?{...t.address}:null;const r=g.createReportCellResolver(e),o=g.reportCellEditKey({address:t.address,source:t.source});for(const[n,c]of e.pages.entries())if(!(t.reportScope!==void 0&&c.meta?.reportScope!==t.reportScope)){for(const[s,d]of c.components.entries())if(d.grid)for(const i of N.resolveGridLayout(d.grid,d.widthMm,d.heightMm).cells){const a={pageIndex:n,componentIndex:s,rowIndex:i.ri,columnIndex:i.ci},u=r(a);if(u?.source&&g.reportCellEditKey(u)===o)return a}}return null}class l extends Error{constructor(t,r){super(r),this.code=t,this.name="ReportDataError"}}function b(e,t,r){const o=e??t;if(!Number.isSafeInteger(o)||o<1||o>r)throw new l("limit","Invalid report data budget");return o}function k(e){if(typeof e=="string"&&e.length>0&&e.length<=2048)return`s:${e}`;if(typeof e=="number"&&Number.isSafeInteger(e))return`n:${Object.is(e,-0)?0:e}`;throw new l("identity","A stable string or safe integer business key is required")}function O(e){if(typeof e.datasetId!="string"||!e.datasetId.trim()||e.datasetId.length>2048)throw new l("identity","A dataset identity is required");if(e.sourceScope!==void 0&&(typeof e.sourceScope!="string"||!e.sourceScope.trim()||e.sourceScope.length>2048))throw new l("identity","Invalid source scope")}function j(e,t=256){if(!Array.isArray(e)||!e.length||e.length>t)throw new l("limit","A bounded explicit field allowlist is required");const r=new Set;for(const o of e){if(typeof o!="string"||!o.trim()||o.length>2048||["__proto__","constructor","prototype"].includes(o))throw new l("identity","Invalid report field");if(r.has(o))throw new l("duplicate","Duplicate report field");r.add(o)}}function C(e,t){const r=Object.getOwnPropertyDescriptor(e.values,t);if(!r)return;if(!("value"in r))throw new l("value","Report values must be plain scalar data");const o=r.value;if(o===null||typeof o=="boolean"||typeof o=="string"||typeof o=="number"&&Number.isFinite(o))return o;throw new l("value","Report values must be finite scalar data")}function J(e){if(!e||typeof e!="object"||![Object.prototype,null].includes(Object.getPrototypeOf(e)))throw new l("value","Report records must be plain data");const t=Object.getOwnPropertyDescriptor(e,"rowKey"),r=Object.getOwnPropertyDescriptor(e,"values");if(!t||!("value"in t)||!r||!("value"in r)||!r.value||typeof r.value!="object"||![Object.prototype,null].includes(Object.getPrototypeOf(r.value)))throw new l("value","Report records require own scalar keys and plain values");return{rowKey:t.value,values:r.value}}function q(e,t,r={}){const o=b(r.maxRows,5e4,1e5),n=b(r.maxCells,1e6,2e6);if(!Array.isArray(e)||Object.getPrototypeOf(e)!==Array.prototype||e.length>o||e.length*t.length>n)throw new l("limit","Report data exceeds its budget");const c=new Map;for(let s=0;s<e.length;s++){const d=Object.getOwnPropertyDescriptor(e,s);if(!d||!("value"in d))throw new l("value","Sparse or accessor report records are unsupported");const i=J(d.value),a=k(i.rowKey);if(c.has(a))throw new l("duplicate","Duplicate business row key");const u=Object.create(null);for(const p of t){const f=C(i,p);f!==void 0&&(u[p]=f)}c.set(a,{rowKey:i.rowKey,values:u})}return c}function P(e){return e==null||e===""}function F(e,t){return P(e)?t.missing==="zero"?y.parseDecimal(0):void 0:y.parseDecimal(e)}function Q(e){return{coefficient:-e.coefficient,scale:e.scale}}function X(e,t,r,o){const n=F(e,r),c=Object.is(e,t)?n:F(t,r);if(!n||!c)return{equal:L(e,t,r),ratioUnavailable:"missing"};const s=y.addDecimal(c,Q(n)),d={...s,coefficient:s.coefficient<0n?-s.coefficient:s.coefficient},i=y.compareDecimal(d,r.toleranceValue)<=0;return i&&!o?{equal:i}:n.coefficient===0n?{equal:i,delta:y.printDecimal(s),...s.coefficient===0n&&r.zeroDenominator==="zero-if-equal"?{changeRatio:"0"}:{ratioUnavailable:"zero-denominator"}}:{equal:i,delta:y.printDecimal(s),changeRatio:y.printDecimal(y.divideDecimal(s,n,r.ratioDigits??12))}}function L(e,t,r){return r.missing==="empty-equivalent"&&P(e)&&P(t)||Object.is(e,t)}function Y(e){j(e.fields.map(t=>t.field),b(e.maxFields,256,1024));for(const t of e.fields){if(t.type!==void 0&&!["decimal","value"].includes(t.type))throw new l("value","Invalid comparison field type");if(t.missing&&!["distinct","empty-equivalent","zero"].includes(t.missing))throw new l("value","Invalid missing-value policy");if(t.zeroDenominator&&!["omit","zero-if-equal"].includes(t.zeroDenominator))throw new l("value","Invalid zero-denominator policy");if(t.missing==="zero"&&t.type!=="decimal")throw new l("value","Zero missing-value policy requires a decimal field");if(t.tolerance!==void 0&&(t.type!=="decimal"||y.compareDecimal(y.parseDecimal(t.tolerance),y.parseDecimal(0))<0))throw new l("value","Tolerance requires a non-negative decimal");if(t.ratioDigits!==void 0&&(!Number.isInteger(t.ratioDigits)||t.ratioDigits<0||t.ratioDigits>100))throw new l("value","Invalid ratio precision")}return e.fields.map(t=>({...t,toleranceValue:y.parseDecimal(t.tolerance??"0")}))}function M(e,t,r,o,n){let c=!1;for(const s of r){const d=e?C(e,s.field):void 0,i=t?C(t,s.field):void 0,a=s.type==="decimal"?X(d,i,s,!e||!t):{equal:L(d,i,s)};if(e&&t&&a.equal)continue;if(c=!0,o.length>=n)throw new l("limit","Report differences exceed their budget");const{equal:u,...p}=a;o.push({rowKey:(t??e).rowKey,kind:e?t?"changed":"removed":"added",field:s.field,label:s.label??s.field,before:d,after:i,...p})}return c}function ee(e,t,r){O(e),O(t);const o=Y(r);if(e.datasetId!==t.datasetId||e.sourceScope!==t.sourceScope)throw new l("identity","Comparison requires the same business dataset and source scope");const n=r.fields.map(u=>u.field),c=q(e.rows,n,r),s=q(t.rows,n,r),d=b(r.maxDifferences,2e4,1e5),i=[],a={added:0,removed:0,changed:0,unchanged:0,cells:0};for(const[u,p]of c){const f=s.get(u),m=M(p,f,o,i,d);f?m?a.changed++:a.unchanged++:a.removed++}for(const[u,p]of s)c.has(u)||(M(void 0,p,o,i,d),a.added++);return a.cells=i.length,{sourceScope:t.sourceScope,datasetId:t.datasetId,differences:i,counts:a}}function K(e,t){O(t),j(t.fields,b(t.maxFields,256,1024));const r=b(t.maxCells,1e6,2e6),o=new Set(t.fields),n=new Map,c=g.createReportCellResolver(e);let s=0;for(const[d,i]of e.pages.entries())for(const[a,u]of i.components.entries()){if(!u.grid)continue;for(const f of u.grid.cells)if(s+=f.length,s>r)throw new l("limit","Report cell scan exceeds its budget");const p=N.resolveGridLayout(u.grid,u.widthMm,u.heightMm).cells;for(const f of p){const m=c({pageIndex:d,componentIndex:a,rowIndex:f.ri,columnIndex:f.ci}),w=m?.source;if(!m||!w||w.datasetId!==t.datasetId||w.sourceScope!==t.sourceScope||!o.has(w.field))continue;k(w.rowKey);const I=g.reportCellEditKey(m),h=n.get(I);h?(!Object.is(h.context.value,m.value)||h.context.source?.revision!==w.revision||h.context.source?.sourceToken!==w.sourceToken||h.context.editable!==m.editable)&&(h.ambiguous=!0):n.set(I,{context:m,ambiguous:!1})}}return n}function te(e,t){const r=K(e,t),o=new Map,n=b(t.maxRows,5e4,1e5);for(const{context:c,ambiguous:s}of r.values()){if(s)throw new l("conflict","Repeated report cells disagree for the same business field");const d=c.source,i=k(d.rowKey);let a=o.get(i);if(!a){if(o.size>=n)throw new l("limit","Report row extraction exceeds its budget");a={rowKey:d.rowKey,values:Object.create(null)},o.set(i,a)}a.values[d.field]=c.value}return{sourceScope:t.sourceScope,datasetId:t.datasetId,rows:[...o.values()]}}function _(e){return e==null||e===""}function re(e,t,r){if(!t){e.reason="missing-target";return}const{context:o,ambiguous:n}=t;if(e.before=o.value,n){e.status="conflict",e.reason="ambiguous";return}if(!o.editable||r.canEdit?.(o)===!1){e.reason="readonly";return}if(_(e.after)){e.reason="missing-source";return}if(Object.is(o.value,e.after)){e.status="matched",e.reason="unchanged";return}if(r.mode!=="replace"&&!_(o.value)){e.reason="occupied";return}try{const c=g.editFromContext(o,e.after);if(Object.is(c.value,c.previousValue)){e.status="matched",e.reason="unchanged";return}return e.after=c.value,e.status="changed",c}catch{e.status="conflict",e.reason="invalid";return}}function oe(e,t){if(O(t),t.mode!==void 0&&t.mode!=="empty"&&t.mode!=="replace")throw new l("value","Invalid prefill policy");const r=b(t.maxFields,256,1024),o=t.fields.map(f=>f.field),n=[...new Set(t.fields.map(f=>f.sourceField??f.field))];j(o,r),j(n,r);const c=q(t.rows,n,t),s=K(e,{...t,fields:o}),d=b(t.maxChanges,1e4,1e4),i=b(t.maxCells,1e6,2e6);if(c.size*o.length>i)throw new l("limit","Prefill review exceeds its budget");const a=[],u=[],p={matched:0,changed:0,skipped:0,conflict:0};for(const f of c.values())for(const m of t.fields){const w={sourceScope:t.sourceScope,datasetId:t.datasetId,rowKey:f.rowKey,field:m.field},I={source:w,label:m.label??m.field,status:"skipped",after:C(f,m.sourceField??m.field)},h=g.reportCellEditKey({address:{pageIndex:0,componentIndex:0,rowIndex:0,columnIndex:0},source:w}),D=re(I,s.get(h),t);if(D){if(u.length>=d)throw new l("limit","Prefill changes exceed the atomic edit budget");u.push(D)}p[I.status]++,a.push(I)}return{sourceScope:t.sourceScope,datasetId:t.datasetId,items:a,counts:p,edits:u}}function ne(e,t,r){if(t.counts.conflict>0)throw new l("conflict","Resolve prefill conflicts before applying");if(t.edits.length>1e4)throw new l("limit","Prefill changes exceed the atomic edit budget");if(!t.edits.length)return[];const o=[...new Set(t.edits.map(s=>s.source.field))],n=K(e,{sourceScope:t.sourceScope,datasetId:t.datasetId,fields:o}),c=new Set;return t.edits.map(s=>{if(!s.source||s.source.datasetId!==t.datasetId||s.source.sourceScope!==t.sourceScope)throw new l("identity","Prefill identity changed");const d=g.reportCellEditKey(s),i=n.get(d);if(c.has(d))throw new l("duplicate","Duplicate prefill target");if(c.add(d),!i||i.ambiguous||g.sourceChanged(i.context,s)||!Object.is(i.context.value,s.previousValue))throw new l("conflict","Prefill target changed; reload the preview");if(!i.context.editable||r?.(i.context)===!1)throw new l("conflict","Prefill target is read-only");return{address:{...i.context.address},value:g.editFromContext(i.context,s.value).value}})}exports.ReportDataError=l;exports.ReportDrillError=v;exports.compareReportData=ee;exports.createPageWindowIndex=B;exports.createReportDrillRequest=Z;exports.createReportPrefill=oe;exports.dataLimit=b;exports.indexReportDataCells=K;exports.matchReportDrillActions=U;exports.reportDataSnapshotFromPlan=te;exports.reportPrefillInputs=ne;exports.resolveReportDrillReturn=H;exports.validateReportDrillActions=A;
@@ -1 +1 @@
1
- "use strict";const a=require("./json-snapshot-DQdkA_At.cjs"),c=require("./diagnostic-collector-wASg6Fzs.cjs"),s=require("./sha256-DgZAKXqI.cjs"),p=require("./workbook-sheets-CaPAulQ6.cjs");function f(e,r,t,o){if(o===void 0&&!e.diagnosticSummary&&!t){r.forEach(i=>e.diagnostics.push(i));return}const n=c.createDiagnosticCollector(o??c.DEFAULT_DIAGNOSTIC_LIMIT);e.diagnosticSummary?n.merge(e.diagnosticSummary):e.diagnostics.forEach(i=>n.push(i)),t?n.merge(t):r.forEach(i=>n.push(i)),e.diagnostics=n.entries,e.diagnosticSummary=n.snapshot()}function S(e,r){return!a.hasValidDataExplanation(e)||!l(e)||["code","message","severity","path","format","pageIndex","componentIndex","kind","nid","valueState"].some(o=>e[o]!==r[o])||e.componentPath?.length!==r.componentPath?.length||e.componentPath?.some((o,n)=>o!==r.componentPath?.[n])||["datasetId","field","rowKey","tableId","reportScope"].some(o=>e.target?.[o]!==r.target?.[o])?!1:e.extension?.id===r.extension?.id&&e.extension?.version===r.extension?.version}function m(e,r){return!c.validDiagnosticSummary(e)||e.entries.length!==r.length?!1:e.entries.every((t,o)=>!!t&&typeof t=="object"&&S(t,r[o]))}function b(e,r,t,o,n=t.length){n&&e.merge({total:n,counts:{[r]:n},entries:t.map(i=>({code:r,message:i,severity:o})),omitted:n-t.length})}function g(e,r){return e===void 0||typeof e=="number"&&Number.isSafeInteger(e)&&e>=r}function l(e){return!(e.format!==void 0&&!["dom","canvas","pdf","xlsx"].includes(e.format)||!g(e.pageIndex,0)||!g(e.componentIndex,-1)||e.componentPath!==void 0&&!x(e.componentPath)||e.extension!==void 0&&(!e.extension||typeof e.extension.id!="string"||typeof e.extension.version!="string"))}function x(e){if(!Array.isArray(e)||e.length>192)return!1;for(const r of e)if(typeof r!="number"||!Number.isSafeInteger(r)||r<0)return!1;return!0}function F(e){return e&&{...e,sheetNames:p.snapshotSheetNames(e.sheetNames),additionalSheets:p.snapshotAdditionalSheets(e.additionalSheets)}}function P(e,r){if(e.format!=="xlsx")return;const t=e.xlsx?.additionalSheets?.reduce((o,n)=>o+n.rows.reduce((i,d)=>i+d.length,0),0)??0;s.assertBudget(r,"maxCells",e.prepared.stats.cells+t)}function I(e){if(!e)return;const r=t=>{if(!(t instanceof Uint8Array)&&!(t instanceof ArrayBuffer))throw new a.ReportSourceError("validate","字体应为 Uint8Array 或 ArrayBuffer");if(t.byteLength>32e6)throw new s.ReportRuntimeError("budget","单份字体超过 32 MB","$.pdf");return new Uint8Array(t instanceof Uint8Array?t:new Uint8Array(t))};if(e.customFontFaces){const t=e.customFontFaces;return{customFontName:e.customFontName,customFontFaces:{regular:r(t.regular),...t.bold?{bold:r(t.bold)}:{},...t.italic?{italic:r(t.italic)}:{},...t.boldItalic?{boldItalic:r(t.boldItalic)}:{}}}}return{customFontName:e.customFontName,...e.customFontBytes?{customFontBytes:r(e.customFontBytes)}:{}}}function y(e){const r=e?.customFontFaces??(e?.customFontBytes?{regular:e.customFontBytes}:void 0);if(!r)return;const t=["regular","bold","italic","boldItalic"].map(o=>{const n=r[o];if(!n)return[o,null];const i=n instanceof Uint8Array?n:new Uint8Array(n);if(i.byteLength>32e6)throw new s.ReportRuntimeError("budget","单份字体超过 32 MB","$.pdf");return[o,s.portableSha256Hex(i)]});return s.portableSha256Hex(new TextEncoder().encode(JSON.stringify(t)))}const u=new WeakMap;function A(e,r,t){const o=h(e,r,t);let n=!0;return{prepared:o,forward(){if(!n)throw new Error("报表快照只能交接一次");return n=!1,u.set(o,r),o}}}function h(e,r,t){if(s.throwIfAborted(t),!Number.isSafeInteger(r)||r<=0)throw new s.ReportRuntimeError("budget","快照预算应为正安全整数","$.budget.maxPreparedBytes");const o=u.get(e);if(u.delete(e),o!==void 0&&o<=r)return e;const n=a.snapshotReportJson(e,{maxBytes:r,maxNodes:r,check:()=>s.throwIfAborted(t),error:(i,d)=>i==="budget"?new s.ReportRuntimeError("budget",d,"$.budget.maxPreparedBytes"):new a.ReportSourceError("validate",d)});return w(n),n}function v(e){if(e===void 0)return!0;if(!Array.isArray(e))return!1;const r=new Set;return e.every(t=>!t||typeof t!="object"||Array.isArray(t)||typeof t.reportId!="string"||!t.reportId.trim()||!Number.isSafeInteger(t.reportIndex)||t.reportIndex<0||r.has(t.reportIndex)||typeof t.reportScope!="string"||!t.reportScope.trim()||t.reportScope.length>4096||t.revision!==void 0&&typeof t.revision!="string"||t.sourceToken!==void 0&&typeof t.sourceToken!="string"?!1:(r.add(t.reportIndex),!0))}function w(e){if(!v(e.sources))throw new a.ReportSourceError("validate","准备结果来源清单无效");if(!e?.stats||["rows","pages","cells"].some(r=>!Number.isSafeInteger(e.stats[r])||e.stats[r]<0)||!Number.isFinite(e.stats.durationMs)||e.stats.durationMs<0)throw new a.ReportSourceError("validate","准备结果统计无效");if(!Array.isArray(e.diagnostics)||e.diagnostics.some(r=>!r||typeof r.code!="string"||typeof r.message!="string"||!["info","warning","error"].includes(r.severity)||!a.hasValidDataExplanation(r)||!l(r)))throw new a.ReportSourceError("validate","准备结果诊断无效");if(e.diagnosticSummary!==void 0&&!m(e.diagnosticSummary,e.diagnostics))throw new a.ReportSourceError("validate","准备结果诊断摘要无效");if(!e.revisions||typeof e.revisions!="object"||Array.isArray(e.revisions)||Object.values(e.revisions).some(r=>!r||typeof r!="object"||r.revision!==void 0&&typeof r.revision!="string"||r.sourceToken!==void 0&&typeof r.sourceToken!="string"))throw new a.ReportSourceError("validate","准备结果修订无效");if(e.layout&&(!["heuristic","provided","font-bytes"].includes(e.layout.textMetrics)||e.layout.fontFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.layout.fontFingerprint)))throw new a.ReportSourceError("validate","准备结果字体度量标识无效")}function E(e){if(e.layoutPolicy!==void 0&&!["verify","preserve"].includes(e.layoutPolicy))throw new a.ReportSourceError("validate","无效的 layoutPolicy");if(e.format!=="pdf")return;if(e.layoutPolicy==="preserve"&&!e.prepared.layout?.fontFingerprint){f(e.prepared,[{code:"prepared-layout-preserved",severity:"info",message:"显式保持现有分页与几何;未验证排版字体身份,实际 PDF 输出仍遵循 fidelity 校验。"}]);return}const r=e.prepared.layout?.fontFingerprint,t=y(e.pdf);if(r===t&&(r!==void 0||e.prepared.layout?.textMetrics==="heuristic"&&!t))return;const o="已准备计划的字体度量无法与本次 PDF 字体确认一致;保持现有分页,未重新查询或排版。请在 prepare 和 exportPrepared 提供相同字体字节。";if(e.fidelity==="strict")throw new a.ReportSourceError("validate",o);f(e.prepared,[{code:"prepared-font-metrics",severity:"warning",message:o}])}exports.appendPreparedDiagnostics=f;exports.assertPreparedOutputBudget=P;exports.capturePreparedHandoff=A;exports.checkPreparedFont=E;exports.matchingDiagnosticSummary=m;exports.mergeDiagnosticMessages=b;exports.reportFontFingerprint=y;exports.snapshotPdfFonts=I;exports.snapshotPreparedReport=h;exports.snapshotXlsxOptions=F;exports.validPreparedSources=v;exports.validReportDiagnosticLocation=l;exports.validatePreparedMetadata=w;
1
+ "use strict";const a=require("./json-snapshot-DCFEtfFw.cjs"),c=require("./diagnostic-collector-wASg6Fzs.cjs"),s=require("./sha256-DgZAKXqI.cjs"),p=require("./workbook-sheets-CaPAulQ6.cjs");function f(e,r,t,o){if(o===void 0&&!e.diagnosticSummary&&!t){r.forEach(i=>e.diagnostics.push(i));return}const n=c.createDiagnosticCollector(o??c.DEFAULT_DIAGNOSTIC_LIMIT);e.diagnosticSummary?n.merge(e.diagnosticSummary):e.diagnostics.forEach(i=>n.push(i)),t?n.merge(t):r.forEach(i=>n.push(i)),e.diagnostics=n.entries,e.diagnosticSummary=n.snapshot()}function S(e,r){return!a.hasValidDataExplanation(e)||!l(e)||["code","message","severity","path","format","pageIndex","componentIndex","kind","nid","valueState"].some(o=>e[o]!==r[o])||e.componentPath?.length!==r.componentPath?.length||e.componentPath?.some((o,n)=>o!==r.componentPath?.[n])||["datasetId","field","rowKey","tableId","reportScope"].some(o=>e.target?.[o]!==r.target?.[o])?!1:e.extension?.id===r.extension?.id&&e.extension?.version===r.extension?.version}function m(e,r){return!c.validDiagnosticSummary(e)||e.entries.length!==r.length?!1:e.entries.every((t,o)=>!!t&&typeof t=="object"&&S(t,r[o]))}function b(e,r,t,o,n=t.length){n&&e.merge({total:n,counts:{[r]:n},entries:t.map(i=>({code:r,message:i,severity:o})),omitted:n-t.length})}function g(e,r){return e===void 0||typeof e=="number"&&Number.isSafeInteger(e)&&e>=r}function l(e){return!(e.format!==void 0&&!["dom","canvas","pdf","xlsx"].includes(e.format)||!g(e.pageIndex,0)||!g(e.componentIndex,-1)||e.componentPath!==void 0&&!x(e.componentPath)||e.extension!==void 0&&(!e.extension||typeof e.extension.id!="string"||typeof e.extension.version!="string"))}function x(e){if(!Array.isArray(e)||e.length>192)return!1;for(const r of e)if(typeof r!="number"||!Number.isSafeInteger(r)||r<0)return!1;return!0}function F(e){return e&&{...e,sheetNames:p.snapshotSheetNames(e.sheetNames),additionalSheets:p.snapshotAdditionalSheets(e.additionalSheets)}}function P(e,r){if(e.format!=="xlsx")return;const t=e.xlsx?.additionalSheets?.reduce((o,n)=>o+n.rows.reduce((i,d)=>i+d.length,0),0)??0;s.assertBudget(r,"maxCells",e.prepared.stats.cells+t)}function I(e){if(!e)return;const r=t=>{if(!(t instanceof Uint8Array)&&!(t instanceof ArrayBuffer))throw new a.ReportSourceError("validate","字体应为 Uint8Array 或 ArrayBuffer");if(t.byteLength>32e6)throw new s.ReportRuntimeError("budget","单份字体超过 32 MB","$.pdf");return new Uint8Array(t instanceof Uint8Array?t:new Uint8Array(t))};if(e.customFontFaces){const t=e.customFontFaces;return{customFontName:e.customFontName,customFontFaces:{regular:r(t.regular),...t.bold?{bold:r(t.bold)}:{},...t.italic?{italic:r(t.italic)}:{},...t.boldItalic?{boldItalic:r(t.boldItalic)}:{}}}}return{customFontName:e.customFontName,...e.customFontBytes?{customFontBytes:r(e.customFontBytes)}:{}}}function y(e){const r=e?.customFontFaces??(e?.customFontBytes?{regular:e.customFontBytes}:void 0);if(!r)return;const t=["regular","bold","italic","boldItalic"].map(o=>{const n=r[o];if(!n)return[o,null];const i=n instanceof Uint8Array?n:new Uint8Array(n);if(i.byteLength>32e6)throw new s.ReportRuntimeError("budget","单份字体超过 32 MB","$.pdf");return[o,s.portableSha256Hex(i)]});return s.portableSha256Hex(new TextEncoder().encode(JSON.stringify(t)))}const u=new WeakMap;function A(e,r,t){const o=h(e,r,t);let n=!0;return{prepared:o,forward(){if(!n)throw new Error("报表快照只能交接一次");return n=!1,u.set(o,r),o}}}function h(e,r,t){if(s.throwIfAborted(t),!Number.isSafeInteger(r)||r<=0)throw new s.ReportRuntimeError("budget","快照预算应为正安全整数","$.budget.maxPreparedBytes");const o=u.get(e);if(u.delete(e),o!==void 0&&o<=r)return e;const n=a.snapshotReportJson(e,{maxBytes:r,maxNodes:r,check:()=>s.throwIfAborted(t),error:(i,d)=>i==="budget"?new s.ReportRuntimeError("budget",d,"$.budget.maxPreparedBytes"):new a.ReportSourceError("validate",d)});return w(n),n}function v(e){if(e===void 0)return!0;if(!Array.isArray(e))return!1;const r=new Set;return e.every(t=>!t||typeof t!="object"||Array.isArray(t)||typeof t.reportId!="string"||!t.reportId.trim()||!Number.isSafeInteger(t.reportIndex)||t.reportIndex<0||r.has(t.reportIndex)||typeof t.reportScope!="string"||!t.reportScope.trim()||t.reportScope.length>4096||t.revision!==void 0&&typeof t.revision!="string"||t.sourceToken!==void 0&&typeof t.sourceToken!="string"?!1:(r.add(t.reportIndex),!0))}function w(e){if(!v(e.sources))throw new a.ReportSourceError("validate","准备结果来源清单无效");if(!e?.stats||["rows","pages","cells"].some(r=>!Number.isSafeInteger(e.stats[r])||e.stats[r]<0)||!Number.isFinite(e.stats.durationMs)||e.stats.durationMs<0)throw new a.ReportSourceError("validate","准备结果统计无效");if(!Array.isArray(e.diagnostics)||e.diagnostics.some(r=>!r||typeof r.code!="string"||typeof r.message!="string"||!["info","warning","error"].includes(r.severity)||!a.hasValidDataExplanation(r)||!l(r)))throw new a.ReportSourceError("validate","准备结果诊断无效");if(e.diagnosticSummary!==void 0&&!m(e.diagnosticSummary,e.diagnostics))throw new a.ReportSourceError("validate","准备结果诊断摘要无效");if(!e.revisions||typeof e.revisions!="object"||Array.isArray(e.revisions)||Object.values(e.revisions).some(r=>!r||typeof r!="object"||r.revision!==void 0&&typeof r.revision!="string"||r.sourceToken!==void 0&&typeof r.sourceToken!="string"))throw new a.ReportSourceError("validate","准备结果修订无效");if(e.layout&&(!["heuristic","provided","font-bytes"].includes(e.layout.textMetrics)||e.layout.fontFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.layout.fontFingerprint)))throw new a.ReportSourceError("validate","准备结果字体度量标识无效")}function E(e){if(e.layoutPolicy!==void 0&&!["verify","preserve"].includes(e.layoutPolicy))throw new a.ReportSourceError("validate","无效的 layoutPolicy");if(e.format!=="pdf")return;if(e.layoutPolicy==="preserve"&&!e.prepared.layout?.fontFingerprint){f(e.prepared,[{code:"prepared-layout-preserved",severity:"info",message:"显式保持现有分页与几何;未验证排版字体身份,实际 PDF 输出仍遵循 fidelity 校验。"}]);return}const r=e.prepared.layout?.fontFingerprint,t=y(e.pdf);if(r===t&&(r!==void 0||e.prepared.layout?.textMetrics==="heuristic"&&!t))return;const o="已准备计划的字体度量无法与本次 PDF 字体确认一致;保持现有分页,未重新查询或排版。请在 prepare 和 exportPrepared 提供相同字体字节。";if(e.fidelity==="strict")throw new a.ReportSourceError("validate",o);f(e.prepared,[{code:"prepared-font-metrics",severity:"warning",message:o}])}exports.appendPreparedDiagnostics=f;exports.assertPreparedOutputBudget=P;exports.capturePreparedHandoff=A;exports.checkPreparedFont=E;exports.matchingDiagnosticSummary=m;exports.mergeDiagnosticMessages=b;exports.reportFontFingerprint=y;exports.snapshotPdfFonts=I;exports.snapshotPreparedReport=h;exports.snapshotXlsxOptions=F;exports.validPreparedSources=v;exports.validReportDiagnosticLocation=l;exports.validatePreparedMetadata=w;
@@ -1,4 +1,4 @@
1
- import { v as g, R as a, s as y } from "./json-snapshot-x0JpllWL.js";
1
+ import { v as g, R as a, s as y } from "./json-snapshot-CBVWZvyC.js";
2
2
  import { H as v, x as h, G as w } from "./diagnostic-collector-gB07PHy2.js";
3
3
  import { R as d, b, t as c, p as u } from "./sha256-BDQ1Qk7A.js";
4
4
  import { s as x, a as F } from "./workbook-sheets-D4M7XXBh.js";
@@ -1 +1 @@
1
- "use strict";const f=require("./json-snapshot-DQdkA_At.cjs"),s=require("./diagnostic-collector-wASg6Fzs.cjs"),g=require("./runtime-DRSuy_SQ.cjs"),n="mach-report-worker/1";class u extends Error{constructor(e){super(e.message),this.name=e.name,this.code=e.code,this.path=e.path,this.issues=e.issues,this.diagnostics=e.diagnostics,this.diagnosticSummary=e.diagnosticSummary,this.issueSummary=e.issueSummary}}function i(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function l(t,e){return g.validReportExecutionResult(t,e)}function m(t){if(!t||typeof t!="object")return{message:String(t).slice(0,4096)};const e={};for(const r of["code","path","field","message"]){const o=t[r];typeof o=="string"&&(e[r]=o.slice(0,r==="code"?128:4096))}return e}function R(t){const e=m(t);if(!i(t))return e;for(const r of["format","severity","kind","nid"])typeof t[r]=="string"&&(e[r]=t[r].slice(0,4096));for(const r of["pageIndex","componentIndex"])Number.isSafeInteger(t[r])&&t[r]>=0&&(e[r]=t[r]);if(f.hasValidDataExplanation(t)&&t.valueState!==void 0&&i(t.target)){e.valueState=t.valueState;const r={};for(const o of["datasetId","field","rowKey","tableId","reportScope"])t.target[o]!==void 0&&(r[o]=t.target[o]);e.target=r}return i(t.extension)&&typeof t.extension.id=="string"&&typeof t.extension.version=="string"&&(e.extension={id:t.extension.id.slice(0,128),version:t.extension.version.slice(0,64)}),Array.isArray(t.componentPath)&&t.componentPath.length<=192&&t.componentPath.every(r=>Number.isSafeInteger(r)&&r>=0)&&(e.componentPath=t.componentPath),e}function d(t){return{code:i(t)&&typeof t.code=="string"?t.code:"unknown",value:t,...i(t)&&t.valueState!==void 0&&f.hasValidDataExplanation(t)?{valueState:t.valueState}:{}}}function p(t,e,r){const o=s.createDiagnosticCollector(s.DEFAULT_DIAGNOSTIC_LIMIT);if(s.validDiagnosticSummary(r))o.merge({...r,entries:r.entries.slice(0,s.DEFAULT_DIAGNOSTIC_LIMIT).map(d)});else for(const a of t)o.push(d(a));const c=o.snapshot();return{...c,entries:c.entries.map(a=>e(a.value))}}function y(t){if(!(t instanceof Error))return{name:"Error",message:String(t).slice(0,8192)};const e=t,r=Array.isArray(e.diagnostics)?p(e.diagnostics,R,e.diagnosticSummary):void 0,o=Array.isArray(e.issues)?p(e.issues,m):void 0;return{name:t.name.slice(0,128),message:t.message.slice(0,8192),...typeof e.code=="string"?{code:e.code.slice(0,128)}:{},...typeof e.path=="string"?{path:e.path.slice(0,4096)}:{},...o?{issues:o.entries,...o.omitted?{issueSummary:o}:{}}:{},...r?{diagnostics:r.entries,...r.omitted||e.diagnosticSummary!==void 0?{diagnosticSummary:r}:{}}:{}}}function I(t){if(!t||typeof t!="object")return!1;const e=t;return e.protocol===n&&typeof e.id=="string"&&(e.operation==="prepare"||e.operation==="export"||e.operation==="exportPrepared")&&!!e.input&&typeof e.input=="object"}async function h(t,e,r){try{const o=e.operation==="prepare"?await t.prepare({...e.input,onEvent:r}):e.operation==="exportPrepared"?await t.exportPrepared({...e.input,onEvent:r}):await t.export({...e.input,onEvent:r});return{protocol:n,id:e.id,result:o}}catch(o){return{protocol:n,id:e.id,error:y(o)}}}function k(t){const e=t.result;return!e||!("bytes"in e)||!(e.bytes.buffer instanceof ArrayBuffer)?[]:[e.bytes.buffer]}function S(t,e){if(!i(t)||typeof t.taskId!="string"||!t.taskId||e.taskId!==void 0&&t.taskId!==e.taskId||t.correlationId!==e.correlationId||t.reportId!==void 0&&(typeof t.reportId!="string"||!("reportIds"in e&&e.reportIds.includes(t.reportId)))||!["query","validate","layout","assets","encode"].includes(t.stage)||!["started","completed","failed"].includes(t.status))return!1;for(const r of["completed","total"])if(t[r]!==void 0&&(typeof t[r]!="number"||!Number.isFinite(t[r])||t[r]<0))return!1;return t.completed===void 0||t.total===void 0||t.completed<=t.total}exports.REPORT_WORKER_PROTOCOL=n;exports.ReportWorkerError=u;exports.isReportWorkerRequest=I;exports.reportWorkerTransferList=k;exports.runReportWorkerRequest=h;exports.serializeError=y;exports.validReportWorkerEvent=S;exports.validReportWorkerResult=l;
1
+ "use strict";const f=require("./json-snapshot-DCFEtfFw.cjs"),s=require("./diagnostic-collector-wASg6Fzs.cjs"),g=require("./runtime-BRx8Agqr.cjs"),n="mach-report-worker/1";class u extends Error{constructor(e){super(e.message),this.name=e.name,this.code=e.code,this.path=e.path,this.issues=e.issues,this.diagnostics=e.diagnostics,this.diagnosticSummary=e.diagnosticSummary,this.issueSummary=e.issueSummary}}function i(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function l(t,e){return g.validReportExecutionResult(t,e)}function m(t){if(!t||typeof t!="object")return{message:String(t).slice(0,4096)};const e={};for(const r of["code","path","field","message"]){const o=t[r];typeof o=="string"&&(e[r]=o.slice(0,r==="code"?128:4096))}return e}function R(t){const e=m(t);if(!i(t))return e;for(const r of["format","severity","kind","nid"])typeof t[r]=="string"&&(e[r]=t[r].slice(0,4096));for(const r of["pageIndex","componentIndex"])Number.isSafeInteger(t[r])&&t[r]>=0&&(e[r]=t[r]);if(f.hasValidDataExplanation(t)&&t.valueState!==void 0&&i(t.target)){e.valueState=t.valueState;const r={};for(const o of["datasetId","field","rowKey","tableId","reportScope"])t.target[o]!==void 0&&(r[o]=t.target[o]);e.target=r}return i(t.extension)&&typeof t.extension.id=="string"&&typeof t.extension.version=="string"&&(e.extension={id:t.extension.id.slice(0,128),version:t.extension.version.slice(0,64)}),Array.isArray(t.componentPath)&&t.componentPath.length<=192&&t.componentPath.every(r=>Number.isSafeInteger(r)&&r>=0)&&(e.componentPath=t.componentPath),e}function d(t){return{code:i(t)&&typeof t.code=="string"?t.code:"unknown",value:t,...i(t)&&t.valueState!==void 0&&f.hasValidDataExplanation(t)?{valueState:t.valueState}:{}}}function p(t,e,r){const o=s.createDiagnosticCollector(s.DEFAULT_DIAGNOSTIC_LIMIT);if(s.validDiagnosticSummary(r))o.merge({...r,entries:r.entries.slice(0,s.DEFAULT_DIAGNOSTIC_LIMIT).map(d)});else for(const a of t)o.push(d(a));const c=o.snapshot();return{...c,entries:c.entries.map(a=>e(a.value))}}function y(t){if(!(t instanceof Error))return{name:"Error",message:String(t).slice(0,8192)};const e=t,r=Array.isArray(e.diagnostics)?p(e.diagnostics,R,e.diagnosticSummary):void 0,o=Array.isArray(e.issues)?p(e.issues,m):void 0;return{name:t.name.slice(0,128),message:t.message.slice(0,8192),...typeof e.code=="string"?{code:e.code.slice(0,128)}:{},...typeof e.path=="string"?{path:e.path.slice(0,4096)}:{},...o?{issues:o.entries,...o.omitted?{issueSummary:o}:{}}:{},...r?{diagnostics:r.entries,...r.omitted||e.diagnosticSummary!==void 0?{diagnosticSummary:r}:{}}:{}}}function I(t){if(!t||typeof t!="object")return!1;const e=t;return e.protocol===n&&typeof e.id=="string"&&(e.operation==="prepare"||e.operation==="export"||e.operation==="exportPrepared")&&!!e.input&&typeof e.input=="object"}async function h(t,e,r){try{const o=e.operation==="prepare"?await t.prepare({...e.input,onEvent:r}):e.operation==="exportPrepared"?await t.exportPrepared({...e.input,onEvent:r}):await t.export({...e.input,onEvent:r});return{protocol:n,id:e.id,result:o}}catch(o){return{protocol:n,id:e.id,error:y(o)}}}function k(t){const e=t.result;return!e||!("bytes"in e)||!(e.bytes.buffer instanceof ArrayBuffer)?[]:[e.bytes.buffer]}function S(t,e){if(!i(t)||typeof t.taskId!="string"||!t.taskId||e.taskId!==void 0&&t.taskId!==e.taskId||t.correlationId!==e.correlationId||t.reportId!==void 0&&(typeof t.reportId!="string"||!("reportIds"in e&&e.reportIds.includes(t.reportId)))||!["query","validate","layout","assets","encode"].includes(t.stage)||!["started","completed","failed"].includes(t.status))return!1;for(const r of["completed","total"])if(t[r]!==void 0&&(typeof t[r]!="number"||!Number.isFinite(t[r])||t[r]<0))return!1;return t.completed===void 0||t.total===void 0||t.completed<=t.total}exports.REPORT_WORKER_PROTOCOL=n;exports.ReportWorkerError=u;exports.isReportWorkerRequest=I;exports.reportWorkerTransferList=k;exports.runReportWorkerRequest=h;exports.serializeError=y;exports.validReportWorkerEvent=S;exports.validReportWorkerResult=l;
@@ -1,6 +1,6 @@
1
- import { v as p } from "./json-snapshot-x0JpllWL.js";
1
+ import { v as p } from "./json-snapshot-CBVWZvyC.js";
2
2
  import { x as y, H as g, G as c } from "./diagnostic-collector-gB07PHy2.js";
3
- import { v as u } from "./runtime-BE30icyB.js";
3
+ import { v as u } from "./runtime-B5d_lQNQ.js";
4
4
  const n = "mach-report-worker/1";
5
5
  class x extends Error {
6
6
  constructor(e) {
@@ -1,5 +1,5 @@
1
1
  import { v as F } from "./dataset-DL83majE.js";
2
- import { v as D, e as z, p as Z } from "./template-registry-DZOtRY7t.js";
2
+ import { v as D, e as z, p as Z } from "./template-registry-DeVgwEZj.js";
3
3
  import { r as N } from "./diagnostic-collector-gB07PHy2.js";
4
4
  function v(t) {
5
5
  let e = "";
@@ -1,3 +1,3 @@
1
- "use strict";const F=require("./dataset-IrlXbUvh.cjs"),R=require("./template-registry-BMScUmM4.cjs"),N=require("./diagnostic-collector-wASg6Fzs.cjs");function S(t){let e="";for(let o=t;o>0;o=Math.floor((o-1)/26))e=String.fromCharCode(65+(o-1)%26)+e;return e}function M(t){return`${S(t.left)}${t.top}:${S(t.right)}${t.bottom}`}function _(t){let e=0;for(const o of t.toUpperCase())e=e*26+o.charCodeAt(0)-64;return e}function d(t){if(typeof t!="string")throw new Error("Excel 范围应为 A1:B20 格式的字符串");const e=/^\$?([A-Z]{1,3})\$?([1-9]\d{0,6})(?::\$?([A-Z]{1,3})\$?([1-9]\d{0,6}))?$/i.exec(t.trim());if(!e)throw new Error(`Excel 范围无效:${t}`);const o={left:_(e[1]),top:Number(e[2]),right:_(e[3]??e[1]),bottom:Number(e[4]??e[2])};if(o.right<o.left||o.bottom<o.top||o.right>16384||o.bottom>1048576)throw new Error(`Excel 范围超出边界或顺序无效:${t}`);return o}function mt(t,e){if(e!==void 0)return d(e);const o=t.model.rows??[];if(!o.length)return{top:1,left:1,bottom:1,right:1};const r={top:1/0,left:1/0,bottom:1,right:1};for(const n of o)r.top=Math.min(r.top,n.number),r.bottom=Math.max(r.bottom,n.number),r.left=Math.min(r.left,n.min||1),r.right=Math.max(r.right,n.max||1);return r}function dt(t,e,o){const r=t.bottom-t.top+1,n=t.right-t.left+1;if(r>e.limits.maxRows||n>e.limits.maxColumns||r*n>o)throw new Error(`Excel 范围 ${M(t)} 超过导入行、列或单元格上限;请用 sheets/range 缩小范围`);return r*n}function pt(t,e){return t.top<=e.bottom&&t.bottom>=e.top&&t.left<=e.right&&t.right>=e.left}function ut(t,e){const o=[];for(const r of t.model.merges){const n=d(r);if(pt(e,n)){if(n.left<e.left||n.right>e.right||n.top<e.top||n.bottom>e.bottom)throw new Error(`${t.name}: 范围 ${M(e)} 截断合并单元格 ${r},请包含完整合并区域`);o.push(n)}}return o}function wt(t,e){const o=new Map;for(const n of e)o.set(n.top,Math.max(o.get(n.top)??n.top,n.bottom));const r=[];for(let n=t.top;n<=t.bottom;){let s=o.get(n)??n;for(let a=n;a<=s;a++)s=Math.max(s,o.get(a)??a);r.push({top:n,bottom:s}),n=s+1}return r}function yt(t,e,o,r){const n=[];let s,a=0;for(const i of t){const c=i.bottom-i.top+1;if(c>200)throw new Error("合并单元格跨越超过 200 行,无法安全分段;请先缩小或拆分该合并区域");let l=0;for(let h=i.top;h<=i.bottom;h++)l+=r(h);if(l>o&&Number.isFinite(o))throw new Error("合并区域或单行高度超过标准纸张可用高度;请使用 wide 或调整原模板行高");const f=s?i.bottom-s.top+1:c;s&&(f>e||a+l>o)&&(n.push(s),s=void 0,a=0),s?s.bottom=i.bottom:s={...i},a+=l}return s&&n.push(s),n}function Et(t){const e=new Map,o=new Set;for(const r of t){e.set(`${r.top}:${r.left}`,r);for(let n=r.top;n<=r.bottom;n++)for(let s=r.left;s<=r.right;s++)(n!==r.top||s!==r.left)&&o.add(`${n}:${s}`)}return{masters:e,covered:o}}function O(t){return JSON.parse(JSON.stringify(t))}function Mt(t,e){const o=t.template.pages.slice(e.pageStart,e.pageStart+e.pageCount),r=o[0];if(!r)throw new Error(`工作表 ${e.name} 没有可绑定页面`);const n=new Map;let s=[];for(const a of o)for(const i of a.components){if(i.kind==="list"||!i.grid||i.meta?.xlsxSheet!==e.name)continue;const c=d(String(i.meta.xlsxRange)),l=i.grid;s=l.colWidthsMm??[],l.cells.forEach((f,h)=>n.set(c.top+h,{cells:O(f),height:l.rowHeightsMm?.[h]??6}))}if(!s.length||!n.size)throw new Error(`工作表 ${e.name} 缺少导入几何元数据`);return{rows:n,widths:[...s],page:r,range:d(e.range)}}function j(t,e,o){const r=[],n=[];for(let s=e;s<=o;s++){const a=t.rows.get(s);if(!a)throw new Error(`导入模板缺少第 ${s} 行`);for(const i of a.cells)if(i&&s+(i.rowSpan??1)-1>o)throw new Error(`第 ${s} 行合并区域跨越绑定边界,请调整 header/detail 范围`);r.push(O(a.cells)),n.push(a.height)}return{cells:r,rowHeightsMm:n,colWidthsMm:t.widths,paddingMm:.25}}function xt(t,e){const o=d(t.header),r=t.detail?d(t.detail):{...e.range,top:o.bottom+1};for(const n of[o,r])if(n.left!==e.range.left||n.right!==e.range.right||n.top<e.range.top||n.bottom>e.range.bottom||n.top>n.bottom)throw new Error("绑定区域必须位于导入选区内并覆盖其完整列宽");if(r.top!==o.bottom+1)throw new Error("detail 应紧接 header,避免静态内容被隐式删除");if(t.columns.length!==e.widths.length)throw new Error("columns 应逐列映射整个选区;不能自动猜测业务字段");return bt(e,[o.top,o.bottom+1,r.bottom+1]),{header:o,detail:r}}function bt(t,e){for(const[o,r]of t.rows)for(const n of r.cells){const s=o+(n?.rowSpan??1);if(e.some(a=>o<a&&s>a))throw new Error(`第 ${o} 行合并区域跨越绑定边界,请调整 header/detail 范围`)}}function $t(t,e){const o=[];for(const r of N.resolveGridLayout(t,e.reduce((n,s)=>n+s,0),100).cells)for(let n=r.ci;n<Math.min(e.length,r.ci+(r.cell.colSpan??1));n++)o[n]=r.cell;return o}function St(t,e,o,r){if(e)return e;const n=t?.numberFormat;if(!n||n==="General")return;const s=/^(#,##)?0(?:\.(0+))?(%)?$/.exec(n);if(s){const a=s[2]?.length??0;if(a<=100)return s[3]?{kind:"percent",digits:a}:{kind:"number",digits:a,...s[1]?{thousands:!0}:{}}}r.push(`${o}: Excel 数字格式 ${n} 未自动套用到动态数据,请在 columns 中显式声明 format`)}function Rt(t,e,o,r,n){const s=$t(e,r),a=N.resolveGridLayout(o,r.reduce((f,h)=>f+h,0),20).cells;if(a.some(({cell:f})=>(f.colSpan??1)!==1||(f.rowSpan??1)!==1))throw new Error("动态明细样例行不能包含合并格;合并表头可以保留");const i=new Map(a.map(f=>[f.ci,f.cell])),c=new Set,l=t.columns.map((f,h)=>{const g=typeof f=="string"?{field:f}:f;if(!g||typeof g.field!="string"||!g.field.trim()||c.has(g.field))throw new Error(`columns[${h}] 需要唯一的非空 field`);c.add(g.field);const m=s[h]?.text??g.field,p=i.get(h),w=t.inferSampleFormats===!1?g.format:St(p,g.format,g.field,n);return{...g,...w?{format:w}:{},header:g.header??m,widthMm:r[h],style:{...p?.style,...g.style},...g.semanticRole&&!g.align?{align:"auto"}:{},...g.editable===void 0&&p?.editable===!1?{editable:!1}:{}}});return vt(t,s,l),l}function vt(t,e,o){const r=new Map;t.columns.forEach((n,s)=>{const a=e[s];if(!a||typeof n=="string")return;const i=r.get(a)??{style:{}};if(n.header!==void 0){if(i.text!==void 0&&i.text!==n.header)throw new Error("同一合并表头不能配置不同 header");i.text=n.header}kt(i.style,{...n.headerAlign?{align:n.headerAlign}:{},...n.headerStyle}),r.set(a,i)});for(const[n,s]of r)s.text!==void 0&&Object.assign(n,{text:s.text,rawText:s.text,value:s.text}),n.style={...n.style,...s.style},e.forEach((a,i)=>{a===n&&(s.text!==void 0&&(o[i].header=s.text),s.style.align!==void 0&&(o[i].headerAlign=s.style.align))})}function kt(t,e){for(const o of Object.keys(e))if(e[o]!==void 0){if(t[o]!==void 0&&t[o]!==e[o])throw new Error(`同一合并表头不能配置不同 ${o}`);Object.assign(t,{[o]:e[o]})}}function Bt(t,e){const o=t.page,r=e.rowHeightsMm.reduce((n,s)=>n+s,0);return{...o,heightMm:Math.max(o.heightMm,r+(o.marginTopMm??0)+(o.marginBottomMm??0)),components:[{kind:"rect",leftMm:o.marginLeftMm??0,topMm:o.marginTopMm??0,widthMm:t.widths.reduce((n,s)=>n+s,0),heightMm:r,grid:e}]}}function At(t,e,o,r){const n=Mt(t,e),{header:s,detail:a}=xt(o,n),i=j(n,n.range.top,s.bottom),c=j(n,a.top,a.top),l={...n.page,components:[]},f={kind:"list",id:`bound:${e.name}`,dataset:o.dataset??"detail",title:e.name,leftMm:l.marginLeftMm??0,topMm:l.marginTopMm??0,widthMm:n.widths.reduce((h,g)=>h+g,0),layout:l.layout??"page",headerGrid:i,columns:Rt(o,i,c,n.widths,r),rowHeightMm:c.rowHeightsMm[0],headerEveryPage:!0,align:"auto",paddingMm:.25,...o.rowKey?{rowKey:o.rowKey}:{},...o.revisionField?{revisionField:o.revisionField}:{},...o.sourceTokenField?{sourceTokenField:o.sourceTokenField}:{},...o.groupBy?{groupBy:o.groupBy}:{},...o.grandTotal===void 0?{}:{grandTotal:o.grandTotal}};return l.components.push(f),a.bottom===n.range.bottom?[l]:(r.push(`${e.name}: 明细区域后的静态内容保留为后续独立页面,不推断动态页脚定位`),[l,Bt(n,j(n,a.bottom+1,n.range.bottom))])}function V(t,e){const o=R.validateReportTemplate(t.template);if(!o.ok)throw new Error(`导入模板无效:${o.errors[0]?.message}`);if(!e.length)throw new Error("至少需要一个 Excel 业务绑定");const r=new Map;for(const c of e){if(!t.sheets.some(l=>l.name===c.sheet)||r.has(c.sheet))throw new Error(`绑定工作表不存在或重复:${c.sheet}`);r.set(c.sheet,c)}const n=[...t.warnings],s=t.sheets.flatMap(c=>{const l=r.get(c.name);return l?At(t,c,l,n):O(t.template.pages.slice(c.pageStart,c.pageStart+c.pageCount))}),a={...O(t.template),pages:s},i=R.validateReportTemplate(a);if(!i.ok)throw new Error(`业务模板无效:${i.errors[0]?.path} ${i.errors[0]?.message}`);return{template:a,warnings:n}}function z(t){const e=t.semanticRole??(t.type==="number"||t.type==="decimal"?"measure":t.type==="date"?"date":"text");return{field:t.field,semanticRole:e,editable:!1,...t.type==="number"&&t.digits!==void 0?{format:{kind:"number",digits:t.digits}}:{},...t.type==="date"?{format:{kind:"date",pattern:"YYYY-MM-DD"}}:{}}}function Ct(t){return t===null||typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function H(t,e=0){if(Ct(t))return;if(!t||typeof t!="object"||e>16)throw new Error("绑定会话元数据只允许有限深度的普通 JSON 值");const o=Object.getPrototypeOf(t);if(Array.isArray(t)?o!==Array.prototype:o!==Object.prototype&&o!==null)throw new Error("绑定会话不能包含特殊对象原型");if(Object.getOwnPropertySymbols(t).length)throw new Error("绑定会话不能包含 Symbol");if(Array.isArray(t)&&Object.keys(t).length!==t.length)throw new Error("绑定会话数组不能包含空位或额外属性");for(const[r,n]of Object.entries(Object.getOwnPropertyDescriptors(t)))if(!(Array.isArray(t)&&r==="length")){if(["__proto__","prototype","constructor"].includes(r)||n.get||n.set||!n.enumerable)throw new Error("绑定会话包含不安全元数据");H(n.value,e+1)}}function Ot(t,e){return Tt(t,e)}function Tt(t,e){const o=t.sheets.find(c=>c.name===e.sheet);if(!o)return[];const r=d(e.regions.header),n=d(e.regions.detail),s=[r.top,r.bottom+1,n.bottom+1],a=[],i=new Set;for(const c of t.template.pages.slice(o.pageStart,o.pageStart+o.pageCount))for(const l of c.components){if(l.kind==="list"||!l.grid||l.meta?.xlsxSheet!==e.sheet)continue;const f=d(String(l.meta.xlsxRange));l.grid.cells.forEach((h,g)=>{const m=f.top+g;for(const p of h){const w=s.some(b=>m<b&&m+(p?.rowSpan??1)>b),x=m===n.top&&((p?.rowSpan??1)>1||(p?.colSpan??1)>1);if(!w&&!x)continue;const E=w?"$.recipe.regions":"$.recipe.regions.detail";i.has(E)||(i.add(E),a.push({path:E,code:"region",message:w?`第 ${m} 行合并区域跨越绑定边界,请选择完整合并区域`:"动态明细原型行不能包含合并格"}))}})}return a}function Z(t){return JSON.parse(JSON.stringify(t))}function T(t){return t instanceof Error?t.message:String(t)}function u(t,e,o,r){t.push({path:e,code:o,message:r})}function U(t,e){return{fields:t.fields,...e?{rowKey:e}:{}}}function Ft(t,e){const o=new Set;for(const[r,n]of t.entries()){const s=`$.datasets[${r}]`;if(!n||typeof n.id!="string"||!n.id.trim()||o.has(n.id)){u(e,s,"schema","数据集标识应非空且唯一");continue}o.add(n.id);try{F.validateDatasetRows([],U(n,n.rowKey));for(const[a,i]of n.fields.entries())i.digits!==void 0&&(!Number.isInteger(i.digits)||i.digits<0||i.digits>100)&&u(e,`${s}.fields[${a}].digits`,"schema","显示精度应为 0–100 的整数")}catch(a){u(e,s,"schema",T(a))}}}function Nt(t,e,o){const r=t.sheets.find(i=>i.name===e.sheet);if(!r){u(o,"$.recipe.sheet","source","指定的工作表不存在");return}let n;try{n=d(r.range)}catch(i){u(o,"$.source.sheets","source",T(i));return}const s=new Map;for(const i of["title","header","detail","footer"]){const c=e.regions?.[i];if(!(!c&&(i==="title"||i==="footer")))try{const l=d(c??"");if(l.left!==n.left||l.right!==n.right||l.top<n.top||l.bottom>n.bottom)throw new Error("区域必须覆盖选区完整列宽,并位于原始工作表内");s.set(i,l)}catch(l){u(o,`$.recipe.regions.${i}`,"region",T(l))}}const a=[...s.values()];a.length&&(a[0].top!==n.top||a[a.length-1].bottom!==n.bottom)&&u(o,"$.recipe.regions","region","标题、表头、明细、页脚应完整覆盖来源,不能隐式删除静态内容");for(let i=1;i<a.length;i++)a[i].top!==a[i-1].bottom+1&&u(o,"$.recipe.regions","region","各区域应顺序相邻且不重叠")}function It(t,e,o,r){if(!Array.isArray(t.fields)||t.fields.length!==o)return u(r,"$.recipe.fields","mapping","每个物理 Excel 列必须显式绑定一个业务字段"),0;const n=new Set(e.fields.map(i=>i.field)),s=new Set;let a=0;t.fields.forEach((i,c)=>{typeof i!="string"||!n.has(i)?u(r,`$.recipe.fields[${c}]`,"mapping","请选择契约中已声明的字段"):s.has(i)?u(r,`$.recipe.fields[${c}]`,"mapping","同一业务字段不能重复绑定物理列"):(a++,s.add(i))});try{if(!t.rowKey)throw new Error("请明确选择稳定业务主键,不能使用展示行号");const i=U(e,t.rowKey),c=F.validateDatasetRows(e.samples??[],i,{path:`$.datasets.${e.id}.samples`,maxRows:100,maxCells:2e5,maxIssues:30});for(const l of c.issues)u(r,l.path,l.code==="row-key"?"row-key":"schema",l.message)}catch(i){u(r,"$.recipe.rowKey","row-key",T(i))}return a}function Q(t,e){const o=[];return!e||e.version!=="1.0"?[{path:"$.recipe.version",code:"schema",message:"不支持的 Excel 绑定配置版本"}]:(Nt(t,e,o),o.length||o.push(...Ot(t,e)),o)}function X(t,e,o){const r=[];if(!e||e.version!=="1.0")return{ok:!1,issues:[{path:"$.recipe.version",code:"schema",message:"不支持的 Excel 绑定配置版本"}],mapped:0,total:0};Ft(o,r);const n=t.sheets.find(i=>i.name===e.sheet)?.columnCount??0,s=o.find(i=>i.id===e.dataset);let a=0;return s?r.some(i=>i.code==="schema")||(a=It(e,s,n,r)):u(r,"$.recipe.dataset","schema","请明确选择宿主提供的数据集契约"),{ok:r.length===0,issues:r,mapped:a,total:n}}function tt(t,e,o){const r=X(t,e,o);if(!e||e.version!=="1.0")return r;const n=[...Q(t,e),...r.issues];return{...r,ok:n.length===0,issues:n}}function Kt(t,e,o,r){const n=tt(t,e,o);if(!n.ok)throw new Error(n.issues.map(f=>`${f.path}: ${f.message}`).join(`
1
+ "use strict";const F=require("./dataset-IrlXbUvh.cjs"),R=require("./template-registry-B-AK1oam.cjs"),N=require("./diagnostic-collector-wASg6Fzs.cjs");function S(t){let e="";for(let o=t;o>0;o=Math.floor((o-1)/26))e=String.fromCharCode(65+(o-1)%26)+e;return e}function M(t){return`${S(t.left)}${t.top}:${S(t.right)}${t.bottom}`}function _(t){let e=0;for(const o of t.toUpperCase())e=e*26+o.charCodeAt(0)-64;return e}function d(t){if(typeof t!="string")throw new Error("Excel 范围应为 A1:B20 格式的字符串");const e=/^\$?([A-Z]{1,3})\$?([1-9]\d{0,6})(?::\$?([A-Z]{1,3})\$?([1-9]\d{0,6}))?$/i.exec(t.trim());if(!e)throw new Error(`Excel 范围无效:${t}`);const o={left:_(e[1]),top:Number(e[2]),right:_(e[3]??e[1]),bottom:Number(e[4]??e[2])};if(o.right<o.left||o.bottom<o.top||o.right>16384||o.bottom>1048576)throw new Error(`Excel 范围超出边界或顺序无效:${t}`);return o}function mt(t,e){if(e!==void 0)return d(e);const o=t.model.rows??[];if(!o.length)return{top:1,left:1,bottom:1,right:1};const r={top:1/0,left:1/0,bottom:1,right:1};for(const n of o)r.top=Math.min(r.top,n.number),r.bottom=Math.max(r.bottom,n.number),r.left=Math.min(r.left,n.min||1),r.right=Math.max(r.right,n.max||1);return r}function dt(t,e,o){const r=t.bottom-t.top+1,n=t.right-t.left+1;if(r>e.limits.maxRows||n>e.limits.maxColumns||r*n>o)throw new Error(`Excel 范围 ${M(t)} 超过导入行、列或单元格上限;请用 sheets/range 缩小范围`);return r*n}function pt(t,e){return t.top<=e.bottom&&t.bottom>=e.top&&t.left<=e.right&&t.right>=e.left}function ut(t,e){const o=[];for(const r of t.model.merges){const n=d(r);if(pt(e,n)){if(n.left<e.left||n.right>e.right||n.top<e.top||n.bottom>e.bottom)throw new Error(`${t.name}: 范围 ${M(e)} 截断合并单元格 ${r},请包含完整合并区域`);o.push(n)}}return o}function wt(t,e){const o=new Map;for(const n of e)o.set(n.top,Math.max(o.get(n.top)??n.top,n.bottom));const r=[];for(let n=t.top;n<=t.bottom;){let s=o.get(n)??n;for(let a=n;a<=s;a++)s=Math.max(s,o.get(a)??a);r.push({top:n,bottom:s}),n=s+1}return r}function yt(t,e,o,r){const n=[];let s,a=0;for(const i of t){const c=i.bottom-i.top+1;if(c>200)throw new Error("合并单元格跨越超过 200 行,无法安全分段;请先缩小或拆分该合并区域");let l=0;for(let h=i.top;h<=i.bottom;h++)l+=r(h);if(l>o&&Number.isFinite(o))throw new Error("合并区域或单行高度超过标准纸张可用高度;请使用 wide 或调整原模板行高");const f=s?i.bottom-s.top+1:c;s&&(f>e||a+l>o)&&(n.push(s),s=void 0,a=0),s?s.bottom=i.bottom:s={...i},a+=l}return s&&n.push(s),n}function Et(t){const e=new Map,o=new Set;for(const r of t){e.set(`${r.top}:${r.left}`,r);for(let n=r.top;n<=r.bottom;n++)for(let s=r.left;s<=r.right;s++)(n!==r.top||s!==r.left)&&o.add(`${n}:${s}`)}return{masters:e,covered:o}}function O(t){return JSON.parse(JSON.stringify(t))}function Mt(t,e){const o=t.template.pages.slice(e.pageStart,e.pageStart+e.pageCount),r=o[0];if(!r)throw new Error(`工作表 ${e.name} 没有可绑定页面`);const n=new Map;let s=[];for(const a of o)for(const i of a.components){if(i.kind==="list"||!i.grid||i.meta?.xlsxSheet!==e.name)continue;const c=d(String(i.meta.xlsxRange)),l=i.grid;s=l.colWidthsMm??[],l.cells.forEach((f,h)=>n.set(c.top+h,{cells:O(f),height:l.rowHeightsMm?.[h]??6}))}if(!s.length||!n.size)throw new Error(`工作表 ${e.name} 缺少导入几何元数据`);return{rows:n,widths:[...s],page:r,range:d(e.range)}}function j(t,e,o){const r=[],n=[];for(let s=e;s<=o;s++){const a=t.rows.get(s);if(!a)throw new Error(`导入模板缺少第 ${s} 行`);for(const i of a.cells)if(i&&s+(i.rowSpan??1)-1>o)throw new Error(`第 ${s} 行合并区域跨越绑定边界,请调整 header/detail 范围`);r.push(O(a.cells)),n.push(a.height)}return{cells:r,rowHeightsMm:n,colWidthsMm:t.widths,paddingMm:.25}}function xt(t,e){const o=d(t.header),r=t.detail?d(t.detail):{...e.range,top:o.bottom+1};for(const n of[o,r])if(n.left!==e.range.left||n.right!==e.range.right||n.top<e.range.top||n.bottom>e.range.bottom||n.top>n.bottom)throw new Error("绑定区域必须位于导入选区内并覆盖其完整列宽");if(r.top!==o.bottom+1)throw new Error("detail 应紧接 header,避免静态内容被隐式删除");if(t.columns.length!==e.widths.length)throw new Error("columns 应逐列映射整个选区;不能自动猜测业务字段");return bt(e,[o.top,o.bottom+1,r.bottom+1]),{header:o,detail:r}}function bt(t,e){for(const[o,r]of t.rows)for(const n of r.cells){const s=o+(n?.rowSpan??1);if(e.some(a=>o<a&&s>a))throw new Error(`第 ${o} 行合并区域跨越绑定边界,请调整 header/detail 范围`)}}function $t(t,e){const o=[];for(const r of N.resolveGridLayout(t,e.reduce((n,s)=>n+s,0),100).cells)for(let n=r.ci;n<Math.min(e.length,r.ci+(r.cell.colSpan??1));n++)o[n]=r.cell;return o}function St(t,e,o,r){if(e)return e;const n=t?.numberFormat;if(!n||n==="General")return;const s=/^(#,##)?0(?:\.(0+))?(%)?$/.exec(n);if(s){const a=s[2]?.length??0;if(a<=100)return s[3]?{kind:"percent",digits:a}:{kind:"number",digits:a,...s[1]?{thousands:!0}:{}}}r.push(`${o}: Excel 数字格式 ${n} 未自动套用到动态数据,请在 columns 中显式声明 format`)}function Rt(t,e,o,r,n){const s=$t(e,r),a=N.resolveGridLayout(o,r.reduce((f,h)=>f+h,0),20).cells;if(a.some(({cell:f})=>(f.colSpan??1)!==1||(f.rowSpan??1)!==1))throw new Error("动态明细样例行不能包含合并格;合并表头可以保留");const i=new Map(a.map(f=>[f.ci,f.cell])),c=new Set,l=t.columns.map((f,h)=>{const g=typeof f=="string"?{field:f}:f;if(!g||typeof g.field!="string"||!g.field.trim()||c.has(g.field))throw new Error(`columns[${h}] 需要唯一的非空 field`);c.add(g.field);const m=s[h]?.text??g.field,p=i.get(h),w=t.inferSampleFormats===!1?g.format:St(p,g.format,g.field,n);return{...g,...w?{format:w}:{},header:g.header??m,widthMm:r[h],style:{...p?.style,...g.style},...g.semanticRole&&!g.align?{align:"auto"}:{},...g.editable===void 0&&p?.editable===!1?{editable:!1}:{}}});return vt(t,s,l),l}function vt(t,e,o){const r=new Map;t.columns.forEach((n,s)=>{const a=e[s];if(!a||typeof n=="string")return;const i=r.get(a)??{style:{}};if(n.header!==void 0){if(i.text!==void 0&&i.text!==n.header)throw new Error("同一合并表头不能配置不同 header");i.text=n.header}kt(i.style,{...n.headerAlign?{align:n.headerAlign}:{},...n.headerStyle}),r.set(a,i)});for(const[n,s]of r)s.text!==void 0&&Object.assign(n,{text:s.text,rawText:s.text,value:s.text}),n.style={...n.style,...s.style},e.forEach((a,i)=>{a===n&&(s.text!==void 0&&(o[i].header=s.text),s.style.align!==void 0&&(o[i].headerAlign=s.style.align))})}function kt(t,e){for(const o of Object.keys(e))if(e[o]!==void 0){if(t[o]!==void 0&&t[o]!==e[o])throw new Error(`同一合并表头不能配置不同 ${o}`);Object.assign(t,{[o]:e[o]})}}function Bt(t,e){const o=t.page,r=e.rowHeightsMm.reduce((n,s)=>n+s,0);return{...o,heightMm:Math.max(o.heightMm,r+(o.marginTopMm??0)+(o.marginBottomMm??0)),components:[{kind:"rect",leftMm:o.marginLeftMm??0,topMm:o.marginTopMm??0,widthMm:t.widths.reduce((n,s)=>n+s,0),heightMm:r,grid:e}]}}function At(t,e,o,r){const n=Mt(t,e),{header:s,detail:a}=xt(o,n),i=j(n,n.range.top,s.bottom),c=j(n,a.top,a.top),l={...n.page,components:[]},f={kind:"list",id:`bound:${e.name}`,dataset:o.dataset??"detail",title:e.name,leftMm:l.marginLeftMm??0,topMm:l.marginTopMm??0,widthMm:n.widths.reduce((h,g)=>h+g,0),layout:l.layout??"page",headerGrid:i,columns:Rt(o,i,c,n.widths,r),rowHeightMm:c.rowHeightsMm[0],headerEveryPage:!0,align:"auto",paddingMm:.25,...o.rowKey?{rowKey:o.rowKey}:{},...o.revisionField?{revisionField:o.revisionField}:{},...o.sourceTokenField?{sourceTokenField:o.sourceTokenField}:{},...o.groupBy?{groupBy:o.groupBy}:{},...o.grandTotal===void 0?{}:{grandTotal:o.grandTotal}};return l.components.push(f),a.bottom===n.range.bottom?[l]:(r.push(`${e.name}: 明细区域后的静态内容保留为后续独立页面,不推断动态页脚定位`),[l,Bt(n,j(n,a.bottom+1,n.range.bottom))])}function V(t,e){const o=R.validateReportTemplate(t.template);if(!o.ok)throw new Error(`导入模板无效:${o.errors[0]?.message}`);if(!e.length)throw new Error("至少需要一个 Excel 业务绑定");const r=new Map;for(const c of e){if(!t.sheets.some(l=>l.name===c.sheet)||r.has(c.sheet))throw new Error(`绑定工作表不存在或重复:${c.sheet}`);r.set(c.sheet,c)}const n=[...t.warnings],s=t.sheets.flatMap(c=>{const l=r.get(c.name);return l?At(t,c,l,n):O(t.template.pages.slice(c.pageStart,c.pageStart+c.pageCount))}),a={...O(t.template),pages:s},i=R.validateReportTemplate(a);if(!i.ok)throw new Error(`业务模板无效:${i.errors[0]?.path} ${i.errors[0]?.message}`);return{template:a,warnings:n}}function z(t){const e=t.semanticRole??(t.type==="number"||t.type==="decimal"?"measure":t.type==="date"?"date":"text");return{field:t.field,semanticRole:e,editable:!1,...t.type==="number"&&t.digits!==void 0?{format:{kind:"number",digits:t.digits}}:{},...t.type==="date"?{format:{kind:"date",pattern:"YYYY-MM-DD"}}:{}}}function Ct(t){return t===null||typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function H(t,e=0){if(Ct(t))return;if(!t||typeof t!="object"||e>16)throw new Error("绑定会话元数据只允许有限深度的普通 JSON 值");const o=Object.getPrototypeOf(t);if(Array.isArray(t)?o!==Array.prototype:o!==Object.prototype&&o!==null)throw new Error("绑定会话不能包含特殊对象原型");if(Object.getOwnPropertySymbols(t).length)throw new Error("绑定会话不能包含 Symbol");if(Array.isArray(t)&&Object.keys(t).length!==t.length)throw new Error("绑定会话数组不能包含空位或额外属性");for(const[r,n]of Object.entries(Object.getOwnPropertyDescriptors(t)))if(!(Array.isArray(t)&&r==="length")){if(["__proto__","prototype","constructor"].includes(r)||n.get||n.set||!n.enumerable)throw new Error("绑定会话包含不安全元数据");H(n.value,e+1)}}function Ot(t,e){return Tt(t,e)}function Tt(t,e){const o=t.sheets.find(c=>c.name===e.sheet);if(!o)return[];const r=d(e.regions.header),n=d(e.regions.detail),s=[r.top,r.bottom+1,n.bottom+1],a=[],i=new Set;for(const c of t.template.pages.slice(o.pageStart,o.pageStart+o.pageCount))for(const l of c.components){if(l.kind==="list"||!l.grid||l.meta?.xlsxSheet!==e.sheet)continue;const f=d(String(l.meta.xlsxRange));l.grid.cells.forEach((h,g)=>{const m=f.top+g;for(const p of h){const w=s.some(b=>m<b&&m+(p?.rowSpan??1)>b),x=m===n.top&&((p?.rowSpan??1)>1||(p?.colSpan??1)>1);if(!w&&!x)continue;const E=w?"$.recipe.regions":"$.recipe.regions.detail";i.has(E)||(i.add(E),a.push({path:E,code:"region",message:w?`第 ${m} 行合并区域跨越绑定边界,请选择完整合并区域`:"动态明细原型行不能包含合并格"}))}})}return a}function Z(t){return JSON.parse(JSON.stringify(t))}function T(t){return t instanceof Error?t.message:String(t)}function u(t,e,o,r){t.push({path:e,code:o,message:r})}function U(t,e){return{fields:t.fields,...e?{rowKey:e}:{}}}function Ft(t,e){const o=new Set;for(const[r,n]of t.entries()){const s=`$.datasets[${r}]`;if(!n||typeof n.id!="string"||!n.id.trim()||o.has(n.id)){u(e,s,"schema","数据集标识应非空且唯一");continue}o.add(n.id);try{F.validateDatasetRows([],U(n,n.rowKey));for(const[a,i]of n.fields.entries())i.digits!==void 0&&(!Number.isInteger(i.digits)||i.digits<0||i.digits>100)&&u(e,`${s}.fields[${a}].digits`,"schema","显示精度应为 0–100 的整数")}catch(a){u(e,s,"schema",T(a))}}}function Nt(t,e,o){const r=t.sheets.find(i=>i.name===e.sheet);if(!r){u(o,"$.recipe.sheet","source","指定的工作表不存在");return}let n;try{n=d(r.range)}catch(i){u(o,"$.source.sheets","source",T(i));return}const s=new Map;for(const i of["title","header","detail","footer"]){const c=e.regions?.[i];if(!(!c&&(i==="title"||i==="footer")))try{const l=d(c??"");if(l.left!==n.left||l.right!==n.right||l.top<n.top||l.bottom>n.bottom)throw new Error("区域必须覆盖选区完整列宽,并位于原始工作表内");s.set(i,l)}catch(l){u(o,`$.recipe.regions.${i}`,"region",T(l))}}const a=[...s.values()];a.length&&(a[0].top!==n.top||a[a.length-1].bottom!==n.bottom)&&u(o,"$.recipe.regions","region","标题、表头、明细、页脚应完整覆盖来源,不能隐式删除静态内容");for(let i=1;i<a.length;i++)a[i].top!==a[i-1].bottom+1&&u(o,"$.recipe.regions","region","各区域应顺序相邻且不重叠")}function It(t,e,o,r){if(!Array.isArray(t.fields)||t.fields.length!==o)return u(r,"$.recipe.fields","mapping","每个物理 Excel 列必须显式绑定一个业务字段"),0;const n=new Set(e.fields.map(i=>i.field)),s=new Set;let a=0;t.fields.forEach((i,c)=>{typeof i!="string"||!n.has(i)?u(r,`$.recipe.fields[${c}]`,"mapping","请选择契约中已声明的字段"):s.has(i)?u(r,`$.recipe.fields[${c}]`,"mapping","同一业务字段不能重复绑定物理列"):(a++,s.add(i))});try{if(!t.rowKey)throw new Error("请明确选择稳定业务主键,不能使用展示行号");const i=U(e,t.rowKey),c=F.validateDatasetRows(e.samples??[],i,{path:`$.datasets.${e.id}.samples`,maxRows:100,maxCells:2e5,maxIssues:30});for(const l of c.issues)u(r,l.path,l.code==="row-key"?"row-key":"schema",l.message)}catch(i){u(r,"$.recipe.rowKey","row-key",T(i))}return a}function Q(t,e){const o=[];return!e||e.version!=="1.0"?[{path:"$.recipe.version",code:"schema",message:"不支持的 Excel 绑定配置版本"}]:(Nt(t,e,o),o.length||o.push(...Ot(t,e)),o)}function X(t,e,o){const r=[];if(!e||e.version!=="1.0")return{ok:!1,issues:[{path:"$.recipe.version",code:"schema",message:"不支持的 Excel 绑定配置版本"}],mapped:0,total:0};Ft(o,r);const n=t.sheets.find(i=>i.name===e.sheet)?.columnCount??0,s=o.find(i=>i.id===e.dataset);let a=0;return s?r.some(i=>i.code==="schema")||(a=It(e,s,n,r)):u(r,"$.recipe.dataset","schema","请明确选择宿主提供的数据集契约"),{ok:r.length===0,issues:r,mapped:a,total:n}}function tt(t,e,o){const r=X(t,e,o);if(!e||e.version!=="1.0")return r;const n=[...Q(t,e),...r.issues];return{...r,ok:n.length===0,issues:n}}function Kt(t,e,o,r){const n=tt(t,e,o);if(!n.ok)throw new Error(n.issues.map(f=>`${f.path}: ${f.message}`).join(`
2
2
  `));const s=t.sheets.find(f=>f.name===e.sheet),a={...t,sheets:[{...s,pageStart:0}],template:{...t.template,pages:t.template.pages.slice(s.pageStart,s.pageStart+s.pageCount)}},i=new Map(o.find(f=>f.id===e.dataset).fields.map(f=>[f.field,f])),c={sheet:e.sheet,dataset:e.dataset,header:e.regions.header,detail:e.regions.detail,rowKey:e.rowKey,inferSampleFormats:!1,columns:e.fields.map(f=>z(i.get(f)))},l=V(a,[c]);return{document:R.defineReportTemplate({...r,template:l.template}),recipe:Z(e),warnings:l.warnings}}function jt(t,e){if(t?.version!=="1.0"||!Array.isArray(t.fields)||t.fields.length>16384||t.fields.some(o=>typeof o!="string"))throw new Error("Excel 绑定配置无效");if(typeof t.dataset!="string"||typeof t.rowKey!="string"||!t.regions||typeof e?.id!="string"||typeof e.name!="string")throw new Error("Excel 绑定参数或标识无效");for(const o of Object.values(t.regions))o!==""&&d(o)}function Gt(t){for(const e of t.sheets)if(d(e.range),typeof e.name!="string"||![e.index,e.rowCount,e.columnCount,e.pageCount].every(o=>Number.isInteger(o)&&o>0)||!Number.isInteger(e.pageStart)||e.pageStart<0||e.pageStart+e.pageCount>t.template.pages.length)throw new Error("Excel 绑定工作表几何元数据无效")}function Ht(t,e,o){if(H({sheets:t.sheets,warnings:t.warnings,recipe:e,identity:o}),!Array.isArray(t.sheets)||!t.sheets.length||t.sheets.length>32||!Array.isArray(t.warnings)||t.warnings.some(r=>typeof r!="string"))throw new Error("Excel 绑定来源元数据无效");if(jt(e,o),!t.sheets.some(r=>r.name===e.sheet))throw new Error("Excel 绑定工作表不存在");Gt(t)}function et(t,e,o){return Ht(t,e,o),R.parseReportTemplate({schemaVersion:"1.0",id:o.id,name:o.name,template:t.template}),Z({version:"1.0",source:t,recipe:e,identity:o})}function Dt(t){if(typeof t=="string"&&t.length>1e7)throw new Error("Excel 绑定会话超过 1000 万字符上限");const e=typeof t=="string"?JSON.parse(t):t;if(!e||e.version!=="1.0"||e.recipe?.version!=="1.0"||!Array.isArray(e.source?.sheets))throw new Error("Excel 绑定会话结构或版本无效");return et(e.source,e.recipe,e.identity)}function Lt(t,e,o,r){const n=t.sheets.find(c=>c.name===e);if(!n)throw new Error("工作表不存在");const s=d(n.range),a=Math.min(o,r),i=Math.max(o,r);if(!Number.isInteger(a)||!Number.isInteger(i)||a<s.top||i>s.bottom)throw new Error("选中行超出来源区域");return M({...s,top:a,bottom:i})}function P(t,e,o){const r=t??e;if(!Number.isInteger(r)||r<1||r>o)throw new Error(`预览窗口大小应为 1–${o} 的整数`);return r}function Y(t,e,o){const r=t??e;if(!Number.isInteger(r))throw new Error("预览起点应为整数");return Math.max(e,Math.min(o,r))}function Jt(t,e,o={}){const r=t.sheets.find(g=>g.name===e);if(!r)throw new Error("指定的工作表不存在");const n=d(r.range),s=Y(o.row,n.top,n.bottom),a=Y(o.column,n.left,n.right),i=Math.min(n.bottom,s+P(o.rows,24,100)-1),c=Math.min(n.right,a+P(o.columns,12,32)-1),l=Array.from({length:i-s+1},(g,m)=>({row:s+m,cells:[]})),f=new Set;for(const g of t.template.pages.slice(r.pageStart,r.pageStart+r.pageCount))for(const m of g.components){if(m.kind==="list"||!m.grid||m.meta?.xlsxSheet!==e)continue;const p=d(String(m.meta.xlsxRange));if(p.bottom<s||p.top>i)continue;const w=N.resolveGridLayout(m.grid,m.widthMm,m.heightMm);for(const x of w.cells)h(x.cell,p.top+x.ri,p.left+x.ci)}for(const g of l){for(let m=a;m<=c;m++)f.has(`${g.row}:${m}`)||g.cells.push({address:`${S(m)}${g.row}`,row:g.row,column:m,text:"",rowSpan:1,colSpan:1,continued:!1});g.cells.sort((m,p)=>m.column-p.column)}return{top:s,bottom:i,left:a,right:c,source:n,rows:l,columns:Array.from({length:c-a+1},(g,m)=>({column:a+m,name:S(a+m)}))};function h(g,m,p){const w=m+(g.rowSpan??1)-1,x=p+(g.colSpan??1)-1;if(w<s||m>i||x<a||p>c)return;const E=Math.max(s,m),b=Math.max(a,p),J=Math.min(i,w)-E+1,W=Math.min(c,x)-b+1;l[E-s].cells.push({address:`${S(p)}${m}`,row:E,column:b,text:g.text??g.rawText??String(g.value??""),rowSpan:J,colSpan:W,continued:E!==m||b!==p,style:g.style});for(let I=E;I<E+J;I++)for(let K=b;K<b+W;K++)f.add(`${I}:${K}`)}}function v(t){return JSON.parse(JSON.stringify(t))}function ot(t,e){const o=t.sheets.find(i=>i.name===e);if(!o)throw new Error("指定的工作表不存在");const r=t.template.pages.slice(o.pageStart,o.pageStart+o.pageCount),n=r[0];if(!n)throw new Error("工作表没有可绑定的页面");const s={page:n,range:d(o.range),widths:[],heights:new Map,cells:[],cellsByRow:new Map,topOffsets:new Map};for(const i of r)for(const c of i.components){if(c.kind==="list"||!c.grid||c.meta?.xlsxSheet!==e)continue;const l=d(String(c.meta.xlsxRange));s.widths.length||(s.widths=[...c.grid.colWidthsMm??[]]),c.grid.cells.forEach((f,h)=>s.heights.set(l.top+h,c.grid.rowHeightsMm?.[h]??6));for(const f of N.resolveGridLayout(c.grid,c.widthMm,c.heightMm).cells){const h=l.top+f.ri,g=l.left+f.ci;s.cells.push({top:h,left:g,bottom:h+(f.cell.rowSpan??1)-1,right:g+(f.cell.colSpan??1)-1,cell:f.cell})}}if(s.widths.length!==s.range.right-s.range.left+1||s.heights.size!==s.range.bottom-s.range.top+1)throw new Error("来源工作表几何元数据不完整");let a=0;for(let i=s.range.top;i<=s.range.bottom;i++)s.topOffsets.set(i,a),a+=s.heights.get(i);s.topOffsets.set(s.range.bottom+1,a);for(const i of s.cells)for(let c=i.top;c<=i.bottom;c++){const l=s.cellsByRow.get(c)??[];l.push(i),s.cellsByRow.set(c,l)}return s}function rt(t,e){return t.left<=e.right&&e.left<=t.right&&t.top<=e.bottom&&e.top<=t.bottom}function k(t,e){return t.top<=e.top&&t.bottom>=e.bottom&&t.left<=e.left&&t.right>=e.right}function nt(t,e){return t.widths.slice(e.left-t.range.left,e.right-t.range.left+1).reduce((o,r)=>o+r,0)}function C(t,e){return(t.topOffsets.get(e.bottom+1)??0)-(t.topOffsets.get(e.top)??0)}function A(t,e){const o=new Set;for(let r=e.top;r<=e.bottom;r++)for(const n of t.cellsByRow.get(r)??[])rt(n,e)&&o.add(n);return[...o]}function st(t,e){for(const o of A(t,e))if(!k(e,o))throw new Error(`合并区域 ${M(o)} 跨越选区 ${M(e)}`)}function G(t,e,o=[]){const r=A(t,e);for(const i of r)if(!k(e,i))throw new Error(`合并区域 ${M(i)} 跨越选区 ${M(e)}`);const n=[],s=new Map,a=new Set;for(const i of r)if(!o.some(c=>k(c,i))){s.set(`${i.top}:${i.left}`,i);for(let c=i.top;c<=i.bottom;c++)for(let l=i.left;l<=i.right;l++)a.add(`${c}:${l}`)}for(let i=e.top;i<=e.bottom;i++){const c=[];for(let l=e.left;l<=e.right;l++){const f=s.get(`${i}:${l}`);f?(c.push(v(f.cell)),l=f.right):a.has(`${i}:${l}`)||c.push(null)}n.push(c)}return{cells:n,colWidthsMm:t.widths.slice(e.left-t.range.left,e.right-t.range.left+1),rowHeightsMm:Array.from({length:e.bottom-e.top+1},(i,c)=>t.heights.get(e.top+c)),paddingMm:.25}}function B(t){const e=d(t.range);return t.headerRange?{...e,top:d(t.headerRange).top}:e}function D(t,e){return(t.page.marginTopMm??0)+(t.topOffsets.get(e)??0)}function it(t,e){return{xlsxFlow:{version:"1.0",columnStart:e.left-t.range.left}}}function at(t,e,o,r,n=[]){const s=G(t,o,n);for(const a of s.cells)for(const i of a)i&&(i.editable=!1,delete i.source);return{kind:"rect",nid:r,leftMm:t.page.marginLeftMm??0,topMm:D(t,o.top),widthMm:nt(t,o),heightMm:C(t,o),grid:s,meta:it(t,o)}}function Wt(t,e,o,r){const n=d(o.range),s=B(o),a=G(t,n),i=new Map(r.fields.map(f=>[f.field,f])),c=a.colWidthsMm,l=o.fields.map((f,h)=>({...z(i.get(f)),header:i.get(f).label??f,widthMm:c[h],style:v(a.cells[0]?.[h]?.style??{}),align:"auto"}));return{kind:"list",id:`xlsx-region:${o.id}`,dataset:o.dataset,rowKey:o.rowKey,...o.revisionField?{revisionField:o.revisionField}:{},...o.sourceTokenField?{sourceTokenField:o.sourceTokenField}:{},title:`${e.sheet} · ${o.id}`,layout:t.page.layout??"wide",leftMm:(t.page.marginLeftMm??0)+t.widths.slice(0,n.left-t.range.left).reduce((f,h)=>f+h,0),topMm:D(t,s.top),widthMm:nt(t,n),rowHeightMm:a.rowHeightsMm[0],header:!!o.headerRange,headerEveryPage:o.mode==="repeat",...o.mode==="record"?{cardinality:"record"}:{},...o.headerRange?{headerGrid:G(t,d(o.headerRange))}:{},columns:l,paddingMm:a.paddingMm,meta:it(t,n)}}function q(t,e,o,r=0){const n=[],s=t.page.heightMm-(t.page.marginTopMm??0)-(t.page.marginBottomMm??0)-r,a=Math.max(1,Math.min(100,Math.floor(1e4/t.widths.length)));for(let i=e;i<=o;){const c=i;let l=i,f=0;for(;i<=o;){let h=i;for(let m=i;m<=h;m++)for(const p of t.cellsByRow.get(m)??[])h=Math.max(h,p.bottom);if(h>o)throw new Error("静态合并区域跨越动态绑定边界,请调整区域");const g=C(t,{...t.range,top:i,bottom:h});if(i>c&&(h-c+1>a||f+g>s))break;if(g>s)throw new Error("静态合并区域高度超过单页可用高度,请调整原始模板");f+=g,l=h,i=h+1}n.push({range:{...t.range,top:c,bottom:l},bindings:[]})}return n}function _t(t,e){const o=[...e.regions].sort((i,c)=>B(i).top-B(c).top),r=[];let n=t.range.top;const s=e.footerRange?C(t,d(e.footerRange)):0;for(const i of o){const c=B(i),l=r[r.length-1];if(l?.bindings.length&&l.range.top===c.top&&l.range.bottom===c.bottom){l.bindings.push(i);continue}n<c.top&&r.push(...q(t,n,c.top-1,s)),r.push({range:{...t.range,top:c.top,bottom:c.bottom},bindings:[i]}),n=c.bottom+1}const a=e.footerRange?d(e.footerRange).top-1:t.range.bottom;return n<=a&&r.push(...q(t,n,a,s)),r}function Pt(t,e,o,r,n){const s=[],a=o.bindings.map(B),i=o.bindings.some(l=>l.mode==="repeat"),c=A(t,o.range).some(l=>!a.some(f=>k(f,l)));!i&&(!o.bindings.length||c)&&s.push(at(t,e,o.range,`xlsx-static:${r}`,a));for(const l of o.bindings)s.push(Wt(t,e,l,n.find(f=>f.id===l.dataset)));return{components:s,flow:{componentIds:s.map(l=>l.kind==="list"?l.id:l.nid),topMm:D(t,o.range.top),heightMm:C(t,o.range)}}}function Yt(t,e,o,r){const n=ot(t,e.sheet),s={...v(n.page),components:[]},a=_t(n,e).map((i,c)=>Pt(n,e,i,c,o));if(s.components=a.flatMap(i=>i.components),s.flow={bands:a.map(i=>i.flow)},s.meta={xlsxFlow:{version:"1.0",templateId:r,sheet:e.sheet,fullWidthsMm:n.widths}},e.footerRange){const i=d(e.footerRange),c=at(n,e,i,"xlsx-footer");c.pageAnchor="footer",c.topMm=s.heightMm-(s.marginBottomMm??0)-c.heightMm,s.components.push(c)}return{...v(t.template),pages:[s]}}function $(t){return t instanceof Error?t.message:String(t)}function y(t,e,o,r){t.push({path:e,code:o,message:r})}function L(t,e,o=!1){const r=d(t);if(!k(e.range,r))throw new Error("绑定范围应完整位于来源工作表内");if(o&&r.top!==r.bottom)throw new Error("每个动态区域应选择一行原型;多个数据行由 repeat 自动扩展");return st(e,r),r}function qt(t){const e=t.cell;return!!e.formula||!!e.children?.length||e.value!==null&&e.value!==void 0&&e.value!==""||!!e.text||!!e.rawText}function Vt(t,e,o){if(!t.headerRange)return;const r=L(t.headerRange,e);if(r.left!==o.left||r.right!==o.right||r.bottom+1!==o.top)throw new Error("区域表头应与原型等列宽,并紧接原型上方");return r}function zt(t,e){const o=L(t.range,e,!0),r=Vt(t,e,o);if(st(e,{...e.range,top:r?.top??o.top,bottom:o.bottom}),A(e,o).some(s=>s.bottom!==s.top||s.left!==s.right))throw new Error("动态原型行不能包含合并格;请保留合并表头并选择其下方数据行");if(t.mode==="repeat"){const s={...e.range,top:r?.top??o.top,bottom:o.bottom};if(A(e,s).some(a=>!k({...o,top:s.top},a)&&qt(a)))throw new Error("纵向重复区域的旁列存在静态内容,无法安全拉伸;请扩大区域或将静态内容移至独立行")}return{...o,top:r?.top??o.top}}function lt(t){if(!t||t.version!=="2.0"||typeof t.sheet!="string"||!Array.isArray(t.regions)||!t.regions.length||t.regions.length>128)throw new Error("多区域绑定应为 version 2.0,并包含 1–128 个区域")}function ct(t,e){const o=[];try{lt(e)}catch(a){return[{path:"$.recipe",code:"schema",message:$(a)}]}let r;try{r=ot(t,e.sheet)}catch(a){return[{path:"$.recipe.sheet",code:"source",message:$(a)}]}const n=new Set,s=[];if(e.regions.forEach((a,i)=>{const c=`$.recipe.regions[${i}]`;try{if(!a||typeof a.id!="string"||!a.id.trim()||n.has(a.id))throw new Error("区域标识应非空且唯一");if(n.add(a.id),!["record","repeat"].includes(a.mode))throw new Error("区域模式应为 record 或 repeat");const l=zt(a,r);for(const f of s){if(rt(l,f.range))throw new Error(`区域与 ${f.path} 重叠(含表头)`);if(l.top<=f.range.bottom&&f.range.top<=l.bottom&&(a.mode==="repeat"||f.mode==="repeat"))throw new Error("同一行不能并排放置重复区域;请按纵向顺序排列");if(l.top<=f.range.bottom&&f.range.top<=l.bottom&&(l.top!==f.range.top||l.bottom!==f.range.bottom))throw new Error("并排单记录区域应使用相同的起止行(包括表头),避免不明确的位移")}s.push({range:l,mode:a.mode,path:c})}catch(l){y(o,c,"region",$(l))}}),e.footerRange)try{const a=L(e.footerRange,r);if(a.left!==r.range.left||a.right!==r.range.right||a.bottom!==r.range.bottom)throw new Error("重复页尾应覆盖完整列宽并位于来源最后几行");if(s.some(i=>i.range.bottom>=a.top))throw new Error("页尾与动态区域或区域表头相交");if(C(r,a)>=r.page.heightMm-(r.page.marginTopMm??0)-(r.page.marginBottomMm??0))throw new Error("页尾高度占满单页,不能为报表明细预留空间")}catch(a){y(o,"$.recipe.footerRange","region",$(a))}return o}function Zt(t,e){const o=new Map;for(const[r,n]of t.entries())try{if(!n||typeof n.id!="string"||!n.id.trim()||o.has(n.id))throw new Error("数据集标识应非空且唯一");F.validateDatasetRows([],{fields:n.fields,...n.rowKey?{rowKey:n.rowKey}:{}});for(const s of n.fields)if(s.digits!==void 0&&(!Number.isInteger(s.digits)||s.digits<0||s.digits>100))throw new Error("显示精度应为 0–100 的整数");o.set(n.id,n)}catch(s){y(e,`$.datasets[${r}]`,"schema",$(s))}return o}function Ut(t,e,o,r){const n=d(t.range),s=n.right-n.left+1;if(!Array.isArray(t.fields)||t.fields.length!==s)return y(r,`${o}.fields`,"mapping","区域每个物理列应显式绑定一个字段"),0;const a=new Set(e.fields.map(l=>l.field)),i=new Set;let c=0;if(t.fields.forEach((l,f)=>{!a.has(l)||i.has(l)?y(r,`${o}.fields[${f}]`,"mapping","请选择契约内已声明且不重复的字段"):(i.add(l),c++)}),!t.rowKey)y(r,`${o}.rowKey`,"row-key","每个区域应声明稳定业务主键");else{const l=F.validateDatasetRows(e.samples??[],{fields:e.fields,rowKey:t.rowKey},{path:`$.datasets.${e.id}.samples`,maxRows:100,maxIssues:30});for(const f of l.issues)y(r,f.path,f.code==="row-key"?"row-key":"schema",f.message)}for(const l of["revisionField","sourceTokenField"])t[l]!==void 0&&!a.has(t[l])&&y(r,`${o}.${l}`,"source","并发字段应引用同一区域数据集契约内的字段");return t.mode==="record"&&(e.samples?.length??0)>1&&y(r,o,"schema","record 区域数据集最多一行;多行请使用 repeat"),c}function ft(t,e){const o=[];try{lt(t)}catch(a){return{ok:!1,issues:[{path:"$.recipe",code:"schema",message:$(a)}],mapped:0,total:0}}const r=Zt(e,o);let n=0,s=0;for(const[a,i]of t.regions.entries()){const c=`$.recipe.regions[${a}]`;try{const l=d(i.range);s+=l.right-l.left+1;const f=r.get(i.dataset);f?n+=Ut(i,f,c,o):y(o,`${c}.dataset`,"source","请选择宿主提供的数据集契约")}catch(l){y(o,c,"schema",$(l))}}return{ok:o.length===0,issues:o,mapped:n,total:s}}function gt(t,e,o){const r=ft(e,o),n=[...ct(t,e),...r.issues];return{...r,ok:!n.length,issues:n}}function Qt(t,e,o,r){const n=gt(t,e,o);if(!n.ok)throw new Error(n.issues.map(s=>`${s.path}: ${s.message}`).join(`
3
3
  `));return{document:R.defineReportTemplate({...r,template:Yt(t,e,o,r.id)}),recipe:v(e),warnings:[...t.warnings]}}function Xt(t){if(!t||t.version!=="2.0"||typeof t.sheet!="string"||!Array.isArray(t.regions)||!t.regions.length||t.regions.length>128)throw new Error("多区域绑定会话配置或版本无效");for(const e of t.regions){if(!e||typeof e.id!="string"||typeof e.dataset!="string"||typeof e.rowKey!="string"||!["record","repeat"].includes(e.mode)||!Array.isArray(e.fields)||e.fields.length>2048||e.fields.some(o=>typeof o!="string"))throw new Error("多区域绑定会话的区域结构无效");e.range&&d(e.range),e.headerRange&&d(e.headerRange)}t.footerRange&&d(t.footerRange)}function ht(t,e,o){if(H({sheets:t.sheets,warnings:t.warnings,recipe:e,identity:o}),Xt(e),!Array.isArray(t.sheets)||!t.sheets.length||!Array.isArray(t.warnings)||t.warnings.some(r=>typeof r!="string")||!t.sheets.some(r=>r.name===e.sheet))throw new Error("多区域绑定会话的来源无效");for(const r of t.sheets)if(d(r.range),![r.index,r.rowCount,r.columnCount,r.pageCount].every(n=>Number.isInteger(n)&&n>0)||!Number.isInteger(r.pageStart)||r.pageStart<0||r.pageStart+r.pageCount>t.template.pages.length)throw new Error("多区域绑定会话的工作表几何无效");return R.parseReportTemplate({schemaVersion:"1.0",...o,template:t.template}),v({version:"2.0",source:t,recipe:e,identity:o})}function te(t){if(typeof t=="string"&&t.length>1e7)throw new Error("绑定会话超过 1000 万字符上限");const e=typeof t=="string"?JSON.parse(t):t;if(!e||e.version!=="2.0"||!e.source||!e.recipe||!e.identity)throw new Error("多区域绑定会话结构或版本无效");return ht(e.source,e.recipe,e.identity)}function ee(t,e,o,r=o){const n=t.sheets.find(i=>i.name===e);if(!n)throw new Error("工作表不存在");const s=d(n.range);if(![o.row,o.column,r.row,r.column].every(Number.isInteger))throw new Error("单元格坐标应为整数");const a={top:Math.min(o.row,r.row),bottom:Math.max(o.row,r.row),left:Math.min(o.column,r.column),right:Math.max(o.column,r.column)};if(a.top<s.top||a.bottom>s.bottom||a.left<s.left||a.right>s.right)throw new Error("选区超出来源工作表");return M(a)}exports.bindExcelTemplate=V;exports.checkedRange=dt;exports.columnName=S;exports.createExcelBindingDocument=Kt;exports.createExcelBindingSession=et;exports.createExcelRegionBindingDocument=Qt;exports.createExcelRegionBindingSession=ht;exports.excelBindingCellRange=ee;exports.excelBindingRowRange=Lt;exports.getExcelSheetWindow=Jt;exports.mergeLookup=Et;exports.mergeRowGroups=wt;exports.parseExcelBindingSession=Dt;exports.parseExcelRegionBindingSession=te;exports.parseImportRange=d;exports.rangeName=M;exports.rowSegments=yt;exports.selectedMerges=ut;exports.selectedRange=mt;exports.validateExcelBindingFields=X;exports.validateExcelBindingRecipe=tt;exports.validateExcelBindingRegions=Q;exports.validateExcelRegionBindings=gt;exports.validateExcelRegionFields=ft;exports.validateExcelRegionGeometry=ct;
@@ -1 +1 @@
1
- "use strict";const e=require("./encoding-Cipno7dq.cjs");e.serveReportEncodingWorker();
1
+ "use strict";const e=require("./encoding-DRVXs5xm.cjs");e.serveReportEncodingWorker();
@@ -1,2 +1,2 @@
1
- import { s as r } from "./encoding-CEkBtlUP.js";
1
+ import { s as r } from "./encoding-Amq3XrtU.js";
2
2
  r();
@@ -1,10 +1,10 @@
1
1
  import { G as Q, x as X } from "./diagnostic-collector-gB07PHy2.js";
2
- import { d as Z, m as T, e as tt, f as et, b as st, s as M, a as A, g as at, h as rt, i as ot, r as nt } from "./prepared-Cyuh61fJ.js";
3
- import { Q as S, R as h, v as it, S as ct, N as O, H as k, n as dt, J as mt, M as pt, o as ft } from "./json-snapshot-x0JpllWL.js";
2
+ import { d as Z, m as T, e as tt, f as et, b as st, s as M, a as A, g as at, h as rt, i as ot, r as nt } from "./prepared-CBJ7BkK0.js";
3
+ import { Q as S, R as h, v as it, S as ct, N as O, H as k, n as dt, J as mt, M as pt, o as ft } from "./json-snapshot-CBVWZvyC.js";
4
4
  import { g as $ } from "./report-params-D9tBuM9B.js";
5
5
  import { l as N, r as gt, R as lt } from "./param-validation-CnDEd2l-.js";
6
6
  import { t as P, b as x, D as ut, v as xt, c as B, R as D } from "./sha256-BDQ1Qk7A.js";
7
- import { b as z } from "./template-registry-DZOtRY7t.js";
7
+ import { b as z } from "./template-registry-DeVgwEZj.js";
8
8
  import { T as yt } from "./template-serialization-CWmHq7lX.js";
9
9
  import { r as _ } from "./assets-C4MIvzQ4.js";
10
10
  import { f as wt, P as ht, e as vt } from "./record-bindings-Cv7lFiof.js";
@@ -1 +1 @@
1
- "use strict";var z=Object.create;var A=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var Z=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!Y.call(e,r)&&r!==s&&A(e,r,{get:()=>t[r],enumerable:!(o=Q(t,r))||o.enumerable});return e};var T=(e,t,s)=>(s=e!=null?z(K(e)):{},Z(t||!e||!e.__esModule?A(s,"default",{value:e,enumerable:!0}):s,e));const B=require("./diagnostic-collector-wASg6Fzs.cjs"),h=require("./prepared-CSywIEAZ.cjs"),d=require("./json-snapshot-DQdkA_At.cjs"),L=require("./report-params-VTg8MoCp.cjs"),C=require("./param-validation-C-8sRJLq.cjs"),i=require("./sha256-DgZAKXqI.cjs"),V=require("./template-registry-BMScUmM4.cjs"),ee=require("./template-serialization-CqQY4zDg.cjs"),$=require("./assets-BYdpkTIt.cjs"),F=require("./record-bindings-B7djSjNs.cjs");function te(e){let t=`$.pages.${e.pageIndex}`;if(e.componentIndex<0)return t;t+=`.components.${e.componentIndex}`;const s=e.componentPath??[];for(let o=0;o+1<s.length;o+=3)t+=`.grid.cells.${s[o]}.${s[o+1]}`,s[o+2]!==void 0&&(t+=`.children.${s[o+2]}`);return t}function E(e=[]){return e.map(t=>({...t,path:te(t)}))}function re(e,t){const s=B.createDiagnosticCollector(t??(e.diagnosticSummary?B.DEFAULT_DIAGNOSTIC_LIMIT:void 0));return e.diagnosticSummary?s.merge(e.diagnosticSummary):e.diagnostics.forEach(o=>s.push(o)),s}function q(e,t){t.diagnosticSummary?e.merge({...t.diagnosticSummary,entries:E(t.diagnosticSummary.entries)}):E(t.diagnostics).forEach(s=>e.push(s))}function se(e){const t=e.prepared.diagnosticSummary?.counts,s=t?!!(t["asset-render-failed"]||t["asset-budget-exceeded"]):e.prepared.diagnostics.some(o=>o.code==="asset-render-failed"||o.code==="asset-budget-exceeded");if(e.fidelity==="strict"&&s)throw new d.ReportSourceError("validate","严格输出拒绝已有资产渲染降级,请修复组件后重新准备报表。")}async function j(e,t,s=Date.now()){const o=e.prepared;h.assertPreparedOutputBudget(e,t),se(e);const r=re(o,e.diagnosticLimit),a=e.format==="pdf"?await import("@agile-team/mach-report/pdf"):void 0;i.throwIfAborted(e.signal);const g=e.pdf?.customFontFaces??(e.pdf?.customFontBytes?{regular:e.pdf.customFontBytes}:void 0),f=a&&g?a.createFontBytesMeasurer(g):void 0,m=d.createReportTaskReporter(e),c=await m.run("encode",async()=>{let u;const R={fidelity:e.fidelity,diagnosticLimit:e.diagnosticLimit??(o.diagnosticSummary?B.DEFAULT_DIAGNOSTIC_LIMIT:void 0),signal:e.signal,onProgress:(n,y)=>m.progress("encode",n,y)};if(e.format==="pdf"){i.throwIfAborted(e.signal);const n=await a.renderPlanToPdf(o.plan,{...e.pdf,...f?{measurer:f}:{},...R});u=n.bytes,q(r,n),h.mergeDiagnosticMessages(r,"pdf-fidelity",n.fidelityWarnings,"warning",n.fidelityWarningCount),h.mergeDiagnosticMessages(r,"pdf-page",n.pageErrors,"error",n.pageErrorCount),n.unsupportedTextCount&&r.push({code:"pdf-font",message:`${n.unsupportedTextCount} 段文本包含当前字体不支持的字符`,severity:"warning"})}else{const{renderPlanToXlsx:n}=await import("@agile-team/mach-report/xlsx");i.throwIfAborted(e.signal);const y=await n(o.plan,{...e.xlsx,...R});u=new Uint8Array(y.buffer),q(r,y),h.mergeDiagnosticMessages(r,"xlsx-fidelity",y.warnings,"warning",y.warningCount),y.notes?.forEach(S=>r.push({code:"xlsx-snapshot",message:S,severity:"info"}))}return i.throwIfAborted(e.signal),u});i.assertBudget(t,"maxOutputBytes",c.byteLength);const{plan:w,...x}=o;return{...x,diagnostics:r.entries,...e.diagnosticLimit===void 0&&!o.diagnosticSummary?{}:{diagnosticSummary:r.snapshot()},bytes:c,format:e.format,contentType:e.format==="pdf"?"application/pdf":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",stats:{...x.stats,durationMs:Date.now()-s,outputBytes:c.byteLength}}}function P(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ae(e){return P(e)?["rows","pages","cells"].every(t=>typeof e[t]=="number"&&Number.isSafeInteger(e[t])&&e[t]>=0)&&typeof e.durationMs=="number"&&Number.isFinite(e.durationMs)&&e.durationMs>=0:!1}function oe(e){return Array.isArray(e)&&e.every(t=>P(t)&&typeof t.code=="string"&&typeof t.message=="string"&&["info","warning","error"].includes(t.severity)&&d.hasValidDataExplanation(t)&&h.validReportDiagnosticLocation(t))}function ne(e){return P(e)&&Object.values(e).every(t=>P(t)&&(t.revision===void 0||typeof t.revision=="string")&&(t.sourceToken===void 0||typeof t.sourceToken=="string"))}function ie(e){return e===void 0?!0:P(e)&&["heuristic","provided","font-bytes"].includes(e.textMetrics)&&(e.fontFingerprint===void 0||typeof e.fontFingerprint=="string"&&/^[a-f0-9]{64}$/.test(e.fontFingerprint))}function J(e,t){if(!P(e)||!ae(e.stats)||!oe(e.diagnostics)||!ne(e.revisions)||!ie(e.layout)||!h.validPreparedSources(e.sources)||e.diagnosticSummary!==void 0&&!h.matchingDiagnosticSummary(e.diagnosticSummary,e.diagnostics))return!1;if(t==="prepare")return V.validateRenderPlan(e.plan).ok;const s=e.format==="pdf"?"application/pdf":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";return e.bytes instanceof Uint8Array&&(e.format==="pdf"||e.format==="xlsx")&&e.contentType===s}function _(e,t){if(!J(e,"export")||!("format"in e)||e.format!==t)throw new d.ReportSourceError("validate","报表执行器返回的导出结果与请求格式不一致或元数据无效")}function N(e){return{...e,reportIds:[...e.reportIds],...e.params?{params:{...e.params}}:{}}}function G(e,t){if(t.length===0)throw new d.ReportSourceError("config","缺少报表 ID");return t.map(s=>{if(!Object.prototype.hasOwnProperty.call(e,s))throw new d.ReportSourceError("config",`未注册报表 ${s}`);return e[s]})}function D(e){return e.grid?.cells.reduce((t,s)=>t+s.reduce((o,r)=>o+(r?1+(r.children?.reduce((a,g)=>a+D(g),0)??0):0),0),0)??0}function ce(e,t,s){return e.pages.reduce((o,r)=>o+r.components.reduce((a,g)=>g.kind!=="list"?a+D(g):a+d.estimateListLayoutCells(g,t,s),0),0)}function de(e,t=Object.keys(e)){return G(e,t).map((s,o)=>{const r=t[o],a=L.getReportParamDefs(e,[r]);return{id:r,params:JSON.parse(JSON.stringify(a)),paramsSchema:C.reportParamsJsonSchema(a),datasetsSchema:Object.fromEntries(Object.entries(s.dataSchema??{}).map(([g,f])=>[g,d.templateDatasetJsonSchema(typeof s.template=="function"?void 0:s.template,g,f)])),capabilities:{save:!!s.provider?.save,export:!!s.provider?.export,templates:!!s.provider?.templates}}})}function W(e,t){G(e,t.reportIds);const s=C.validateReportParams(L.getReportParamDefs(e,t.reportIds),t.params),o=t.reportIds.flatMap(a=>C.validateReportParams(L.getReportParamDefs(e,[a]),t.params).issues),r=new Map(o.map(a=>[JSON.stringify(a),a]));return{...s,ok:r.size===0,issues:[...r.values()]}}function M(e,t){const s=V.validateRenderPlan(e.plan);if(!s.ok)throw new d.ReportSourceError("validate",`执行器返回无效计划:${s.errors[0]?.path}`);const o=e.plan.pages.length,r=e.plan.pages.reduce((a,g)=>a+g.components.reduce((f,m)=>f+D(m),0),0);return i.assertBudget(t,"maxRows",e.stats.rows),i.assertBudget(t,"maxPages",o),i.assertBudget(t,"maxCells",r),{...e,stats:{...e.stats,pages:o,cells:r}}}function U(e,t){const s=W(e.reports,t);if(!s.ok)throw new C.ReportParamValidationError(s.issues)}function pe(e){const t={...i.DEFAULT_REPORT_RUNTIME_BUDGET,...e.budget};i.validateBudget(t);const s=async(r,a)=>{const g=Date.now();let f=0,m=0;const c=B.createDiagnosticCollector(r.diagnosticLimit),w={},x=[],u=Object.fromEntries(Object.entries(e.reports).map(([p,l])=>[p,{...l,pagination:{...e.pagination,...l.pagination,...a?{measurer:a}:{}},dataValidation:{...l.dataValidation,maxRows:Math.min(t.maxRows??1e5,l.dataValidation?.maxRows??1/0),maxCells:Math.min(t.maxCells??2e6,l.dataValidation?.maxCells??1/0)}}])),n=await d.createReportSource(u,{maxPages:t.maxPages,maxCells:t.maxCells,maxChartComponents:t.maxChartComponents,onDatasets:(p,l,v)=>{try{f+=d.templateDatasetRowCount(v,l,{maxRows:t.maxRows,signal:r.signal})}catch(b){throw b instanceof ee.TreeRowLimitError?new i.ReportRuntimeError("budget",b.message,"$.budget.maxRows"):b}i.assertBudget(t,"maxRows",f),m+=ce(v,l,u[p]?.pagination),i.assertBudget(t,"maxCells",m)}})({...r,params:r.params??{},onWarning:p=>c.push({code:"layout",message:p,severity:"warning"}),onQueryResult:(p,l,v=0)=>{const b=d.reportOccurrenceScope(v,p);Object.defineProperty(w,p,{value:{revision:l.revision,sourceToken:l.sourceToken},enumerable:!0,writable:!0}),x.push({reportId:p,reportIndex:v,reportScope:b,...l.revision===void 0?{}:{revision:l.revision},...l.sourceToken===void 0?{}:{sourceToken:l.sourceToken}}),(l.diagnostics??[]).forEach(I=>c.push({...I,...I.target?{target:{...I.target,reportScope:b,...I.target.tableId?{tableId:JSON.stringify([v,p,I.target.tableId])}:{}}}:{}}))}}).catch(p=>{throw p instanceof d.ReportSourceError&&p.cause instanceof F.PaginatePageLimitError?new i.ReportRuntimeError("budget",p.cause.message,"$.budget.maxPages"):p instanceof d.ReportSourceError&&p.cause instanceof F.PaginateCellLimitError?new i.ReportRuntimeError("budget",p.cause.message,"$.budget.maxCells"):p instanceof d.ReportSourceError&&p.cause instanceof F.PaginateChartComponentLimitError?new i.ReportRuntimeError("budget",p.cause.message,"$.budget.maxChartComponents"):p});i.throwIfAborted(r.signal);const y=e.assets?await d.createReportTaskReporter(r).run("assets",()=>$.resolvePlanAssets(n,{...e.assets,diagnosticLimit:r.diagnosticLimit,signal:r.signal})):{plan:n,diagnostics:[]},S=y.plan;y.diagnosticSummary?c.merge({...y.diagnosticSummary,entries:E(y.diagnosticSummary.entries)}):E(y.diagnostics).forEach(p=>c.push(p));const O=S.pages.reduce((p,l)=>p+l.components.reduce((v,b)=>v+D(b),0),0);i.assertBudget(t,"maxPages",S.pages.length),i.assertBudget(t,"maxCells",O);const k=h.reportFontFingerprint(r.pdf),X=e.pagination?.measurer||Object.values(e.reports).some(p=>p.pagination?.measurer);return{plan:S,diagnostics:c.entries,...r.diagnosticLimit===void 0?{}:{diagnosticSummary:c.snapshot()},revisions:w,sources:x,layout:{textMetrics:k?"font-bytes":X?"provided":"heuristic",...k?{fontFingerprint:k}:{}},stats:{rows:f,pages:S.pages.length,cells:O,durationMs:Date.now()-g}}},o=async r=>{const a=Date.now();if(r.format!=="pdf"&&r.format!=="xlsx")throw new d.ReportSourceError("config","不支持的报表导出格式");const g=r.format==="pdf"?await import("@agile-team/mach-report/pdf"):void 0;i.throwIfAborted(r.signal);const f=r.pdf?.customFontFaces??(r.pdf?.customFontBytes?{regular:r.pdf.customFontBytes}:void 0),m=g&&f?g.createFontBytesMeasurer(f):void 0,c=await s(r,m);return i.throwIfAborted(r.signal),j({...r,prepared:c},t,a)};return{describe:r=>de(e.reports,r),validate:r=>W(e.reports,r),prepare:r=>i.controlled(r.signal,t.maxDurationMs,async a=>{const{signal:g,onEvent:f,...m}=N(r),c={...m,...m.pdf?{pdf:h.snapshotPdfFonts(m.pdf)}:{},taskId:m.taskId??d.reportTaskId()},w=f?y=>d.notifyReportTaskEvent(f,y,a):void 0,x={...c,signal:a,onEvent:w};d.createReportTaskReporter(x).runSync("validate",()=>U(e,c));let u;const R=c.pdf?.customFontFaces??(c.pdf?.customFontBytes?{regular:c.pdf.customFontBytes}:void 0);if(!e.executor&&R){const y=await import("@agile-team/mach-report/pdf");i.throwIfAborted(a),u=y.createFontBytesMeasurer(R)}const n=e.executor?await e.executor.prepare(c,a,w):await s(x,u);return M(n,t)}),exportPrepared:r=>i.controlled(r.signal,t.maxDurationMs,async a=>{const g=Date.now(),{signal:f,onEvent:m,...c}=r,w=M(h.snapshotPreparedReport(r.prepared,t.maxPreparedBytes??64e6,a),t),x={...c,xlsx:h.snapshotXlsxOptions(c.xlsx),prepared:w,...c.pdf?{pdf:h.snapshotPdfFonts(c.pdf)}:{},taskId:c.taskId??d.reportTaskId()};if(x.format!=="pdf"&&x.format!=="xlsx")throw new d.ReportSourceError("config","不支持的报表导出格式");const u=m?n=>d.notifyReportTaskEvent(m,n,a):void 0;if(e.executor){if(!e.executor.exportPrepared)throw new d.ReportSourceError("config","执行器未实现 exportPrepared;请升级执行器或显式使用本地运行时");const n=await e.executor.exportPrepared(x,a,u);return _(n,x.format),i.assertBudget(t,"maxRows",n.stats.rows),i.assertBudget(t,"maxPages",n.stats.pages),i.assertBudget(t,"maxCells",n.stats.cells),i.assertBudget(t,"maxOutputBytes",n.bytes.byteLength),{...n,stats:{...n.stats,outputBytes:n.bytes.byteLength}}}const R={...x,signal:a,onEvent:u};if(d.createReportTaskReporter(R).runSync("validate",()=>h.checkPreparedFont(R)),e.assets){const n=await d.createReportTaskReporter(R).run("assets",()=>$.resolvePlanAssets(w.plan,{...e.assets,diagnosticLimit:r.diagnosticLimit,signal:a}));w.plan=n.plan,h.appendPreparedDiagnostics(w,E(n.diagnostics),n.diagnosticSummary?{...n.diagnosticSummary,entries:E(n.diagnosticSummary.entries)}:void 0,r.diagnosticLimit)}return j(R,t,g)}),export:r=>i.controlled(r.signal,t.maxDurationMs,async a=>{const{signal:g,onEvent:f,...m}=N(r),c={...m,xlsx:h.snapshotXlsxOptions(m.xlsx),...m.pdf?{pdf:h.snapshotPdfFonts(m.pdf)}:{},taskId:m.taskId??d.reportTaskId()},w=f?R=>d.notifyReportTaskEvent(f,R,a):void 0,x={...c,signal:a,onEvent:w};if(d.createReportTaskReporter(x).runSync("validate",()=>U(e,c)),c.format!=="pdf"&&c.format!=="xlsx")throw new d.ReportSourceError("config","不支持的报表导出格式");const u=e.executor?await e.executor.export(c,a,w):await o(x);return e.executor&&_(u,c.format),i.assertBudget(t,"maxRows",u.stats.rows),i.assertBudget(t,"maxPages",u.stats.pages),i.assertBudget(t,"maxCells",u.stats.cells),i.assertBudget(t,"maxOutputBytes",u.bytes.byteLength),{...u,stats:{...u.stats,outputBytes:u.bytes.byteLength}}})}}exports.createReportRuntime=pe;exports.enforcePrepared=M;exports.validReportExecutionResult=J;
1
+ "use strict";var z=Object.create;var A=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var Z=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of H(t))!Y.call(e,r)&&r!==s&&A(e,r,{get:()=>t[r],enumerable:!(o=Q(t,r))||o.enumerable});return e};var T=(e,t,s)=>(s=e!=null?z(K(e)):{},Z(t||!e||!e.__esModule?A(s,"default",{value:e,enumerable:!0}):s,e));const B=require("./diagnostic-collector-wASg6Fzs.cjs"),h=require("./prepared-BlNeOjoO.cjs"),d=require("./json-snapshot-DCFEtfFw.cjs"),L=require("./report-params-VTg8MoCp.cjs"),C=require("./param-validation-C-8sRJLq.cjs"),i=require("./sha256-DgZAKXqI.cjs"),V=require("./template-registry-B-AK1oam.cjs"),ee=require("./template-serialization-CqQY4zDg.cjs"),$=require("./assets-BYdpkTIt.cjs"),F=require("./record-bindings-B7djSjNs.cjs");function te(e){let t=`$.pages.${e.pageIndex}`;if(e.componentIndex<0)return t;t+=`.components.${e.componentIndex}`;const s=e.componentPath??[];for(let o=0;o+1<s.length;o+=3)t+=`.grid.cells.${s[o]}.${s[o+1]}`,s[o+2]!==void 0&&(t+=`.children.${s[o+2]}`);return t}function E(e=[]){return e.map(t=>({...t,path:te(t)}))}function re(e,t){const s=B.createDiagnosticCollector(t??(e.diagnosticSummary?B.DEFAULT_DIAGNOSTIC_LIMIT:void 0));return e.diagnosticSummary?s.merge(e.diagnosticSummary):e.diagnostics.forEach(o=>s.push(o)),s}function q(e,t){t.diagnosticSummary?e.merge({...t.diagnosticSummary,entries:E(t.diagnosticSummary.entries)}):E(t.diagnostics).forEach(s=>e.push(s))}function se(e){const t=e.prepared.diagnosticSummary?.counts,s=t?!!(t["asset-render-failed"]||t["asset-budget-exceeded"]):e.prepared.diagnostics.some(o=>o.code==="asset-render-failed"||o.code==="asset-budget-exceeded");if(e.fidelity==="strict"&&s)throw new d.ReportSourceError("validate","严格输出拒绝已有资产渲染降级,请修复组件后重新准备报表。")}async function j(e,t,s=Date.now()){const o=e.prepared;h.assertPreparedOutputBudget(e,t),se(e);const r=re(o,e.diagnosticLimit),a=e.format==="pdf"?await import("@agile-team/mach-report/pdf"):void 0;i.throwIfAborted(e.signal);const g=e.pdf?.customFontFaces??(e.pdf?.customFontBytes?{regular:e.pdf.customFontBytes}:void 0),f=a&&g?a.createFontBytesMeasurer(g):void 0,m=d.createReportTaskReporter(e),c=await m.run("encode",async()=>{let u;const R={fidelity:e.fidelity,diagnosticLimit:e.diagnosticLimit??(o.diagnosticSummary?B.DEFAULT_DIAGNOSTIC_LIMIT:void 0),signal:e.signal,onProgress:(n,y)=>m.progress("encode",n,y)};if(e.format==="pdf"){i.throwIfAborted(e.signal);const n=await a.renderPlanToPdf(o.plan,{...e.pdf,...f?{measurer:f}:{},...R});u=n.bytes,q(r,n),h.mergeDiagnosticMessages(r,"pdf-fidelity",n.fidelityWarnings,"warning",n.fidelityWarningCount),h.mergeDiagnosticMessages(r,"pdf-page",n.pageErrors,"error",n.pageErrorCount),n.unsupportedTextCount&&r.push({code:"pdf-font",message:`${n.unsupportedTextCount} 段文本包含当前字体不支持的字符`,severity:"warning"})}else{const{renderPlanToXlsx:n}=await import("@agile-team/mach-report/xlsx");i.throwIfAborted(e.signal);const y=await n(o.plan,{...e.xlsx,...R});u=new Uint8Array(y.buffer),q(r,y),h.mergeDiagnosticMessages(r,"xlsx-fidelity",y.warnings,"warning",y.warningCount),y.notes?.forEach(S=>r.push({code:"xlsx-snapshot",message:S,severity:"info"}))}return i.throwIfAborted(e.signal),u});i.assertBudget(t,"maxOutputBytes",c.byteLength);const{plan:w,...x}=o;return{...x,diagnostics:r.entries,...e.diagnosticLimit===void 0&&!o.diagnosticSummary?{}:{diagnosticSummary:r.snapshot()},bytes:c,format:e.format,contentType:e.format==="pdf"?"application/pdf":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",stats:{...x.stats,durationMs:Date.now()-s,outputBytes:c.byteLength}}}function P(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ae(e){return P(e)?["rows","pages","cells"].every(t=>typeof e[t]=="number"&&Number.isSafeInteger(e[t])&&e[t]>=0)&&typeof e.durationMs=="number"&&Number.isFinite(e.durationMs)&&e.durationMs>=0:!1}function oe(e){return Array.isArray(e)&&e.every(t=>P(t)&&typeof t.code=="string"&&typeof t.message=="string"&&["info","warning","error"].includes(t.severity)&&d.hasValidDataExplanation(t)&&h.validReportDiagnosticLocation(t))}function ne(e){return P(e)&&Object.values(e).every(t=>P(t)&&(t.revision===void 0||typeof t.revision=="string")&&(t.sourceToken===void 0||typeof t.sourceToken=="string"))}function ie(e){return e===void 0?!0:P(e)&&["heuristic","provided","font-bytes"].includes(e.textMetrics)&&(e.fontFingerprint===void 0||typeof e.fontFingerprint=="string"&&/^[a-f0-9]{64}$/.test(e.fontFingerprint))}function J(e,t){if(!P(e)||!ae(e.stats)||!oe(e.diagnostics)||!ne(e.revisions)||!ie(e.layout)||!h.validPreparedSources(e.sources)||e.diagnosticSummary!==void 0&&!h.matchingDiagnosticSummary(e.diagnosticSummary,e.diagnostics))return!1;if(t==="prepare")return V.validateRenderPlan(e.plan).ok;const s=e.format==="pdf"?"application/pdf":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";return e.bytes instanceof Uint8Array&&(e.format==="pdf"||e.format==="xlsx")&&e.contentType===s}function _(e,t){if(!J(e,"export")||!("format"in e)||e.format!==t)throw new d.ReportSourceError("validate","报表执行器返回的导出结果与请求格式不一致或元数据无效")}function N(e){return{...e,reportIds:[...e.reportIds],...e.params?{params:{...e.params}}:{}}}function G(e,t){if(t.length===0)throw new d.ReportSourceError("config","缺少报表 ID");return t.map(s=>{if(!Object.prototype.hasOwnProperty.call(e,s))throw new d.ReportSourceError("config",`未注册报表 ${s}`);return e[s]})}function D(e){return e.grid?.cells.reduce((t,s)=>t+s.reduce((o,r)=>o+(r?1+(r.children?.reduce((a,g)=>a+D(g),0)??0):0),0),0)??0}function ce(e,t,s){return e.pages.reduce((o,r)=>o+r.components.reduce((a,g)=>g.kind!=="list"?a+D(g):a+d.estimateListLayoutCells(g,t,s),0),0)}function de(e,t=Object.keys(e)){return G(e,t).map((s,o)=>{const r=t[o],a=L.getReportParamDefs(e,[r]);return{id:r,params:JSON.parse(JSON.stringify(a)),paramsSchema:C.reportParamsJsonSchema(a),datasetsSchema:Object.fromEntries(Object.entries(s.dataSchema??{}).map(([g,f])=>[g,d.templateDatasetJsonSchema(typeof s.template=="function"?void 0:s.template,g,f)])),capabilities:{save:!!s.provider?.save,export:!!s.provider?.export,templates:!!s.provider?.templates}}})}function W(e,t){G(e,t.reportIds);const s=C.validateReportParams(L.getReportParamDefs(e,t.reportIds),t.params),o=t.reportIds.flatMap(a=>C.validateReportParams(L.getReportParamDefs(e,[a]),t.params).issues),r=new Map(o.map(a=>[JSON.stringify(a),a]));return{...s,ok:r.size===0,issues:[...r.values()]}}function M(e,t){const s=V.validateRenderPlan(e.plan);if(!s.ok)throw new d.ReportSourceError("validate",`执行器返回无效计划:${s.errors[0]?.path}`);const o=e.plan.pages.length,r=e.plan.pages.reduce((a,g)=>a+g.components.reduce((f,m)=>f+D(m),0),0);return i.assertBudget(t,"maxRows",e.stats.rows),i.assertBudget(t,"maxPages",o),i.assertBudget(t,"maxCells",r),{...e,stats:{...e.stats,pages:o,cells:r}}}function U(e,t){const s=W(e.reports,t);if(!s.ok)throw new C.ReportParamValidationError(s.issues)}function pe(e){const t={...i.DEFAULT_REPORT_RUNTIME_BUDGET,...e.budget};i.validateBudget(t);const s=async(r,a)=>{const g=Date.now();let f=0,m=0;const c=B.createDiagnosticCollector(r.diagnosticLimit),w={},x=[],u=Object.fromEntries(Object.entries(e.reports).map(([p,l])=>[p,{...l,pagination:{...e.pagination,...l.pagination,...a?{measurer:a}:{}},dataValidation:{...l.dataValidation,maxRows:Math.min(t.maxRows??1e5,l.dataValidation?.maxRows??1/0),maxCells:Math.min(t.maxCells??2e6,l.dataValidation?.maxCells??1/0)}}])),n=await d.createReportSource(u,{maxPages:t.maxPages,maxCells:t.maxCells,maxChartComponents:t.maxChartComponents,onDatasets:(p,l,v)=>{try{f+=d.templateDatasetRowCount(v,l,{maxRows:t.maxRows,signal:r.signal})}catch(b){throw b instanceof ee.TreeRowLimitError?new i.ReportRuntimeError("budget",b.message,"$.budget.maxRows"):b}i.assertBudget(t,"maxRows",f),m+=ce(v,l,u[p]?.pagination),i.assertBudget(t,"maxCells",m)}})({...r,params:r.params??{},onWarning:p=>c.push({code:"layout",message:p,severity:"warning"}),onQueryResult:(p,l,v=0)=>{const b=d.reportOccurrenceScope(v,p);Object.defineProperty(w,p,{value:{revision:l.revision,sourceToken:l.sourceToken},enumerable:!0,writable:!0}),x.push({reportId:p,reportIndex:v,reportScope:b,...l.revision===void 0?{}:{revision:l.revision},...l.sourceToken===void 0?{}:{sourceToken:l.sourceToken}}),(l.diagnostics??[]).forEach(I=>c.push({...I,...I.target?{target:{...I.target,reportScope:b,...I.target.tableId?{tableId:JSON.stringify([v,p,I.target.tableId])}:{}}}:{}}))}}).catch(p=>{throw p instanceof d.ReportSourceError&&p.cause instanceof F.PaginatePageLimitError?new i.ReportRuntimeError("budget",p.cause.message,"$.budget.maxPages"):p instanceof d.ReportSourceError&&p.cause instanceof F.PaginateCellLimitError?new i.ReportRuntimeError("budget",p.cause.message,"$.budget.maxCells"):p instanceof d.ReportSourceError&&p.cause instanceof F.PaginateChartComponentLimitError?new i.ReportRuntimeError("budget",p.cause.message,"$.budget.maxChartComponents"):p});i.throwIfAborted(r.signal);const y=e.assets?await d.createReportTaskReporter(r).run("assets",()=>$.resolvePlanAssets(n,{...e.assets,diagnosticLimit:r.diagnosticLimit,signal:r.signal})):{plan:n,diagnostics:[]},S=y.plan;y.diagnosticSummary?c.merge({...y.diagnosticSummary,entries:E(y.diagnosticSummary.entries)}):E(y.diagnostics).forEach(p=>c.push(p));const O=S.pages.reduce((p,l)=>p+l.components.reduce((v,b)=>v+D(b),0),0);i.assertBudget(t,"maxPages",S.pages.length),i.assertBudget(t,"maxCells",O);const k=h.reportFontFingerprint(r.pdf),X=e.pagination?.measurer||Object.values(e.reports).some(p=>p.pagination?.measurer);return{plan:S,diagnostics:c.entries,...r.diagnosticLimit===void 0?{}:{diagnosticSummary:c.snapshot()},revisions:w,sources:x,layout:{textMetrics:k?"font-bytes":X?"provided":"heuristic",...k?{fontFingerprint:k}:{}},stats:{rows:f,pages:S.pages.length,cells:O,durationMs:Date.now()-g}}},o=async r=>{const a=Date.now();if(r.format!=="pdf"&&r.format!=="xlsx")throw new d.ReportSourceError("config","不支持的报表导出格式");const g=r.format==="pdf"?await import("@agile-team/mach-report/pdf"):void 0;i.throwIfAborted(r.signal);const f=r.pdf?.customFontFaces??(r.pdf?.customFontBytes?{regular:r.pdf.customFontBytes}:void 0),m=g&&f?g.createFontBytesMeasurer(f):void 0,c=await s(r,m);return i.throwIfAborted(r.signal),j({...r,prepared:c},t,a)};return{describe:r=>de(e.reports,r),validate:r=>W(e.reports,r),prepare:r=>i.controlled(r.signal,t.maxDurationMs,async a=>{const{signal:g,onEvent:f,...m}=N(r),c={...m,...m.pdf?{pdf:h.snapshotPdfFonts(m.pdf)}:{},taskId:m.taskId??d.reportTaskId()},w=f?y=>d.notifyReportTaskEvent(f,y,a):void 0,x={...c,signal:a,onEvent:w};d.createReportTaskReporter(x).runSync("validate",()=>U(e,c));let u;const R=c.pdf?.customFontFaces??(c.pdf?.customFontBytes?{regular:c.pdf.customFontBytes}:void 0);if(!e.executor&&R){const y=await import("@agile-team/mach-report/pdf");i.throwIfAborted(a),u=y.createFontBytesMeasurer(R)}const n=e.executor?await e.executor.prepare(c,a,w):await s(x,u);return M(n,t)}),exportPrepared:r=>i.controlled(r.signal,t.maxDurationMs,async a=>{const g=Date.now(),{signal:f,onEvent:m,...c}=r,w=M(h.snapshotPreparedReport(r.prepared,t.maxPreparedBytes??64e6,a),t),x={...c,xlsx:h.snapshotXlsxOptions(c.xlsx),prepared:w,...c.pdf?{pdf:h.snapshotPdfFonts(c.pdf)}:{},taskId:c.taskId??d.reportTaskId()};if(x.format!=="pdf"&&x.format!=="xlsx")throw new d.ReportSourceError("config","不支持的报表导出格式");const u=m?n=>d.notifyReportTaskEvent(m,n,a):void 0;if(e.executor){if(!e.executor.exportPrepared)throw new d.ReportSourceError("config","执行器未实现 exportPrepared;请升级执行器或显式使用本地运行时");const n=await e.executor.exportPrepared(x,a,u);return _(n,x.format),i.assertBudget(t,"maxRows",n.stats.rows),i.assertBudget(t,"maxPages",n.stats.pages),i.assertBudget(t,"maxCells",n.stats.cells),i.assertBudget(t,"maxOutputBytes",n.bytes.byteLength),{...n,stats:{...n.stats,outputBytes:n.bytes.byteLength}}}const R={...x,signal:a,onEvent:u};if(d.createReportTaskReporter(R).runSync("validate",()=>h.checkPreparedFont(R)),e.assets){const n=await d.createReportTaskReporter(R).run("assets",()=>$.resolvePlanAssets(w.plan,{...e.assets,diagnosticLimit:r.diagnosticLimit,signal:a}));w.plan=n.plan,h.appendPreparedDiagnostics(w,E(n.diagnostics),n.diagnosticSummary?{...n.diagnosticSummary,entries:E(n.diagnosticSummary.entries)}:void 0,r.diagnosticLimit)}return j(R,t,g)}),export:r=>i.controlled(r.signal,t.maxDurationMs,async a=>{const{signal:g,onEvent:f,...m}=N(r),c={...m,xlsx:h.snapshotXlsxOptions(m.xlsx),...m.pdf?{pdf:h.snapshotPdfFonts(m.pdf)}:{},taskId:m.taskId??d.reportTaskId()},w=f?R=>d.notifyReportTaskEvent(f,R,a):void 0,x={...c,signal:a,onEvent:w};if(d.createReportTaskReporter(x).runSync("validate",()=>U(e,c)),c.format!=="pdf"&&c.format!=="xlsx")throw new d.ReportSourceError("config","不支持的报表导出格式");const u=e.executor?await e.executor.export(c,a,w):await o(x);return e.executor&&_(u,c.format),i.assertBudget(t,"maxRows",u.stats.rows),i.assertBudget(t,"maxPages",u.stats.pages),i.assertBudget(t,"maxCells",u.stats.cells),i.assertBudget(t,"maxOutputBytes",u.bytes.byteLength),{...u,stats:{...u.stats,outputBytes:u.bytes.byteLength}}})}}exports.createReportRuntime=pe;exports.enforcePrepared=M;exports.validReportExecutionResult=J;
@@ -6,7 +6,7 @@
6
6
  "component": {
7
7
  "type": "library",
8
8
  "name": "@agile-team/mach-report",
9
- "version": "2.25.0"
9
+ "version": "2.25.1"
10
10
  },
11
11
  "properties": [
12
12
  {