@agile-team/mach-report 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -16
- package/dist/ReportPreview-BdvoqdOd.cjs +6 -0
- package/dist/ReportPreview-COFkbeEM.js +3719 -0
- package/dist/_plugin-vue_export-helper-BHFhmbuH.cjs +1 -0
- package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
- package/dist/analytics.cjs +1 -0
- package/dist/analytics.d.cts +276 -0
- package/dist/analytics.d.ts +276 -0
- package/dist/analytics.js +223 -0
- package/dist/assets-B9qJku3V.js +160 -0
- package/dist/assets-RZan7EyL.cjs +1 -0
- package/dist/capabilities-joSutDF8.js +63 -0
- package/dist/capabilities-xGTpnPjJ.cjs +1 -0
- package/dist/designer.cjs +1 -0
- package/dist/designer.d.cts +869 -0
- package/dist/designer.d.ts +869 -0
- package/dist/designer.js +628 -0
- package/dist/index.cjs +8 -5
- package/dist/index.d.cts +497 -9
- package/dist/index.d.ts +497 -9
- package/dist/index.js +1088 -1499
- package/dist/param-validation-BWNjLcN0.js +116 -0
- package/dist/param-validation-CiTxFeZ8.cjs +1 -0
- package/dist/pdf.cjs +48 -48
- package/dist/pdf.d.cts +119 -1
- package/dist/pdf.d.ts +119 -1
- package/dist/pdf.js +3932 -3868
- package/dist/{plugin-DMPLDpBY.cjs → plugin-9t_ZFwhz.cjs} +1 -1
- package/dist/{plugin-DDLcFWlk.js → plugin-s8Ay8kKk.js} +2 -2
- package/dist/progress-DD964VAB.js +102 -0
- package/dist/progress-KvhwXZ1Q.cjs +1 -0
- package/dist/render-plan-CckPEQyf.cjs +1 -0
- package/dist/{render-plan-CXBWRog4.js → render-plan-uzZYYSy1.js} +11 -10
- package/dist/report-params-B_VCihAh.js +12 -0
- package/dist/report-params-CjWrjPl6.cjs +1 -0
- package/dist/report-source-BXHNy_AD.js +755 -0
- package/dist/report-source-CCAvFE3t.cjs +1 -0
- package/dist/server/node.d.cts +320 -0
- package/dist/server/node.d.ts +320 -0
- package/dist/server-node.cjs +1 -0
- package/dist/server-node.js +303 -0
- package/dist/server.cjs +1 -0
- package/dist/server.d.cts +668 -0
- package/dist/server.d.ts +668 -0
- package/dist/server.js +245 -0
- package/dist/style-CpwiOPyB.cjs +1 -0
- package/dist/style-Dv5o_x6b.js +67 -0
- package/dist/style.css +1 -1
- package/dist/task-events-DQ276fn2.cjs +1 -0
- package/dist/task-events-Dpsvf_t2.js +47 -0
- package/dist/template-registry-DWExx0gU.cjs +1 -0
- package/dist/template-registry-NpOakidD.js +354 -0
- package/dist/textwrap-CnGsEum6.cjs +4 -0
- package/dist/textwrap-DOl04hCQ.js +110 -0
- package/dist/validate-DfHPD8wX.cjs +1 -0
- package/dist/validate-S6CgIm5d.js +148 -0
- package/dist/vue/async.d.cts +1507 -1538
- package/dist/vue/async.d.ts +1507 -1538
- package/dist/vue/index.d.cts +2376 -2347
- package/dist/vue/index.d.ts +2376 -2347
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +184 -75
- package/dist/worker.cjs +1 -0
- package/dist/worker.d.cts +325 -0
- package/dist/worker.d.ts +325 -0
- package/dist/worker.js +158 -0
- package/dist/xlsx/node.d.cts +47 -0
- package/dist/xlsx/node.d.ts +47 -0
- package/dist/xlsx-node.cjs +221 -0
- package/dist/xlsx-node.js +36409 -0
- package/dist/xlsx.cjs +20 -20
- package/dist/xlsx.d.cts +87 -2
- package/dist/xlsx.d.ts +87 -2
- package/dist/xlsx.js +5987 -5840
- package/package.json +63 -3
- package/dist/ReportPreview-CBKLI--k.js +0 -2188
- package/dist/ReportPreview-ClM8h0pM.cjs +0 -6
- package/dist/grid-geometry-BNIvw52m.cjs +0 -1
- package/dist/grid-geometry-C8hGoe9o.js +0 -130
- package/dist/render-plan-CCTL4F9v.cjs +0 -1
- package/dist/report-params-B3Fia6JO.js +0 -10
- package/dist/report-params-D1gZ1DME.cjs +0 -1
- package/dist/textwrap-nH0UYU6D.js +0 -108
- package/dist/textwrap-oD-t4b4B.cjs +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const T=require("./render-plan-CckPEQyf.cjs"),A=require("./textwrap-CnGsEum6.cjs"),x=require("./style-CpwiOPyB.cjs"),ae=require("./validate-DfHPD8wX.cjs"),ie=require("./report-params-CjWrjPl6.cjs"),B=require("./template-registry-DWExx0gU.cjs"),j=require("./param-validation-CiTxFeZ8.cjs"),se=require("./task-events-DQ276fn2.cjs");function K(e){if(!e||e.kind==="date")return;const t=e.digits;if(!(t!==void 0&&(!Number.isInteger(t)||t<0||t>100))){if(e.kind==="percent"){const r=t??2;return`0${r?`.${"0".repeat(r)}`:""}%`}return t===void 0?e.thousands?"#,##0.###############":void 0:`${e.thousands?"#,##0":"0"}${t?`.${"0".repeat(t)}`:""}`}}function Y(e){const t=/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(e.trim());if(t){const n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return Number.isNaN(n.getTime())?null:n}const r=new Date(e);return Number.isNaN(r.getTime())?null:r}function I(e,t){return e.toLocaleString("en-US",{minimumFractionDigits:t,maximumFractionDigits:t})}function me(e,t){const r=n=>String(n).padStart(2,"0");return t.replace(/YYYY/g,String(e.getFullYear())).replace(/MM/g,r(e.getMonth()+1)).replace(/DD/g,r(e.getDate())).replace(/hh/g,r(e.getHours())).replace(/mm/g,r(e.getMinutes())).replace(/ss/g,r(e.getSeconds()))}function ce(e,t,r){return r!=null?t?I(e,r):e.toFixed(r):t?I(e):String(e)}function F(e){const t=typeof e=="number"?e:Number(String(e).replace(/,/g,""));return Number.isFinite(t)?t:null}function q(e,t){if(e==null||e===""||!t)return String(e??"");switch(t.kind){case"number":{const r=F(e);return r==null?String(e):ce(r,t.thousands===!0,t.digits)}case"percent":{const r=F(e);return r==null?String(e):`${I(r*100,t.digits??2)}%`}case"date":{const r=t.pattern??"YYYY-MM-DD",n=e instanceof Date?e:Y(String(e));return n?me(n,r):String(e)}default:return String(e)}}function V(e,t){const r=e[t.field];if(r==null||r==="")return!1;if(typeof t.value=="number"){const i=F(r);if(i==null)return!1;switch(t.op){case">":return i>t.value;case">=":return i>=t.value;case"<":return i<t.value;case"<=":return i<=t.value;case"==":return i===t.value;case"!=":return i!==t.value}}const n=String(r),o=String(t.value);switch(t.op){case"==":return n===o;case"!=":return n!==o;case">":return n>o;case">=":return n>=o;case"<":return n<o;case"<=":return n<=o}return!1}const ue=["text","number","boolean","date","decimal"],le=new Set(["__proto__","prototype","constructor"]);function v(e){throw new Error(`数据契约无效:${e}`)}function J(e){(!e||!Array.isArray(e.fields)||!e.fields.length||e.fields.length>2048)&&v("fields 应包含 1–2048 个字段");const t=new Set;for(const r of e.fields)(!r||typeof r.field!="string"||!r.field.trim()||le.has(r.field)||t.has(r.field))&&v("字段名应安全、非空且唯一"),t.add(r.field),ue.includes(r.type)||v(`未知字段类型 ${r.type}`),he(r),fe(r),de(r);ge(e,t)}function de(e){e.enum!==void 0&&(!Array.isArray(e.enum)||!e.enum.length||e.enum.some(t=>!U(t,e.type)))&&v("enum 应为匹配字段类型的非空标量数组")}function ge(e,t){e.rowKey!==void 0&&((typeof e.rowKey!="string"||!e.rowKey.trim()||!t.has(e.rowKey))&&v("rowKey 应为引用已声明字段的非空字符串"),e.fields.find(r=>r.field===e.rowKey)?.type==="boolean"&&v("布尔字段不能作为业务主键"))}function fe(e){for(const t of["label","unit"])e[t]!==void 0&&typeof e[t]!="string"&&v(`${t} 应为字符串`);for(const t of["required","nullable"])e[t]!==void 0&&typeof e[t]!="boolean"&&v(`${t} 应为布尔值`);e.semanticRole!==void 0&&!["identifier","dimension","measure","date","text"].includes(e.semanticRole)&&v("未知字段语义")}function he(e){for(const t of["min","max","minLength","maxLength"]){const r=e[t];r!==void 0&&(!Number.isFinite(r)||t.includes("Length")&&(!Number.isInteger(r)||r<0))&&v(`${t} 无效`)}e.min!==void 0&&e.max!==void 0&&e.min>e.max&&v("min 不能超过 max"),e.minLength!==void 0&&e.maxLength!==void 0&&e.minLength>e.maxLength&&v("minLength 不能超过 maxLength"),e.type!=="number"&&(e.min!==void 0||e.max!==void 0)&&v("min/max 仅适用于 number,精确小数文本需业务校验"),["number","boolean"].includes(e.type)&&(e.minLength!==void 0||e.maxLength!==void 0)&&v("长度约束仅适用于文本类型")}function pe(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;const r=Number(t[1]),n=Number(t[2]),o=Number(t[3]),i=r%4===0&&(r%100!==0||r%400===0);return r>0&&n>=1&&n<=12&&o>=1&&o<=[31,i?29:28,31,30,31,30,31,31,30,31,30,31][n-1]}function U(e,t){return t==="number"?typeof e=="number"&&Number.isFinite(e):t==="boolean"?typeof e=="boolean":typeof e!="string"?!1:t==="date"?pe(e):t==="decimal"?e.length<=1e4&&/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(e):!0}function ye(e,t){if(e==null)return t.required||e===null&&t.nullable===!1?{code:"required",message:"缺少必需字段值"}:void 0;if(!U(e,t.type))return{code:"type",message:`值应为 ${t.type},不会自动转换原始值`};if(t.enum&&!t.enum.includes(e))return{code:"enum",message:"值不在允许的枚举中"};if(typeof e=="number"&&(t.min!==void 0&&e<t.min||t.max!==void 0&&e>t.max))return{code:"range",message:"数值超出范围"};if(typeof e=="string"&&!we(e,t))return{code:"range",message:"文本长度超出范围"}}function we(e,t){if(t.minLength===void 0&&t.maxLength===void 0)return!0;let r=0;for(const n of e)r++;return(t.minLength===void 0||r>=t.minLength)&&(t.maxLength===void 0||r<=t.maxLength)}function D(e,t){const r=e??t;if(!Number.isInteger(r)||r<1)throw new Error("数据校验预算应为正整数");return r}function be(e,t,r){const n=Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if((typeof n!="string"||!n.trim())&&!(typeof n=="number"&&Number.isFinite(n)))return"业务主键应为非空字符串或有限数字";const o=JSON.stringify([typeof n,n]);if(r.has(o))return"业务主键重复";r.add(o)}function Q(e,t,r={}){J(t);const n=r.path??"$.rows",o=[],i=D(r.maxIssues,100);if(!Array.isArray(e))return{ok:!1,issues:[{code:"row",path:n,message:"数据集应为对象数组"}]};if(e.length>D(r.maxRows,1e5)||e.length*t.fields.length>D(r.maxCells,2e6))return{ok:!1,issues:[{code:"budget",path:n,message:"数据校验超出行数或单元格预算"}]};const a=new Set;for(let s=0;s<e.length&&o.length<i;s++){const d=e[s];if(!d||typeof d!="object"||Array.isArray(d)){o.push({code:"row",path:`${n}[${s}]`,rowIndex:s,message:"行应为对象"});continue}Me(d,t,s,n,a,o,i)}return{ok:o.length===0,issues:o}}function Me(e,t,r,n,o,i,a){for(const s of t.fields){if(i.length>=a)return;const d=ye(Object.prototype.hasOwnProperty.call(e,s.field)?e[s.field]:void 0,s);d&&i.push({...d,rowIndex:r,field:s.field,path:`${n}[${r}].${s.field}`})}if(t.rowKey&&i.length<a){const s=be(e,t.rowKey,o);s&&i.push({code:"row-key",path:`${n}[${r}].${t.rowKey}`,message:s,rowIndex:r,field:t.rowKey})}}function Se(e){return J(e),{$schema:"https://json-schema.org/draft/2020-12/schema",type:"array",items:{type:"object",properties:Object.fromEntries(e.fields.map(r=>[r.field,ve(r,r.field===e.rowKey)])),required:e.fields.filter(r=>r.required||r.field===e.rowKey).map(r=>r.field),additionalProperties:!0},...e.rowKey?{"x-report-rowKey":e.rowKey}:{}}}function ve(e,t){const r=!t&&e.nullable!==!1&&!e.required;return{type:r?[W(e.type),"null"]:W(e.type),...e.label?{title:e.label}:{},...e.type==="date"?{format:"date"}:{},...e.type==="decimal"?{pattern:"^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$"}:{},...e.enum?{enum:r?[...e.enum,null]:[...e.enum]}:{},...e.min===void 0?{}:{minimum:e.min},...e.max===void 0?{}:{maximum:e.max},...xe(e,t),...t&&e.type==="text"?{pattern:"\\S"}:{},...e.unit?{"x-report-unit":e.unit}:{},...e.semanticRole?{"x-report-semanticRole":e.semanticRole}:{}}}function xe(e,t){const r={};return(e.minLength!==void 0||t&&e.type!=="number")&&(r.minLength=Math.max(e.minLength??0,t?1:0)),e.type==="decimal"?r.maxLength=Math.min(e.maxLength??1e4,1e4):e.maxLength!==void 0&&(r.maxLength=e.maxLength),r}function W(e){return e==="text"||e==="date"||e==="decimal"?"string":e}class E extends Error{constructor(t,r){super(`报表页数超出上限 ${t}(至少 ${r} 页)`),this.limit=t,this.actual=r,this.code="page-limit",this.name="PaginatePageLimitError"}}function Pe(e){return{widthMm:e.widthMm,heightMm:e.heightMm,marginTopMm:e.marginTopMm??0,marginBottomMm:e.marginBottomMm??0,marginLeftMm:e.marginLeftMm??0,marginRightMm:e.marginRightMm??0,components:[]}}function $e(e,t){return t.heightMm-(e.layout==="wide"?t.marginBottomMm:e.marginBottomMm??t.marginBottomMm)}function X(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(typeof e=="boolean")return e?"是":"否";if(e instanceof Date)return e.toISOString().slice(0,10);try{return JSON.stringify(e)}catch{return String(e)}}function Z(e,t){let r=e.textMetrics.get(t);if(!r){const n=x.resolveFontSize(t).fontSizePt;r={measureOptions:{fontSizePt:n,fontFamily:t.fontFamily??T.DEFAULT_FONT_FAMILY,italic:t.italic,bold:t.bold,letterSpacingPt:t.letterSpacing},lineMm:n*(t.lineHeight??T.LINE_HEIGHT)*25.4/72},e.textMetrics.set(t,r)}return r}function ee(e,t,r){return r==="identifier"||r==="dimension"||r==="date"?"center":r==="measure"?"right":r==="text"?"left":t?.kind==="number"||t?.kind==="percent"?"right":t?.kind==="date"||e instanceof Date||typeof e=="boolean"?"center":typeof e=="number"&&Number.isFinite(e)?"right":"left"}function ke(e){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e}function Re(e,t){const r=e.fontSizePt??T.DEFAULT_FONT_PT,n=e.paddingMm??1,o=e.columns.map(m=>m.align??m.style?.align??e.align??"left"),i=e.columns.map((m,u)=>({...x.mergeComponentStyles({fontSize:r,verticalAlign:"middle"},m.style),align:o[u]==="auto"?"left":o[u]})),a=i.map((m,u)=>o[u]==="auto"?{left:m,center:{...m,align:"center"},right:{...m,align:"right"}}:void 0),s=e.columns.map((m,u)=>m.rules?.map(b=>{const P=a[u];if(P)return{left:x.mergeComponentStyles(P.left,b.style),center:x.mergeComponentStyles(P.center,b.style),right:x.mergeComponentStyles(P.right,b.style)};const k=x.mergeComponentStyles(i[u],b.style);return{left:k,center:k,right:k}})),d=e.columns.map(m=>{let u=x.mergeComponentStyles({fontSize:r,bold:e.headerBold??!0,align:"center",verticalAlign:"middle",backgroundColor:e.headerBackgroundColor},m.style);return e.headerAlign!==void 0&&(u.align=e.headerAlign),u=x.mergeComponentStyles(u,e.headerStyle),m.headerAlign!==void 0&&(u.align=m.headerAlign),x.mergeComponentStyles(u,m.headerStyle)}),f=e.columns.map(m=>m.header);let c=e.rowHeightMm??0;for(let m=0;m<f.length;m++){const u=d[m],b=x.resolveFontSize(u).fontSizePt,P=A.wrapText(f[m],e.columns[m].widthMm-n*2,{fontSizePt:b,fontFamily:u.fontFamily??T.DEFAULT_FONT_FAMILY,italic:u.italic,bold:u.bold,letterSpacingPt:u.letterSpacing},t),k=b*(u.lineHeight??T.LINE_HEIGHT)*25.4/72;c=Math.max(c,Math.max(P.length,1)*k+n*2)}const g=f.map((m,u)=>({text:m,style:d[u]})),w=e.border===!1?{borderTop:!1,borderRight:!1,borderBottom:!1,borderLeft:!1}:{borderBottom:!0,borderLeft:!0,borderRight:!0,borderTop:!0},p=e.columns.map(m=>m.widthMm),h=Te(e.headerGrid,p,{cells:[g],colWidthsMm:p,rowHeightsMm:[c],paddingMm:n});return{fontSizePt:r,paddingMm:n,cellStyles:i,autoStyles:a,ruleStyles:s,textMetrics:new WeakMap,numberFormats:e.columns.map(m=>K(m.format)),borderStyle:w,headerHeightMm:h.rowHeightsMm.reduce((m,u)=>m+u,0),headerGrid:h,colWidthsMm:p,columns:e.columns}}function Te(e,t,r){if(!e)return r;if(!e.cells.length)throw new Error("自定义列表表头至少需要一行");const n=e.rowHeightsMm??e.cells.map(()=>r.rowHeightsMm[0]);if(n.length!==e.cells.length||n.some(o=>!Number.isFinite(o)||o<=0))throw new Error("自定义列表表头行高无效");return{...e,colWidthsMm:t,rowHeightsMm:n}}function Le(e,t,r){const n=t.format?.kind==="number"||t.format?.kind==="percent";t.valueType!==void 0?e.valueType=t.valueType:n&&(e.valueType="number"),t.editable!==void 0&&(e.editable=t.editable),(typeof e.value=="number"||e.value==null)&&r!==void 0&&(e.numberFormat=r)}function z(e,t,r){const n=e.columns;let o=e.rowHeightFloorMm;const i=new Array(n.length);for(let a=0;a<n.length;a++){const s=n[a],d=t[s.field],f=e.autoStyles[a]?ee(d,s.format,s.semanticRole):"left";let c=e.autoStyles[a]?.[f]??e.cellStyles[a];if(s.rules)for(let u=0;u<s.rules.length;u++){const b=s.rules[u];if(V(t,b.when)){c=e.ruleStyles[a][u][f];break}}const g=s.format?q(d,s.format):X(d),w=Z(e,c),p=A.wrapText(g,s.widthMm-e.paddingMm*2,w.measureOptions,r);o=Math.max(o,p.length*w.lineMm+e.paddingMm*2);const h=ke(d),m={text:g,style:c};h!==void 0&&(m.value=h),Le(m,s,e.numberFormats[a]),i[a]=m}return{grid:{cells:[i],colWidthsMm:e.colWidthsMm,rowHeightsMm:[o],paddingMm:e.paddingMm},heightMm:o}}function*Ee(e,t){if(!t){for(const n of e)yield{kind:"row",row:n};return}const r=new Map;for(const n of e){const o=X(n[t.field]),i=r.get(o);i?i.push(n):r.set(o,[n])}for(const[n,o]of r){yield{kind:"groupHeader",label:(t.headerTemplate??"{value}").replace(/\{value\}/g,n),firstRow:o[0]};for(const i of o)yield{kind:"row",row:i};t.subtotal?.length&&(yield{kind:"subtotal",label:t.subtotalLabel??"小计",rows:o})}}function Ne(e,t){let r=0;for(const n of e){const o=typeof n[t]=="number"?n[t]:Number(n[t]);Number.isFinite(o)&&(r+=o)}return r}function te(e,t,r){return new Map(r.map(n=>{const o=e.find(a=>a.field===n)?.format??{kind:"number",thousands:!0},i=Ne(t,n);return[n,{text:q(i,o),value:i,numberFormat:K(o)}]}))}function re(e,t){const r=e.findIndex(n=>t.includes(n.field));return r>0?r:1}function C(e,t,r,n,o,i){const a=[],s=Math.max(1,Math.min(i,e.columns.length)),d=x.mergeComponentStyles({fontSize:e.fontSizePt},o);a.push({text:r,colSpan:s,style:{bold:!0,...d}});for(let g=s;g<e.columns.length;g++){const w=e.columns[g],p=n.get(w.field),h=e.autoStyles[g]?.[ee(p?.value,w.format)]??e.cellStyles[g];a.push({...p,text:p?.text??"",style:x.mergeComponentStyles(h,o)})}let f=e.rowHeightFloorMm,c=0;for(const g of a){let w=0;const p=c+(g.colSpan??1);for(;c<p;c++)w+=e.colWidthsMm[c]??0;const h=Z(e,g.style),m=A.wrapText(g.text??"",w-e.paddingMm*2,h.measureOptions,t);f=Math.max(f,m.length*h.lineMm+e.paddingMm*2)}return{grid:{cells:[a],colWidthsMm:e.colWidthsMm,rowHeightsMm:[f],paddingMm:e.paddingMm},heightMm:f}}function Fe(e,t,r){const{templatePage:n,current:o,warnings:i,nextId:a,pushCurrent:s}=r,d=()=>$e(n,o),f=o.marginTopMm,c={id:r.tableId,columnKeys:e.columns.map(l=>l.field),...e.layout===void 0?{}:{layout:e.layout},...e.title===void 0?{}:{title:e.title}};let g=0;const w={kind:"rect",leftMm:e.leftMm,topMm:0,widthMm:e.widthMm,heightMm:t.headerHeightMm,grid:t.headerGrid,nid:a("listh"),table:{...c,role:"header",rowIndex:-1},style:t.borderStyle},p=l=>o.components.push({...w,topMm:l});let h=e.topMm;p(h),h+=t.headerHeightMm+r.mmPerRow;function m(){const l=n.layout==="wide"?0:e.topMm;return e.headerEveryPage!==!1?l+t.headerHeightMm:n.layout==="wide"?0:f}function u(){const l=n.layout==="wide"?0:o.marginBottomMm;return n.heightMm-l-m()}function b(l){if(h+l<=d())return;s(),o.components=[],o.heightMm=n.heightMm,n.layout==="wide"&&(o.marginTopMm=0,o.marginBottomMm=0);const M=n.layout==="wide"?0:e.topMm;e.headerEveryPage!==!1?(p(M),h=M+t.headerHeightMm):h=n.layout==="wide"?0:f}function P(l,M,S,R){const L=u();l.heightMm>L&&i.push(`列表 ${e.id??e.dataset} 行高 ${l.heightMm.toFixed(2)}mm 超出单页可用高度 ${L.toFixed(2)}mm,预览与打印可能截断内容`),b(l.heightMm),o.components.push({kind:"rect",leftMm:e.leftMm,topMm:h,widthMm:e.widthMm,heightMm:l.heightMm,grid:l.grid,nid:a(M),table:{...c,role:S,rowIndex:g++,...R?{source:R}:{}},style:t.borderStyle}),h+=l.heightMm}function k(l){l<=u()&&b(l)}return{keepTogether:k,placeGridRow:P}}function Ae(e,t){if(!e.rowKey)return;const r=t[e.rowKey];if((typeof r!="string"||!r.trim())&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error(`数据集 ${e.dataset} 的 ${e.rowKey} 应为稳定的字符串或有限数字主键`);const n=e.revisionField?t[e.revisionField]:void 0,o=e.sourceTokenField?t[e.sourceTokenField]:void 0;if(n!==void 0&&typeof n!="string"&&!(typeof n=="number"&&Number.isFinite(n)))throw new Error("业务修订号应为字符串或有限数字");if(o!==void 0&&typeof o!="string")throw new Error("来源令牌应为字符串");return{datasetId:e.dataset,rowKey:r,...n===void 0?{}:{revision:n},...o===void 0?{}:{sourceToken:o}}}function He(e,t){const r=new Map;if(!e.rowKey)return r;const n=new Set;for(const o of t){const i=Ae(e,o),a=JSON.stringify(i.rowKey);if(n.has(a))throw new Error(`数据集 ${e.dataset} 的业务主键重复:${String(i.rowKey)}`);n.add(a),r.set(o,i)}return r}function De(e,t,r,n,o){if(!e.grandTotal)return;const i=typeof e.grandTotal=="object"?e.grandTotal:void 0,a=i?.fields??e.groupBy?.subtotal??[];if(a.length===0){n.warnings.push(`列表 ${e.id??""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);return}const s=C(r,n.measurer,i?.label??"合计",te(e.columns,t,a),i?.style??{},re(e.columns,a));o.placeGridRow(s,"listgt","grand-total")}function Ie(e,t,r){const n=He(e,t),o=e.columns.reduce((c,g)=>c+g.widthMm,0),i=o>e.widthMm?e.widthMm/o:1,a=i===1?e:{...e,columns:e.columns.map(c=>({...c,widthMm:c.widthMm*i}))},s={...Re(a,r.measurer),rowHeightFloorMm:a.rowHeightMm??0},d=Fe(a,s,r);let f;for(const c of Ee(t,a.groupBy))if(c.kind==="row")d.placeGridRow(f??z(s,c.row,r.measurer),"listr","body",n.get(c.row)),f=void 0;else if(c.kind==="groupHeader"){const g=C(s,r.measurer,c.label,new Map,a.groupBy?.headerStyle??{},a.columns.length);f=z(s,c.firstRow,r.measurer),a.groupBy?.keepWithNext!==!1&&d.keepTogether(g.heightMm+f.heightMm),d.placeGridRow(g,"listg","group-header")}else{const g=a.groupBy?.subtotal??[],w=C(s,r.measurer,c.label,te(a.columns,c.rows,g),a.groupBy?.subtotalStyle??{},re(a.columns,g));d.placeGridRow(w,"listst","subtotal")}De(a,t,s,r,d)}function G(e){return e.kind==="text"&&typeof e.text=="string"&&(e.text.includes("{page}")||e.text.includes("{totalPages}"))}function Ce(e,t,r,n,o,i){const a={pageWidthMm:t.widthMm,pageHeightMm:t.heightMm,...e.layout===void 0?{}:{layout:e.layout},marginTopMm:t.marginTopMm,marginBottomMm:t.marginBottomMm,marginLeftMm:t.marginLeftMm,marginRightMm:t.marginRightMm,components:t.components};n.push(a);for(const s of r){const d={...s,text:String(s.text??"").replace(/\{page\}/g,String(n.length))};a.components.push(d),d.text.includes("{totalPages}")&&o.push(d)}if(e.layout==="wide"){const s=a.components.reduce((d,f)=>Math.max(d,f.topMm+f.heightMm),0);a.marginBottomMm=i?e.marginBottomMm??0:0,a.pageHeightMm=Math.max(1,s+a.marginBottomMm)}}function ne(e,t,r={}){const n=typeof r=="number"?{mmPerRow:r}:r;if(n.maxPages!==void 0&&(!Number.isSafeInteger(n.maxPages)||n.maxPages<1))throw new RangeError("maxPages 应为正安全整数");const o=[],i=[],a=[];let s=0;const d=f=>`${f}_${(++s).toString(36)}`;for(const[f,c]of e.pages.entries()){const g=Pe(c),w=c.components.filter(G),p=(h=!1)=>{if(n.maxPages!==void 0&&i.length>=n.maxPages)throw new E(n.maxPages,i.length+1);Ce(c,g,w,i,a,h)};for(const[h,m]of c.components.entries()){if(G(m))continue;if(m.kind!=="list"){g.components.push(m);continue}const u=t[m.dataset];Array.isArray(u)||o.push(`数据集 ${m.dataset} 未提供数据,列表 ${m.id??""} 输出为空`),Ie(m,Array.isArray(u)?u:[],{templatePage:c,current:g,warnings:o,nextId:d,pushCurrent:p,measurer:n.measurer??A.heuristicMeasurer,mmPerRow:n.mmPerRow??0,tableId:`table:${f}:${h}`})}p(!0)}for(const f of a)f.text=f.text.replace(/\{totalPages\}/g,String(i.length));return{plan:{schemaVersion:T.RENDER_PLAN_SCHEMA_VERSION,pages:i},warnings:o}}function Oe(e){if(!("mapData"in e))return e;const{load:t,mapData:r,...n}=e;return{...n,load:async o=>{const i=await t(o);$(o.signal);try{return r(i,o)}catch(a){throw new y("validate",`报表 ${o.reportId} 数据映射失败`,a)}}}}class y extends Error{constructor(t,r,n){super(r),this.name="ReportSourceError",this.code=t,this.cause=n}}function H(e){const t=new Error("报表加载已取消");return t.name="AbortError",Object.defineProperty(t,"cause",{value:e.reason}),t}function $(e){if(e?.aborted)throw H(e)}function O(e,t){return t?new Promise((r,n)=>{const o=()=>t.removeEventListener("abort",i),i=()=>{o(),n(H(t))};t.addEventListener("abort",i,{once:!0}),t.aborted&&i(),Promise.resolve(e).then(a=>{o(),r(a)},a=>{o(),n(a)})}):Promise.resolve(e)}function Ke(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new y("validate",`报表 ${t} 的数据集应为对象`);for(const[r,n]of Object.entries(e))if(!Array.isArray(n)||n.some(o=>!o||typeof o!="object"||Array.isArray(o)))throw new y("validate",`报表 ${t} 的数据集 ${r} 应为对象数组`)}async function qe(e,t,r){const{reportId:n,signal:o}=t;try{const i=await O(e(t),o);$(o);const a=B.validateReportTemplate(i);if(!a.ok)throw new y("validate",`报表 ${n} 模板校验失败:${a.errors.slice(0,3).map(s=>`${s.path}: ${s.message}`).join("; ")}`);return r.push(...a.warnings.map(s=>`${n}: ${s.path}: ${s.message}`)),i}catch(i){throw o?.aborted?H(o):i instanceof y?i:i instanceof B.ReportTemplateError?new y("validate",`报表 ${n} 模板校验失败:${i.message}`,i):new y("fetch",`报表 ${n} 模板加载失败:${i instanceof Error?i.message:String(i)}`,i)}}async function _e(e,t,r,n){const o=t.signal;let i;try{if(e.load)i=await O(e.load(t),o);else if(e.provider){const a=await O(e.provider.query(t),o);$(o),Be(a,r),i=a.datasets,n?.(r,a)}else i=e.datasets??{}}catch(a){throw o?.aborted?H(o):a instanceof y?a:new y("fetch",`报表 ${r} 取数失败:${a instanceof Error?a.message:String(a)}`,a)}return $(o),i}function Be(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new y("validate",`报表 ${t} Provider 应返回 datasets 结果对象`);for(const r of["revision","sourceToken"])if(e[r]!==void 0&&typeof e[r]!="string")throw new y("validate",`报表 ${t} Provider ${r} 应为字符串`);if(e.diagnostics!==void 0&&(!Array.isArray(e.diagnostics)||e.diagnostics.some(r=>!r||typeof r.code!="string"||typeof r.message!="string"||!["info","warning","error"].includes(r.severity))))throw new y("validate",`报表 ${t} Provider diagnostics 不符合结构化诊断契约`)}function je(e,t,r){for(const[n,o]of Object.entries(e.dataSchema??{})){let i;try{i=Q(Object.prototype.hasOwnProperty.call(t,n)?t[n]:void 0,o,{...e.dataValidation,path:`$.datasets.${n}`})}catch(a){throw new y("config",`报表 ${r} 数据集 ${n} 字段契约配置无效`,a)}if(!i.ok)throw new y("validate",`报表 ${r} 数据集 ${n} 不符合字段契约:${i.issues[0]?.message}`,{issues:i.issues})}}function We(e,t,r,n,o){const i=o?o.maxPages-o.usedPages:void 0;try{if(i!==void 0&&i<1&&e.pages.length)throw new E(0,1);const a=i===void 0?r.pagination:{...r.pagination,maxPages:Math.max(1,Math.min(i,r.pagination?.maxPages??i))};return ne(e,t,a)}catch(a){const s=a instanceof E&&o&&a.limit===i?new E(o.maxPages,o.usedPages+a.actual):a;throw new y("validate",`报表 ${n} 排版失败:${s instanceof Error?s.message:String(s)}`,s)}}function ze(e,t,r,n){const o=new Map,i=a=>{let s=o.get(a);return s===void 0&&(s=JSON.stringify([r,n,a]),o.set(a,s)),s};for(const a of t.pages)e.push({...a,components:a.components.map(s=>s.table?{...s,table:{...s.table,id:i(s.table.id)}}:s)})}function Ge(e,t={}){if(t.maxPages!==void 0&&(!Number.isSafeInteger(t.maxPages)||t.maxPages<1))throw new y("config","maxPages 应为正安全整数");function r(o){const i=Object.prototype.hasOwnProperty.call(e,o)?e[o]:void 0;if(!i)throw new y("config",`未注册报表 ${o}`);return i}return Object.assign(async({reportIds:o,params:i,signal:a,onWarning:s,onQueryResult:d,...f})=>{$(a);const c=se.createReportTaskReporter({...f,signal:a}),g=[...o],w={...i};if(g.length===0)throw new y("config","缺少报表 ID");const p=g.map(r),h=c.runSync("validate",()=>p.map(l=>j.assertReportParams(l.params??(typeof l.template=="function"?[]:l.template.params)??[],w))),m=[],u=[];for(const[l,M]of p.entries()){$(a);const S=g[l],R={reportId:S,params:h[l],signal:a},L=typeof M.template=="function"?await c.run("query",()=>qe(M.template,R,u),S):M.template;R.params=c.runSync("validate",()=>j.assertReportParams(M.params??L.params??[],R.params),S);const N=await c.run("query",()=>_e(M,R,S,d),S);c.runSync("validate",()=>{Ke(N,S),t.onDatasets?.(S,N,L),je(M,N,S)},S),$(a);const _=c.runSync("layout",()=>We(L,N,M,S,t.maxPages===void 0?void 0:{maxPages:t.maxPages,usedPages:m.length}),S);ze(m,_.plan,l,S),u.push(..._.warnings.map(oe=>`${S}: ${oe}`))}$(a);const b={schemaVersion:T.RENDER_PLAN_SCHEMA_VERSION,pages:m},P=c.runSync("validate",()=>{const l=ae.validateRenderPlan(b);if(!l.ok)throw new y("validate",`渲染计划校验失败:${l.errors.slice(0,3).map(M=>`${M.path}: ${M.message}`).join("; ")}`);return l});u.push(...P.warnings.map(l=>`${l.path}: ${l.message}`));const k=s??t.onWarning??(l=>console.warn("[mach-report]",l));for(const l of u)$(a),k(l);return $(a),b},{getParamDefs:o=>ie.getReportParamDefs(e,o)})}exports.PaginatePageLimitError=E;exports.ReportSourceError=y;exports.createReportSource=Ge;exports.datasetJsonSchema=Se;exports.defineReport=Oe;exports.evalStyleRule=V;exports.formatValue=q;exports.paginateTemplate=ne;exports.parseDateLocal=Y;exports.toExcelNumberFormat=K;exports.toNumber=F;exports.validateDatasetRows=Q;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
import { WorkerOptions as WorkerOptions_2 } from 'node:worker_threads';
|
|
4
|
+
|
|
5
|
+
declare type ComponentKind = "text" | "image" | "barcode" | "qrcode" | "chart" | "line" | "rect" | "ellipse";
|
|
6
|
+
|
|
7
|
+
declare interface ComponentStyle {
|
|
8
|
+
fontSizePx?: number;
|
|
9
|
+
fontSize?: number;
|
|
10
|
+
fontFamily?: string;
|
|
11
|
+
bold?: boolean;
|
|
12
|
+
italic?: boolean;
|
|
13
|
+
underline?: boolean;
|
|
14
|
+
color?: string;
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
align?: "left" | "center" | "right" | "justify";
|
|
17
|
+
verticalAlign?: "top" | "middle" | "bottom";
|
|
18
|
+
lineColor?: string;
|
|
19
|
+
borderColor?: string;
|
|
20
|
+
lineWidthPt?: number;
|
|
21
|
+
borderTop?: boolean;
|
|
22
|
+
borderRight?: boolean;
|
|
23
|
+
borderBottom?: boolean;
|
|
24
|
+
borderLeft?: boolean;
|
|
25
|
+
lineHeight?: number;
|
|
26
|
+
letterSpacing?: number;
|
|
27
|
+
opacity?: number;
|
|
28
|
+
rotateDeg?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 独立 worker_threads 适配器;worker 入口注册自己的模板/Provider,不把函数跨线程序列化。 */
|
|
32
|
+
export declare function createNodeReportExecutor(options: NodeReportExecutorOptions): ReportRuntimeExecutor;
|
|
33
|
+
|
|
34
|
+
declare interface GridCell {
|
|
35
|
+
text?: string;
|
|
36
|
+
rawText?: string;
|
|
37
|
+
/** 原始值,仅供 Excel raw 模式消费;不参与预览、分页与 PDF 绘制。 */
|
|
38
|
+
value?: string | number | boolean | null;
|
|
39
|
+
/** Excel 数字格式(例如 #,##0.00 / 0.00%),不改变 text。 */
|
|
40
|
+
numberFormat?: string;
|
|
41
|
+
/** 编辑输入类型;省略时只按原始值推断,数字字符串不会被转换为数值。 */
|
|
42
|
+
valueType?: "text" | "number" | "boolean";
|
|
43
|
+
/** 单元格级编辑控制;预览仍需显式开启 editing。 */
|
|
44
|
+
editable?: boolean;
|
|
45
|
+
source?: ReportCellSource;
|
|
46
|
+
/** Excel 公式保留元数据;当前引擎不计算公式,公式格始终只读。 */
|
|
47
|
+
formula?: string;
|
|
48
|
+
children?: PlanComponent[];
|
|
49
|
+
colSpan?: number;
|
|
50
|
+
rowSpan?: number;
|
|
51
|
+
style?: ComponentStyle;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare interface NodeReportExecutorOptions extends ReportWorkerOptions {
|
|
55
|
+
filename?: string | URL;
|
|
56
|
+
workerUrl?: string | URL;
|
|
57
|
+
workerOptions?: WorkerOptions_2;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare interface PlanComponent {
|
|
61
|
+
kind: ComponentKind;
|
|
62
|
+
leftMm: number;
|
|
63
|
+
topMm: number;
|
|
64
|
+
widthMm: number;
|
|
65
|
+
heightMm: number;
|
|
66
|
+
nid?: string;
|
|
67
|
+
rkey?: string;
|
|
68
|
+
text?: string;
|
|
69
|
+
rawText?: string;
|
|
70
|
+
lines?: string[];
|
|
71
|
+
richParagraphs?: RichParagraph[];
|
|
72
|
+
imageData?: string;
|
|
73
|
+
/** 明确指定线段方向;省略保持历史水平线行为。 */
|
|
74
|
+
lineDirection?: "down" | "up";
|
|
75
|
+
grid?: PlanGrid;
|
|
76
|
+
table?: PlanTableFragment;
|
|
77
|
+
style?: ComponentStyle;
|
|
78
|
+
meta?: Record<string, unknown>;
|
|
79
|
+
/** MachReport 扩展字段:未知 kind 的兜底渲染标记 */
|
|
80
|
+
fallbackText?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare interface PlanGrid {
|
|
84
|
+
/** 行内允许 null 空位;渲染器按空单元格处理 */
|
|
85
|
+
cells: (GridCell | null)[][];
|
|
86
|
+
colWidthsMm?: number[];
|
|
87
|
+
rowHeightsMm?: number[];
|
|
88
|
+
gapMm?: number;
|
|
89
|
+
/** 单元格四边内距;旧静态网格默认 0.5mm,分页列表使用其真实测量内距。 */
|
|
90
|
+
paddingMm?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare interface PlanPage {
|
|
94
|
+
/** wide 表示完整自然列宽;页面仅为预览的垂直窗口分段。 */
|
|
95
|
+
layout?: "page" | "wide";
|
|
96
|
+
pageWidthMm: number;
|
|
97
|
+
pageHeightMm: number;
|
|
98
|
+
marginTopMm?: number;
|
|
99
|
+
marginBottomMm?: number;
|
|
100
|
+
marginLeftMm?: number;
|
|
101
|
+
marginRightMm?: number;
|
|
102
|
+
components: PlanComponent[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 列表的逻辑行来源;用于连续 Excel 重组,避免按文本猜测重复表头。 */
|
|
106
|
+
declare interface PlanTableFragment {
|
|
107
|
+
/** 在整个计划中唯一的逻辑表身份;同一表的分页片段共享身份。 */
|
|
108
|
+
id: string;
|
|
109
|
+
/** 表头固定 -1;其余行(包括组头/小计/总计)从 0 连续递增。 */
|
|
110
|
+
rowIndex: number;
|
|
111
|
+
role: "header" | "body" | "group-header" | "subtotal" | "grand-total";
|
|
112
|
+
/** 按物理列顺序保存字段身份;不以表头显示文本判断列结构。 */
|
|
113
|
+
columnKeys: string[];
|
|
114
|
+
layout?: "page" | "wide";
|
|
115
|
+
title?: string;
|
|
116
|
+
/** 只有宿主声明稳定 rowKey 时生成,不能用显示顺序替代业务主键。 */
|
|
117
|
+
source?: Omit<ReportCellSource, "field" | "rowKey"> & {
|
|
118
|
+
rowKey?: string | number;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
declare interface PreparedReport {
|
|
123
|
+
plan: RenderPlan;
|
|
124
|
+
diagnostics: ReportDiagnostic[];
|
|
125
|
+
stats: ReportRuntimeStats;
|
|
126
|
+
revisions: Record<string, {
|
|
127
|
+
revision?: string;
|
|
128
|
+
sourceToken?: string;
|
|
129
|
+
}>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare interface RenderPlan {
|
|
133
|
+
schemaVersion: string;
|
|
134
|
+
pages: PlanPage[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 可持久化的业务身份与计划坐标独立;权限及并发校验仍由业务服务器执行。 */
|
|
138
|
+
declare interface ReportCellSource {
|
|
139
|
+
datasetId: string;
|
|
140
|
+
rowKey: string | number;
|
|
141
|
+
field: string;
|
|
142
|
+
revision?: string | number;
|
|
143
|
+
sourceToken?: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare interface ReportDescription {
|
|
147
|
+
id: string;
|
|
148
|
+
params: ReportParamDef[];
|
|
149
|
+
paramsSchema: Record<string, unknown>;
|
|
150
|
+
datasetsSchema: Record<string, Record<string, unknown>>;
|
|
151
|
+
/** Provider 的可选远程能力;runtime 自身始终提供 PDF/XLSX 导出。 */
|
|
152
|
+
capabilities: {
|
|
153
|
+
save: boolean;
|
|
154
|
+
export: boolean;
|
|
155
|
+
templates: boolean;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare interface ReportDiagnostic {
|
|
160
|
+
code: string;
|
|
161
|
+
message: string;
|
|
162
|
+
path?: string;
|
|
163
|
+
severity: "warning" | "error" | "info";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** 报表参数定义(声明式,模板自描述参数面:渲染组件据此生成查询面板) */
|
|
167
|
+
declare interface ReportParamDef {
|
|
168
|
+
/** 参数名(传入 params,与数据集 SQL #{field} 绑定对应) */
|
|
169
|
+
field: string;
|
|
170
|
+
/** 显示名(缺省用 field) */
|
|
171
|
+
label?: string;
|
|
172
|
+
type?: "text" | "number" | "date" | "select";
|
|
173
|
+
/** select 选项 */
|
|
174
|
+
options?: Array<{
|
|
175
|
+
label: string;
|
|
176
|
+
value: string;
|
|
177
|
+
}>;
|
|
178
|
+
defaultValue?: string;
|
|
179
|
+
required?: boolean;
|
|
180
|
+
placeholder?: string;
|
|
181
|
+
/** 数字上下界;date 参数使用 YYYY-MM-DD 字符串(含边界)。 */
|
|
182
|
+
min?: number | string;
|
|
183
|
+
max?: number | string;
|
|
184
|
+
minLength?: number;
|
|
185
|
+
maxLength?: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare interface ReportParamIssue {
|
|
189
|
+
code: ReportParamIssueCode;
|
|
190
|
+
path: string;
|
|
191
|
+
field: string;
|
|
192
|
+
message: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare type ReportParamIssueCode = "definition" | "required" | "type" | "option" | "minimum" | "maximum" | "minLength" | "maxLength";
|
|
196
|
+
|
|
197
|
+
declare interface ReportParamValidation {
|
|
198
|
+
ok: boolean;
|
|
199
|
+
/** 保留历史取数契约的字符串形式;未知参数保留,不能代替接口权限白名单。 */
|
|
200
|
+
values: Record<string, string>;
|
|
201
|
+
/** JSON Schema 对应的规范值:number 参数转换为有限数字。 */
|
|
202
|
+
typedValues: Record<string, string | number>;
|
|
203
|
+
issues: ReportParamIssue[];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare interface ReportRuntime {
|
|
207
|
+
describe(reportIds?: string[]): ReportDescription[];
|
|
208
|
+
validate(input: Omit<ReportRuntimeInput, "signal">): ReportParamValidation;
|
|
209
|
+
prepare(input: ReportRuntimeInput): Promise<PreparedReport>;
|
|
210
|
+
export(input: ReportRuntimeExportInput): Promise<ReportRuntimeExportResult>;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** 可用 worker_threads/进程/RPC 实现;接收可序列化请求,signal 由桥接层映射为取消消息。 */
|
|
214
|
+
declare interface ReportRuntimeExecutor {
|
|
215
|
+
prepare(input: Omit<ReportRuntimeInput, "signal" | "onEvent">, signal?: AbortSignal, onEvent?: ReportTaskObserver): Promise<PreparedReport>;
|
|
216
|
+
export(input: Omit<ReportRuntimeExportInput, "signal" | "onEvent">, signal?: AbortSignal, onEvent?: ReportTaskObserver): Promise<ReportRuntimeExportResult>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare interface ReportRuntimeExportInput extends ReportRuntimeInput {
|
|
220
|
+
format: "pdf" | "xlsx";
|
|
221
|
+
/** strict 在编码前拒绝已识别的输出降级;默认保留诊断并继续。 */
|
|
222
|
+
fidelity?: "warn" | "strict";
|
|
223
|
+
/** PDF 中文需宿主显式提供有授权的字体;不隐式下载字体或资源。 */
|
|
224
|
+
pdf?: {
|
|
225
|
+
customFontBytes?: Uint8Array | ArrayBuffer;
|
|
226
|
+
customFontName?: string;
|
|
227
|
+
customFontFaces?: {
|
|
228
|
+
regular: Uint8Array | ArrayBuffer;
|
|
229
|
+
bold?: Uint8Array | ArrayBuffer;
|
|
230
|
+
italic?: Uint8Array | ArrayBuffer;
|
|
231
|
+
boldItalic?: Uint8Array | ArrayBuffer;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
xlsx?: {
|
|
235
|
+
sheetMode?: "auto" | "pages" | "continuous";
|
|
236
|
+
valueMode?: "text" | "raw";
|
|
237
|
+
paperSize?: "auto" | "a3" | "a4" | "a5";
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare interface ReportRuntimeExportResult extends Omit<PreparedReport, "plan"> {
|
|
242
|
+
bytes: Uint8Array;
|
|
243
|
+
format: "pdf" | "xlsx";
|
|
244
|
+
contentType: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
declare interface ReportRuntimeInput extends ReportTaskMonitoring {
|
|
248
|
+
reportIds: string[];
|
|
249
|
+
params?: Record<string, string>;
|
|
250
|
+
signal?: AbortSignal;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
declare interface ReportRuntimeStats {
|
|
254
|
+
rows: number;
|
|
255
|
+
pages: number;
|
|
256
|
+
cells: number;
|
|
257
|
+
durationMs: number;
|
|
258
|
+
outputBytes?: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 阶段事件只包含可序列化值;不表示估算百分比,也不包含业务数据。 */
|
|
262
|
+
declare interface ReportTaskEvent {
|
|
263
|
+
taskId: string;
|
|
264
|
+
correlationId?: string;
|
|
265
|
+
stage: "query" | "validate" | "layout" | "encode";
|
|
266
|
+
status: "started" | "completed" | "failed";
|
|
267
|
+
reportId?: string;
|
|
268
|
+
completed?: number;
|
|
269
|
+
total?: number;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare interface ReportTaskMonitoring {
|
|
273
|
+
taskId?: string;
|
|
274
|
+
correlationId?: string;
|
|
275
|
+
onEvent?: ReportTaskObserver;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
declare type ReportTaskObserver = (event: ReportTaskEvent) => void;
|
|
279
|
+
|
|
280
|
+
export declare class ReportWorkerError extends Error {
|
|
281
|
+
readonly code?: string;
|
|
282
|
+
readonly path?: string;
|
|
283
|
+
readonly issues?: unknown;
|
|
284
|
+
readonly diagnostics?: unknown;
|
|
285
|
+
constructor(error: SerializedReportError);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
declare interface ReportWorkerOptions {
|
|
289
|
+
timeoutMs?: number;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
declare interface RichParagraph {
|
|
293
|
+
segments: RichSegment[];
|
|
294
|
+
align?: ComponentStyle["align"];
|
|
295
|
+
lineHeight?: number;
|
|
296
|
+
spaceBeforeMm?: number;
|
|
297
|
+
spaceAfterMm?: number;
|
|
298
|
+
indentMm?: number;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
declare interface RichSegment {
|
|
302
|
+
kind?: "text" | "field";
|
|
303
|
+
text?: string;
|
|
304
|
+
field?: string;
|
|
305
|
+
style?: ComponentStyle;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
declare interface SerializedReportError {
|
|
309
|
+
name: string;
|
|
310
|
+
message: string;
|
|
311
|
+
code?: string;
|
|
312
|
+
path?: string;
|
|
313
|
+
issues?: unknown;
|
|
314
|
+
diagnostics?: unknown;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Node Worker 入口调用;主线程调用会明确报错。 */
|
|
318
|
+
export declare function serveNodeReportWorker(runtime: ReportRuntime): () => void;
|
|
319
|
+
|
|
320
|
+
export { }
|