@agile-team/mach-report 2.6.1 → 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.
Files changed (61) hide show
  1. package/README.md +37 -4
  2. package/dist/ReportPreview-BdvoqdOd.cjs +6 -0
  3. package/dist/ReportPreview-COFkbeEM.js +3719 -0
  4. package/dist/{assets-NVA_sftu.js → assets-B9qJku3V.js} +54 -57
  5. package/dist/assets-RZan7EyL.cjs +1 -0
  6. package/dist/capabilities-joSutDF8.js +63 -0
  7. package/dist/capabilities-xGTpnPjJ.cjs +1 -0
  8. package/dist/designer.cjs +1 -1
  9. package/dist/designer.d.cts +869 -753
  10. package/dist/designer.d.ts +869 -753
  11. package/dist/designer.js +490 -234
  12. package/dist/index.cjs +8 -8
  13. package/dist/index.d.cts +86 -3
  14. package/dist/index.d.ts +86 -3
  15. package/dist/index.js +582 -508
  16. package/dist/pdf.cjs +30 -30
  17. package/dist/pdf.d.cts +11 -3
  18. package/dist/pdf.d.ts +11 -3
  19. package/dist/pdf.js +1501 -1500
  20. package/dist/{plugin-BqBkn_kI.cjs → plugin-9t_ZFwhz.cjs} +1 -1
  21. package/dist/{plugin-Ds10VnQO.js → plugin-s8Ay8kKk.js} +1 -1
  22. package/dist/progress-DD964VAB.js +102 -0
  23. package/dist/progress-KvhwXZ1Q.cjs +1 -0
  24. package/dist/{report-source-B9bENO0F.js → report-source-BXHNy_AD.js} +337 -332
  25. package/dist/report-source-CCAvFE3t.cjs +1 -0
  26. package/dist/server/node.d.cts +26 -3
  27. package/dist/server/node.d.ts +26 -3
  28. package/dist/server-node.cjs +1 -1
  29. package/dist/server-node.js +125 -92
  30. package/dist/server.cjs +1 -1
  31. package/dist/server.d.cts +28 -3
  32. package/dist/server.d.ts +28 -3
  33. package/dist/server.js +172 -164
  34. package/dist/style.css +1 -1
  35. package/dist/task-events-DQ276fn2.cjs +1 -0
  36. package/dist/task-events-Dpsvf_t2.js +47 -0
  37. package/dist/vue/async.d.cts +1507 -2083
  38. package/dist/vue/async.d.ts +1507 -2083
  39. package/dist/vue/index.d.cts +2376 -3310
  40. package/dist/vue/index.d.ts +2376 -3310
  41. package/dist/vue-async.cjs +1 -1
  42. package/dist/vue-async.js +3 -3
  43. package/dist/vue.cjs +1 -1
  44. package/dist/vue.js +131 -107
  45. package/dist/worker.cjs +1 -1
  46. package/dist/worker.d.cts +26 -3
  47. package/dist/worker.d.ts +26 -3
  48. package/dist/worker.js +110 -85
  49. package/dist/xlsx.cjs +14 -14
  50. package/dist/xlsx.d.cts +11 -3
  51. package/dist/xlsx.d.ts +11 -3
  52. package/dist/xlsx.js +656 -652
  53. package/package.json +2 -2
  54. package/dist/ReportPreview-Dk-28QAi.js +0 -2946
  55. package/dist/ReportPreview-FSvcBLjH.cjs +0 -6
  56. package/dist/assets-66UBlhES.cjs +0 -1
  57. package/dist/capabilities-CNjIirfo.js +0 -36
  58. package/dist/capabilities-D4xeVYSR.cjs +0 -1
  59. package/dist/grid-geometry-BNptEcMm.js +0 -65
  60. package/dist/grid-geometry-CZ_cYB6O.cjs +0 -1
  61. package/dist/report-source-BbNkkBDy.cjs +0 -1
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./render-plan-CckPEQyf.cjs"),I=require("./report-source-BbNkkBDy.cjs"),m=require("./style-CpwiOPyB.cjs"),X=require("./validate-DfHPD8wX.cjs"),O=require("./textwrap-CnGsEum6.cjs"),j=require("./grid-geometry-CZ_cYB6O.cjs"),z=require("./assets-66UBlhES.cjs"),H=require("./capabilities-D4xeVYSR.cjs"),_e=require("./page-window-index-DEjnM6IB.cjs"),F=require("./template-registry-DWExx0gU.cjs"),W=require("./param-validation-CiTxFeZ8.cjs"),ve=require("./number-format-CZ2T_5kF.cjs"),ze={root:"mr-root",page:"mr-page",comp:"mr-comp",text:"mr-text",lines:"mr-lines",line:"mr-line",rich:"mr-rich",paragraph:"mr-paragraph",segment:"mr-segment",image:"mr-image",shape:"mr-shape",grid:"mr-grid",row:"mr-row",cell:"mr-cell",unknown:"mr-unknown"};function P(e,t){return t?.classNames?.[e]??ze[e]}class He{constructor(){this.props=[]}add(t,r){return r==null||r===!1||r===""?this:(this.props.push([t,String(r)]),this)}mm(t,r,n,o=2){return this.add(t,`${m.round(m.mmToPx(r,n),o)}px`)}toString(){let t="";for(const[r,n]of this.props)t+=`${r}:${n};`;return t}applyTo(t){const r=this.toString();r&&(t.style.cssText=r)}}function M(e,t="unset"){return new He().add("all",t).add("display",e).add("box-sizing","border-box")}function be(e,t,r){e.add("color",t.color).add("font-family",t.fontFamily).add("font-weight",t.bold!=null?t.bold?"700":"400":void 0).add("font-style",t.italic!=null?t.italic?"italic":"normal":void 0).add("text-decoration",t.underline!=null?t.underline?"underline":"none":void 0).add("letter-spacing",t.letterSpacing!=null?`${t.letterSpacing}pt`:void 0).add("line-height",String(m.resolveLineHeight(t))).add("text-align",t.align);const n=m.resolveFontSize(t,r);e.add("font-size",`${m.round(n.fontSizePx,2)}px`)}function Be(e,t,r){const n=t.style??{};be(e,n,r),e.add("background-color",n.backgroundColor).add("opacity",n.opacity!=null?String(n.opacity):void 0).add("transform",n.rotateDeg?`rotate(${n.rotateDeg}deg)`:void 0)}function je(e,t,r,n,o,l){const i=e.cell,a=l.createElement("td");a.className=P("cell",o),a.dataset.mrRowIndex=String(e.ri),a.dataset.mrColumnIndex=String(e.ci),a.setAttribute("role",t.table?.role==="header"?"columnheader":"cell"),i.colSpan&&(a.colSpan=i.colSpan),i.rowSpan&&(a.rowSpan=i.rowSpan);const s=m.mergeComponentStyles(t.style,i.style),d=M("block").add("position","absolute").mm("left",e.xMm,n).mm("top",e.yMm,n).mm("width",e.widthMm,n).mm("height",e.heightMm,n).add("background-color",s.backgroundColor).add("vertical-align",s.verticalAlign??"middle");be(d,s,n),d.applyTo(a);const c=l.createElement("div");c.className="mr-cell-content",M("flex").add("position","absolute").mm("left",r,n).mm("right",r,n).mm("top",r,n).mm("bottom",r,n).add("flex-direction","column").add("justify-content",s.verticalAlign==="top"?"flex-start":s.verticalAlign==="bottom"?"flex-end":"center").add("overflow-wrap","anywhere").add("overflow","hidden").applyTo(c),i.text!=null&&c.append(i.text);for(const u of i.children??[])c.appendChild(ie(u,n,o,l));return a.appendChild(c),a}function We(e,t,r,n){return z.resolveGridStrokes(e,t).map(o=>{const l=`${m.round(o.widthPt*r/72,2)}px solid ${o.color}`,i=n.createElement("div");i.className="mr-grid-edge",i.setAttribute("aria-hidden","true");const a=o.kind==="h";return M("block").add("position","absolute").add("pointer-events","none").mm("left",a?o.from:o.pos,r).mm("top",a?o.pos:o.from,r).mm("width",a?o.to-o.from:0,r).mm("height",a?0:o.to-o.from,r).add(a?"border-top":"border-left",l).applyTo(i),i})}function Ke(e,t,r,n,o){const l=o.createElement("table");l.className=P("grid",n),l.setAttribute("role","table"),M("block").add("position","relative").add("width","100%").add("height","100%").applyTo(l);const i=j.resolveGridLayout(e,t.widthMm,t.heightMm),a=o.createElement("tbody");M("contents").applyTo(a),l.appendChild(a);const s=e.cells.map(()=>{const c=o.createElement("tr");return c.className=P("row",n),c.setAttribute("role","row"),M("contents").applyTo(c),a.appendChild(c),c});for(const c of i.cells)s[c.ri].appendChild(je(c,t,e.paddingMm??.5,r,n,o));const d=o.createElement("div");return M("block").add("position","relative").add("width","100%").add("height","100%").applyTo(d),d.append(l,...We(i,t,r,o)),d}function Ve(e,t,r,n){const o=n.createElement("div");o.className=P("paragraph",r),M("block").add("text-align",e.align).add("line-height",e.lineHeight!=null?String(e.lineHeight):void 0).mm("margin-top",e.spaceBeforeMm??0,t).mm("margin-bottom",e.spaceAfterMm??0,t).mm("text-indent",e.indentMm??0,t).applyTo(o);for(const l of e.segments||[]){const i=n.createElement("span");i.className=P("segment",r),i.textContent=l.kind==="field"?l.field??"":l.text??"";const a=M("inline");if(l.style){const s=l.style;a.add("color",s.color).add("font-family",s.fontFamily).add("font-weight",s.bold!=null?s.bold?"700":"400":void 0).add("font-style",s.italic!=null?s.italic?"italic":"normal":void 0).add("text-decoration",s.underline!=null?s.underline?"underline":"none":void 0),(s.fontSize!=null||s.fontSizePx!=null)&&a.add("font-size",`${m.round(m.resolveFontSize(s,t).fontSizePx,2)}px`)}a.applyTo(i),o.appendChild(i)}return o}function Ge(e,t,r,n){if(b.isRichText(e)){const o=n.createElement("div");o.className=P("rich",r),M("block").applyTo(o);for(const l of e.richParagraphs)o.appendChild(Ve(l,t,r,n));return o}if(Array.isArray(e.lines)&&e.lines.length>0){const o=n.createElement("div");o.className=P("lines",r),M("block").applyTo(o);for(const l of e.lines){const i=n.createElement("div");i.className=P("line",r),i.textContent=l,M("block").add("white-space","pre").add("min-height","1lh").applyTo(i),o.appendChild(i)}return o}return e.text??""}function Ue(e,t,r,n){const o=n.createElement("div");o.className=P("text",r);const l=e.style||{};return M("flex").add("width","100%").add("height","100%").add("flex-direction","column").add("justify-content",l.verticalAlign==="middle"?"center":l.verticalAlign==="bottom"?"flex-end":"flex-start").add("overflow-wrap","anywhere").add("overflow","hidden").applyTo(o),o.append(Ge(e,t,r,n)),o}function qe(e,t,r){const n=r.createElement("img");return n.className=P("image",t),n.src=e.imageData,M("block").add("width","100%").add("height","100%").add("object-fit","contain").applyTo(n),n.alt=e.kind,n}function he(e,t,r,n){const o=n.createElement("div");o.className=P("shape",r);const l=e.style||{},i=m.resolveStroke(l),a=m.resolveBoxBorders(l),s=`${m.round(i.widthPt*t/72,2)}px solid ${i.color}`,d=M("block");return e.grid?d.add("position","relative"):e.kind==="rect"?(a.top&&d.add("border-top",s),a.right&&d.add("border-right",s),a.bottom&&d.add("border-bottom",s),a.left&&d.add("border-left",s)):e.kind==="ellipse"?(a.inner&&d.add("border",s).add("border-radius","50%"),l.backgroundColor&&d.add("background-color",l.backgroundColor)):e.kind==="line"&&d.add("height","0").add("border-top",s),d.add("box-sizing","border-box").add("width","100%").add("height","100%"),d.applyTo(o),o}function Je(e,t,r){const n=r.createElementNS("http://www.w3.org/2000/svg","svg"),o=m.mmToPx(e.widthMm,t),l=m.mmToPx(e.heightMm,t);n.setAttribute("width",String(Math.max(1,o))),n.setAttribute("height",String(Math.max(1,l))),n.setAttribute("aria-hidden","true"),n.style.overflow="visible",n.style.display="block";const i=r.createElementNS("http://www.w3.org/2000/svg","line");i.setAttribute("x1","0"),i.setAttribute("x2",String(o)),i.setAttribute("y1",e.lineDirection==="up"?String(l):"0"),i.setAttribute("y2",e.lineDirection==="up"?"0":String(l));const a=m.resolveStroke({...e.style,borderColor:e.style?.lineColor??e.style?.borderColor});return i.setAttribute("stroke",a.color),i.setAttribute("stroke-width",String(a.widthPt*t/72)),n.appendChild(i),n}function ie(e,t,r,n){const o=n.createElement("div");o.className=`${P("comp",r)} mr-kind-${e.kind}`;const l=M("block").add("position","absolute").mm("left",e.leftMm,t).mm("top",e.topMm,t).mm("width",e.widthMm,t).mm("height",e.heightMm,t).add("box-sizing","border-box");if(Be(l,e,t),l.applyTo(o),b.isImageBackedComponent(e))return o.appendChild(qe(e,r,n)),o;if(e.kind==="text")return o.appendChild(Ue(e,t,r,n)),o;if(e.grid){const a=he(e,t,r,n);return a.appendChild(Ke(e.grid,e,t,r,n)),o.appendChild(a),o}if(e.kind==="line"&&e.lineDirection)return o.appendChild(Je(e,t,n)),o;if(e.kind==="line"||e.kind==="rect"||e.kind==="ellipse")return o.appendChild(he(e,t,r,n)),o;const i=n.createElement("div");return i.className=P("unknown",r),M("block").applyTo(i),i.textContent=e.fallbackText??`[${e.kind}]`,i.dataset.mrUnsupported=e.kind,i.setAttribute("role","note"),o.appendChild(i),o}function ye(e,t,r,n){const o=n.createElement("div");return o.className=P("page",r),M("block","initial").add("position","relative").add("font-family",b.DEFAULT_FONT_FAMILY).add("font-size",`${m.round(m.resolveFontSize(void 0,t).fontSizePx,2)}px`).add("line-height",String(m.resolveLineHeight(void 0))).add("white-space","pre-wrap").add("direction","ltr").mm("width",e.pageWidthMm,t).mm("height",e.pageHeightMm,t).add("background-color","#fff").add("color",b.DEFAULT_TEXT_COLOR).add("overflow","hidden").add("box-sizing","border-box").applyTo(o),e.components.forEach((l,i)=>{const a=ie(l,t,r,n);a.dataset.mrComponentIndex=String(i),o.appendChild(a)}),o}function Ye(e,t,r={}){const n=r.dpi??96;H.reportOutputDiagnostics(e,"dom",r);const o=t.createElement("div");return o.className=P("root",r),M("block").applyTo(o),o.dataset.schemaVersion=e.schemaVersion,e.pages.forEach(l=>{o.appendChild(ye(l,n,r,t))}),o}function $(e){if(e?.aborted)throw e.reason??new DOMException("The operation was aborted.","AbortError")}const Xe=(e,t)=>($(t),/^data:image\/(?:png|jpe?g|webp|gif|svg\+xml)[;,]/i.test(e)?new Promise((r,n)=>{const o=new Image,l=()=>{o.onload=null,o.onerror=null,t?.removeEventListener("abort",i)},i=()=>{l(),o.src="",n(t?.reason??new DOMException("The operation was aborted.","AbortError"))};o.onload=()=>{l(),r(o)},o.onerror=()=>{l(),n(new Error("Image could not be decoded for Canvas output."))},t?.addEventListener("abort",i,{once:!0}),o.src=e}):Promise.reject(new TypeError("Canvas imageData must be an image data URL; provide imageLoader for other sources.")));function Ze(e,t,r){return $(r),r?new Promise((n,o)=>{const l=()=>o(r.reason??new DOMException("The operation was aborted.","AbortError"));r.addEventListener("abort",l,{once:!0}),Promise.resolve().then(()=>e(t,r)).then(n,o).finally(()=>r.removeEventListener("abort",l))}):e(t)}async function Qe(e,t,r){const n=new Map;for(const o of e.components)!b.isImageBackedComponent(o)||n.has(o.imageData)||n.set(o.imageData,await Ze(t,o.imageData,r));return $(r),n}function et(e,t,r,n,o,l){const i=t,a=i.naturalWidth??i.width??o,s=i.naturalHeight??i.height??l;if(a<=0||s<=0)throw new RangeError("Decoded Canvas image dimensions must be positive.");const d=Math.min(o/a,l/s),c=a*d,u=s*d;e.drawImage(t,r+(o-c)/2,n+(l-u)/2,c,u)}function Me(e){return _e.createPageWindowIndex(e.pageHeightsPx,e.gapPx).window(e.viewportHeightPx,e.scrollTopPx,e.overscan)}const ae=96/25.4;function Z(e,t=96){const r=t/96*ae;return{widthPx:Math.max(1,Math.round(e.pageWidthMm*r)),heightPx:Math.max(1,Math.round(e.pageHeightMm*r))}}function Te(e,t,r,n=64e6){if(!Number.isFinite(t)||t<=0||!Number.isFinite(r)||r<=0)throw new RangeError("Canvas dpr and dpi must be positive finite numbers.");if(!Number.isFinite(n)||n<=0)throw new RangeError("maxCanvasPixels must be positive and finite.");const o=Z(e,r),l=Math.round(o.widthPx*t),i=Math.round(o.heightPx*t);if(!Number.isSafeInteger(l)||!Number.isSafeInteger(i)||l*i>n)throw new RangeError("Canvas page exceeds maxCanvasPixels; reduce resolution or split the report.");return{width:l,height:i}}function Ee(e,t,r,n){const o=document.createElement("canvas"),{widthPx:l,heightPx:i}=Z(e,r),a=Te(e,t,r,n);o.width=a.width,o.height=a.height,o.style.width=`${l}px`,o.style.height=`${i}px`;const s=o.getContext("2d");if(!s)throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");return s.scale(t,t),s.fillStyle="#ffffff",s.fillRect(0,0,l,i),{canvas:o,ctx:s}}function tt(e,t=96){return m.resolveFontSize(e,t).fontSizePx}function xe(e,t,r,n,o,l,i,a="top"){e.font=`${t.italic?"italic ":""}${t.bold?"bold ":""}${t.fontSizePx}px ${i}`,"letterSpacing"in e&&(e.letterSpacing="0px"),e.fillStyle=t.color,e.textBaseline="alphabetic";const s=t.fontSizePx*t.lineHeight,d=t.text===""?[""]:t.text.split(`
2
- `),c=d.length*s;let u=n;a==="middle"?u=n+(l-c)/2:a==="bottom"&&(u=n+l-c),d.forEach((f,h)=>{rt(e,f,t,r,u+h*s+t.fontSizePx*.8,o)}),e.textAlign="left"}function rt(e,t,r,n,o,l){const i=Array.from(t),a=r.letterSpacingPx??0;if(!a){e.textAlign=r.align==="center"?"center":r.align==="right"?"right":"left";const u=r.align==="center"?n+l/2:r.align==="right"?n+l:n;e.fillText(t,u,o);return}const s=e.measureText(t).width+Math.max(0,i.length-1)*a,d=r.align==="center"?n+(l-s)/2:r.align==="right"?n+l-s:n;e.textAlign="left";let c="";i.forEach((u,f)=>{e.fillText(u,d+e.measureText(c).width+f*a,o),c+=u})}function nt(e,t,r,n,o,l,i){for(const a of z.resolveGridStrokes(t,r))e.strokeStyle=a.color,e.lineWidth=m.ptToPx(a.widthPt,i),e.beginPath(),a.kind==="v"?(e.moveTo(n+a.pos*l,o+a.from*l),e.lineTo(n+a.pos*l,o+a.to*l)):(e.moveTo(n+a.from*l,o+a.pos*l),e.lineTo(n+a.to*l,o+a.pos*l)),e.stroke()}function ot(e,t,r,n,o,l){e.beginPath(),t.top&&(e.moveTo(r,n),e.lineTo(r+o,n)),t.right&&(e.moveTo(r+o,n),e.lineTo(r+o,n+l)),t.bottom&&(e.moveTo(r+o,n+l),e.lineTo(r,n+l)),t.left&&(e.moveTo(r,n+l),e.lineTo(r,n)),e.stroke()}function it(e,t,r,n,o,l,i,a,s,d,c){const u=j.resolveGridLayout(t,l/a,i/a);for(const h of u.cells){const p=h.cell.style?.backgroundColor??r.style?.backgroundColor;p&&(e.fillStyle=p,e.fillRect(n+h.xMm*a,o+h.yMm*a,h.widthMm*a,h.heightMm*a))}nt(e,u,r,n,o,a,s);const f=t.paddingMm??.5;for(const h of u.cells){const p=h.cell.text??"";if(!p)continue;const g=m.mergeComponentStyles(r.style,h.cell.style),v=m.resolveFontSize(g,s),E=Math.max(0,h.widthMm-2*f),x=O.wrapText(p,E,{fontSizePt:v.fontSizePt,bold:g.bold,italic:g.italic,fontFamily:g.fontFamily??d,letterSpacingPt:g.letterSpacing},c).join(`
3
- `);xe(e,{text:x,fontSizePx:v.fontSizePx,bold:g.bold??!1,italic:g.italic,color:m.resolveTextColor(g,b.DEFAULT_TEXT_COLOR),align:g.align??"left",lineHeight:m.resolveLineHeight(g),letterSpacingPx:m.ptToPx(g.letterSpacing??0,s)},n+(h.xMm+f)*a,o+(h.yMm+f)*a,E*a,Math.max(0,h.heightMm-2*f)*a,g.fontFamily??d,g.verticalAlign??"middle")}}function at(e,t,r,n,o,l,i,a,s){const d=t.style??{},c=m.resolveFontSize(d,i),u=b.isRichText(t)?t.richParagraphs.map(f=>f.segments.map(h=>h.text??h.field??"").join("")).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./render-plan-CckPEQyf.cjs"),A=require("./report-source-CCAvFE3t.cjs"),f=require("./style-CpwiOPyB.cjs"),Z=require("./validate-DfHPD8wX.cjs"),$=require("./textwrap-CnGsEum6.cjs"),H=require("./progress-KvhwXZ1Q.cjs"),j=require("./assets-RZan7EyL.cjs"),D=require("./capabilities-xGTpnPjJ.cjs"),je=require("./page-window-index-DEjnM6IB.cjs"),N=require("./template-registry-DWExx0gU.cjs"),q=require("./param-validation-CiTxFeZ8.cjs"),be=require("./number-format-CZ2T_5kF.cjs"),We={root:"mr-root",page:"mr-page",comp:"mr-comp",text:"mr-text",lines:"mr-lines",line:"mr-line",rich:"mr-rich",paragraph:"mr-paragraph",segment:"mr-segment",image:"mr-image",shape:"mr-shape",grid:"mr-grid",row:"mr-row",cell:"mr-cell",unknown:"mr-unknown"};function P(e,t){return t?.classNames?.[e]??We[e]}class qe{constructor(){this.props=[]}add(t,n){return n==null||n===!1||n===""?this:(this.props.push([t,String(n)]),this)}mm(t,n,r,o=2){return this.add(t,`${f.round(f.mmToPx(n,r),o)}px`)}toString(){let t="";for(const[n,r]of this.props)t+=`${n}:${r};`;return t}applyTo(t){const n=this.toString();n&&(t.style.cssText=n)}}function x(e,t="unset"){return new qe().add("all",t).add("display",e).add("box-sizing","border-box")}function ye(e,t,n){e.add("color",t.color).add("font-family",t.fontFamily).add("font-weight",t.bold!=null?t.bold?"700":"400":void 0).add("font-style",t.italic!=null?t.italic?"italic":"normal":void 0).add("text-decoration",t.underline!=null?t.underline?"underline":"none":void 0).add("letter-spacing",t.letterSpacing!=null?`${t.letterSpacing}pt`:void 0).add("line-height",String(f.resolveLineHeight(t))).add("text-align",t.align);const r=f.resolveFontSize(t,n);e.add("font-size",`${f.round(r.fontSizePx,2)}px`)}function Ke(e,t,n){const r=t.style??{};ye(e,r,n),e.add("background-color",r.backgroundColor).add("opacity",r.opacity!=null?String(r.opacity):void 0).add("transform",r.rotateDeg?`rotate(${r.rotateDeg}deg)`:void 0)}function Ve(e,t,n,r,o,l){const i=e.cell,a=l.createElement("td");a.className=P("cell",o),a.dataset.mrRowIndex=String(e.ri),a.dataset.mrColumnIndex=String(e.ci),a.setAttribute("role",t.table?.role==="header"?"columnheader":"cell"),i.colSpan&&(a.colSpan=i.colSpan),i.rowSpan&&(a.rowSpan=i.rowSpan);const s=f.mergeComponentStyles(t.style,i.style),c=x("block").add("position","absolute").mm("left",e.xMm,r).mm("top",e.yMm,r).mm("width",e.widthMm,r).mm("height",e.heightMm,r).add("background-color",s.backgroundColor).add("vertical-align",s.verticalAlign??"middle");ye(c,s,r),c.applyTo(a);const d=l.createElement("div");d.className="mr-cell-content",x("flex").add("position","absolute").mm("left",n,r).mm("right",n,r).mm("top",n,r).mm("bottom",n,r).add("flex-direction","column").add("justify-content",s.verticalAlign==="top"?"flex-start":s.verticalAlign==="bottom"?"flex-end":"center").add("overflow-wrap","anywhere").add("overflow","hidden").applyTo(d),i.text!=null&&d.append(i.text);for(const u of i.children??[])d.appendChild(se(u,r,o,l));return a.appendChild(d),a}function Ue(e,t,n,r){return j.resolveGridStrokes(e,t).map(o=>{const l=`${f.round(o.widthPt*n/72,2)}px solid ${o.color}`,i=r.createElement("div");i.className="mr-grid-edge",i.setAttribute("aria-hidden","true");const a=o.kind==="h";return x("block").add("position","absolute").add("pointer-events","none").mm("left",a?o.from:o.pos,n).mm("top",a?o.pos:o.from,n).mm("width",a?o.to-o.from:0,n).mm("height",a?0:o.to-o.from,n).add(a?"border-top":"border-left",l).applyTo(i),i})}function Ge(e,t,n,r,o){const l=o.createElement("table");l.className=P("grid",r),l.setAttribute("role","table"),x("block").add("position","relative").add("width","100%").add("height","100%").applyTo(l);const i=H.resolveGridLayout(e,t.widthMm,t.heightMm),a=o.createElement("tbody");x("contents").applyTo(a),l.appendChild(a);const s=e.cells.map(()=>{const d=o.createElement("tr");return d.className=P("row",r),d.setAttribute("role","row"),x("contents").applyTo(d),a.appendChild(d),d});for(const d of i.cells)s[d.ri].appendChild(Ve(d,t,e.paddingMm??.5,n,r,o));const c=o.createElement("div");return x("block").add("position","relative").add("width","100%").add("height","100%").applyTo(c),c.append(l,...Ue(i,t,n,o)),c}function Ye(e,t,n,r){const o=r.createElement("div");o.className=P("paragraph",n),x("block").add("text-align",e.align).add("line-height",e.lineHeight!=null?String(e.lineHeight):void 0).mm("margin-top",e.spaceBeforeMm??0,t).mm("margin-bottom",e.spaceAfterMm??0,t).mm("text-indent",e.indentMm??0,t).applyTo(o);for(const l of e.segments||[]){const i=r.createElement("span");i.className=P("segment",n),i.textContent=l.kind==="field"?l.field??"":l.text??"";const a=x("inline");if(l.style){const s=l.style;a.add("color",s.color).add("font-family",s.fontFamily).add("font-weight",s.bold!=null?s.bold?"700":"400":void 0).add("font-style",s.italic!=null?s.italic?"italic":"normal":void 0).add("text-decoration",s.underline!=null?s.underline?"underline":"none":void 0),(s.fontSize!=null||s.fontSizePx!=null)&&a.add("font-size",`${f.round(f.resolveFontSize(s,t).fontSizePx,2)}px`)}a.applyTo(i),o.appendChild(i)}return o}function Je(e,t,n,r){if(y.isRichText(e)){const o=r.createElement("div");o.className=P("rich",n),x("block").applyTo(o);for(const l of e.richParagraphs)o.appendChild(Ye(l,t,n,r));return o}if(Array.isArray(e.lines)&&e.lines.length>0){const o=r.createElement("div");o.className=P("lines",n),x("block").applyTo(o);for(const l of e.lines){const i=r.createElement("div");i.className=P("line",n),i.textContent=l,x("block").add("white-space","pre").add("min-height","1lh").applyTo(i),o.appendChild(i)}return o}return e.text??""}function Xe(e,t,n,r){const o=r.createElement("div");o.className=P("text",n);const l=e.style||{};return x("flex").add("width","100%").add("height","100%").add("flex-direction","column").add("justify-content",l.verticalAlign==="middle"?"center":l.verticalAlign==="bottom"?"flex-end":"flex-start").add("overflow-wrap","anywhere").add("overflow","hidden").applyTo(o),o.append(Je(e,t,n,r)),o}function Ze(e,t,n){const r=n.createElement("img");return r.className=P("image",t),r.src=e.imageData,x("block").add("width","100%").add("height","100%").add("object-fit","contain").applyTo(r),r.alt=e.kind,r}function ge(e,t,n,r){const o=r.createElement("div");o.className=P("shape",n);const l=e.style||{},i=f.resolveStroke(l),a=f.resolveBoxBorders(l),s=`${f.round(i.widthPt*t/72,2)}px solid ${i.color}`,c=x("block");return e.grid?c.add("position","relative"):e.kind==="rect"?(a.top&&c.add("border-top",s),a.right&&c.add("border-right",s),a.bottom&&c.add("border-bottom",s),a.left&&c.add("border-left",s)):e.kind==="ellipse"?(a.inner&&c.add("border",s).add("border-radius","50%"),l.backgroundColor&&c.add("background-color",l.backgroundColor)):e.kind==="line"&&c.add("height","0").add("border-top",s),c.add("box-sizing","border-box").add("width","100%").add("height","100%"),c.applyTo(o),o}function Qe(e,t,n){const r=n.createElementNS("http://www.w3.org/2000/svg","svg"),o=f.mmToPx(e.widthMm,t),l=f.mmToPx(e.heightMm,t);r.setAttribute("width",String(Math.max(1,o))),r.setAttribute("height",String(Math.max(1,l))),r.setAttribute("aria-hidden","true"),r.style.overflow="visible",r.style.display="block";const i=n.createElementNS("http://www.w3.org/2000/svg","line");i.setAttribute("x1","0"),i.setAttribute("x2",String(o)),i.setAttribute("y1",e.lineDirection==="up"?String(l):"0"),i.setAttribute("y2",e.lineDirection==="up"?"0":String(l));const a=f.resolveStroke({...e.style,borderColor:e.style?.lineColor??e.style?.borderColor});return i.setAttribute("stroke",a.color),i.setAttribute("stroke-width",String(a.widthPt*t/72)),r.appendChild(i),r}function se(e,t,n,r){const o=r.createElement("div");o.className=`${P("comp",n)} mr-kind-${e.kind}`;const l=x("block").add("position","absolute").mm("left",e.leftMm,t).mm("top",e.topMm,t).mm("width",e.widthMm,t).mm("height",e.heightMm,t).add("box-sizing","border-box");if(Ke(l,e,t),l.applyTo(o),y.isImageBackedComponent(e))return o.appendChild(Ze(e,n,r)),o;if(e.kind==="text")return o.appendChild(Xe(e,t,n,r)),o;if(e.grid){const a=ge(e,t,n,r);return a.appendChild(Ge(e.grid,e,t,n,r)),o.appendChild(a),o}if(e.kind==="line"&&e.lineDirection)return o.appendChild(Qe(e,t,r)),o;if(e.kind==="line"||e.kind==="rect"||e.kind==="ellipse")return o.appendChild(ge(e,t,n,r)),o;const i=r.createElement("div");return i.className=P("unknown",n),x("block").applyTo(i),i.textContent=e.fallbackText??`[${e.kind}]`,i.dataset.mrUnsupported=e.kind,i.setAttribute("role","note"),o.appendChild(i),o}function Me(e,t,n,r){const o=r.createElement("div");return o.className=P("page",n),x("block","initial").add("position","relative").add("font-family",y.DEFAULT_FONT_FAMILY).add("font-size",`${f.round(f.resolveFontSize(void 0,t).fontSizePx,2)}px`).add("line-height",String(f.resolveLineHeight(void 0))).add("white-space","pre-wrap").add("direction","ltr").mm("width",e.pageWidthMm,t).mm("height",e.pageHeightMm,t).add("background-color","#fff").add("color",y.DEFAULT_TEXT_COLOR).add("overflow","hidden").add("box-sizing","border-box").applyTo(o),e.components.forEach((l,i)=>{const a=se(l,t,n,r);a.dataset.mrComponentIndex=String(i),o.appendChild(a)}),o}function et(e,t,n={}){const r=n.dpi??96;D.reportOutputDiagnostics(e,"dom",n);const o=t.createElement("div");return o.className=P("root",n),x("block").applyTo(o),o.dataset.schemaVersion=e.schemaVersion,e.pages.forEach(l=>{o.appendChild(Me(l,r,n,t))}),o}function F(e){if(e?.aborted)throw e.reason??new DOMException("The operation was aborted.","AbortError")}const tt=(e,t)=>(F(t),/^data:image\/(?:png|jpe?g|webp|gif|svg\+xml)[;,]/i.test(e)?new Promise((n,r)=>{const o=new Image,l=()=>{o.onload=null,o.onerror=null,t?.removeEventListener("abort",i)},i=()=>{l(),o.src="",r(t?.reason??new DOMException("The operation was aborted.","AbortError"))};o.onload=()=>{l(),n(o)},o.onerror=()=>{l(),r(new Error("Image could not be decoded for Canvas output."))},t?.addEventListener("abort",i,{once:!0}),o.src=e}):Promise.reject(new TypeError("Canvas imageData must be an image data URL; provide imageLoader for other sources.")));function nt(e,t,n){return F(n),n?new Promise((r,o)=>{const l=()=>o(n.reason??new DOMException("The operation was aborted.","AbortError"));n.addEventListener("abort",l,{once:!0}),Promise.resolve().then(()=>e(t,n)).then(r,o).finally(()=>n.removeEventListener("abort",l))}):e(t)}async function rt(e,t,n){const r=new Map;for(const o of e.components)!y.isImageBackedComponent(o)||r.has(o.imageData)||r.set(o.imageData,await nt(t,o.imageData,n));return F(n),r}function ot(e,t,n,r,o,l){const i=t,a=i.naturalWidth??i.width??o,s=i.naturalHeight??i.height??l;if(a<=0||s<=0)throw new RangeError("Decoded Canvas image dimensions must be positive.");const c=Math.min(o/a,l/s),d=a*c,u=s*c;e.drawImage(t,n+(o-d)/2,r+(l-u)/2,d,u)}function Te(e){return je.createPageWindowIndex(e.pageHeightsPx,e.gapPx).window(e.viewportHeightPx,e.scrollTopPx,e.overscan)}const le=96/25.4;function Q(e,t=96){const n=t/96*le;return{widthPx:Math.max(1,Math.round(e.pageWidthMm*n)),heightPx:Math.max(1,Math.round(e.pageHeightMm*n))}}function xe(e,t,n,r=64e6){if(!Number.isFinite(t)||t<=0||!Number.isFinite(n)||n<=0)throw new RangeError("Canvas dpr and dpi must be positive finite numbers.");if(!Number.isFinite(r)||r<=0)throw new RangeError("maxCanvasPixels must be positive and finite.");const o=Q(e,n),l=Math.round(o.widthPx*t),i=Math.round(o.heightPx*t);if(!Number.isSafeInteger(l)||!Number.isSafeInteger(i)||l*i>r)throw new RangeError("Canvas page exceeds maxCanvasPixels; reduce resolution or split the report.");return{width:l,height:i}}function Ee(e,t,n,r){const o=document.createElement("canvas"),{widthPx:l,heightPx:i}=Q(e,n),a=xe(e,t,n,r);o.width=a.width,o.height=a.height,o.style.width=`${l}px`,o.style.height=`${i}px`;const s=o.getContext("2d");if(!s)throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");return s.scale(t,t),s.fillStyle="#ffffff",s.fillRect(0,0,l,i),{canvas:o,ctx:s}}function it(e,t=96){return f.resolveFontSize(e,t).fontSizePx}function Se(e,t,n,r,o,l,i,a="top"){e.font=`${t.italic?"italic ":""}${t.bold?"bold ":""}${t.fontSizePx}px ${i}`,"letterSpacing"in e&&(e.letterSpacing="0px"),e.fillStyle=t.color,e.textBaseline="alphabetic";const s=t.fontSizePx*t.lineHeight,c=t.text===""?[""]:t.text.split(`
2
+ `),d=c.length*s;let u=r;a==="middle"?u=r+(l-d)/2:a==="bottom"&&(u=r+l-d),c.forEach((m,h)=>{at(e,m,t,n,u+h*s+t.fontSizePx*.8,o)}),e.textAlign="left"}function at(e,t,n,r,o,l){const i=Array.from(t),a=n.letterSpacingPx??0;if(!a){e.textAlign=n.align==="center"?"center":n.align==="right"?"right":"left";const u=n.align==="center"?r+l/2:n.align==="right"?r+l:r;e.fillText(t,u,o);return}const s=e.measureText(t).width+Math.max(0,i.length-1)*a,c=n.align==="center"?r+(l-s)/2:n.align==="right"?r+l-s:r;e.textAlign="left";let d="";i.forEach((u,m)=>{e.fillText(u,c+e.measureText(d).width+m*a,o),d+=u})}function st(e,t,n,r,o,l,i){for(const a of j.resolveGridStrokes(t,n))e.strokeStyle=a.color,e.lineWidth=f.ptToPx(a.widthPt,i),e.beginPath(),a.kind==="v"?(e.moveTo(r+a.pos*l,o+a.from*l),e.lineTo(r+a.pos*l,o+a.to*l)):(e.moveTo(r+a.from*l,o+a.pos*l),e.lineTo(r+a.to*l,o+a.pos*l)),e.stroke()}function lt(e,t,n,r,o,l){e.beginPath(),t.top&&(e.moveTo(n,r),e.lineTo(n+o,r)),t.right&&(e.moveTo(n+o,r),e.lineTo(n+o,r+l)),t.bottom&&(e.moveTo(n+o,r+l),e.lineTo(n,r+l)),t.left&&(e.moveTo(n,r+l),e.lineTo(n,r)),e.stroke()}function ct(e,t,n,r,o,l,i,a,s,c,d){const u=H.resolveGridLayout(t,l/a,i/a);for(const h of u.cells){const g=h.cell.style?.backgroundColor??n.style?.backgroundColor;g&&(e.fillStyle=g,e.fillRect(r+h.xMm*a,o+h.yMm*a,h.widthMm*a,h.heightMm*a))}st(e,u,n,r,o,a,s);const m=t.paddingMm??.5;for(const h of u.cells){const g=h.cell.text??"";if(!g)continue;const p=f.mergeComponentStyles(n.style,h.cell.style),b=f.resolveFontSize(p,s),E=Math.max(0,h.widthMm-2*m),S=$.wrapText(g,E,{fontSizePt:b.fontSizePt,bold:p.bold,italic:p.italic,fontFamily:p.fontFamily??c,letterSpacingPt:p.letterSpacing},d).join(`
3
+ `);Se(e,{text:S,fontSizePx:b.fontSizePx,bold:p.bold??!1,italic:p.italic,color:f.resolveTextColor(p,y.DEFAULT_TEXT_COLOR),align:p.align??"left",lineHeight:f.resolveLineHeight(p),letterSpacingPx:f.ptToPx(p.letterSpacing??0,s)},r+(h.xMm+m)*a,o+(h.yMm+m)*a,E*a,Math.max(0,h.heightMm-2*m)*a,p.fontFamily??c,p.verticalAlign??"middle")}}function dt(e,t,n,r,o,l,i,a,s){const c=t.style??{},d=f.resolveFontSize(c,i),u=y.isRichText(t)?t.richParagraphs.map(m=>m.segments.map(h=>h.text??h.field??"").join("")).join(`
4
4
  `):t.lines?.length?t.lines.join(`
5
- `):O.wrapText(t.text??"",t.widthMm,{fontSizePt:c.fontSizePt,bold:d.bold,italic:d.italic,fontFamily:d.fontFamily??a,letterSpacingPt:d.letterSpacing},s).join(`
6
- `);xe(e,{text:u,fontSizePx:c.fontSizePx,bold:d.bold??!1,italic:d.italic,color:m.resolveTextColor(d),align:d.align??"left",lineHeight:m.resolveLineHeight(d),letterSpacingPx:m.ptToPx(d.letterSpacing??0,i)},r,n,o,l,d.fontFamily??a,d.verticalAlign)}function se(e,t,r,n,o,l,i){const a=t.leftMm*r,s=t.topMm*r,d=t.widthMm*r,c=t.heightMm*r,u=t.style??{};if(b.isImageBackedComponent(t)){const f=i?.get(t.imageData);f?et(e,f,a,s,d,c):ge(e,t,a,s,d,c);return}if(t.grid){it(e,t.grid,t,a,s,d,c,r,n,o,l);return}switch(t.kind){case"text":{at(e,t,a,s,d,c,n,o,l);break}case"rect":{const f=m.resolveStroke(u),h=m.resolveBoxBorders(u);u.backgroundColor&&(e.fillStyle=u.backgroundColor,e.fillRect(a,s,d,c)),h.inner&&(e.strokeStyle=f.color,e.lineWidth=m.ptToPx(f.widthPt,n),ot(e,h,a,s,d,c));break}case"line":{const f=m.resolveStroke({...u,borderColor:u.lineColor??u.borderColor});e.strokeStyle=f.color,e.lineWidth=m.ptToPx(f.widthPt,n),e.beginPath();const h=t.lineDirection==="up"?s+c:t.lineDirection==="down"?s:s+c/2,p=t.lineDirection==="up"?s:t.lineDirection==="down"?s+c:s+c/2;e.moveTo(a,h),e.lineTo(a+d,p),e.stroke();break}case"ellipse":{const f=m.resolveStroke(u);e.strokeStyle=f.color,e.lineWidth=m.ptToPx(f.widthPt,n),u.backgroundColor&&(e.fillStyle=u.backgroundColor,e.beginPath(),e.ellipse(a+d/2,s+c/2,d/2,c/2,0,0,Math.PI*2),e.fill()),e.beginPath(),e.ellipse(a+d/2,s+c/2,d/2,c/2,0,0,Math.PI*2),e.stroke();break}default:ge(e,t,a,s,d,c);break}}function ge(e,t,r,n,o,l){e.save(),e.strokeStyle="#94a3b8",e.strokeRect(r,n,o,l),e.fillStyle="#64748b",e.font="12px sans-serif",e.fillText(t.fallbackText??`[${t.kind}]`,r+3,n+14),e.restore()}async function st(e,t={}){if(typeof document>"u")throw new Error("renderPlanToImages 需要浏览器环境(SSR/Node 请在客户端钩子中调用)");const{format:r="png",quality:n=.92,...o}=t;if(r!=="png"&&r!=="jpeg")throw new TypeError("Image format must be png or jpeg.");if(!Number.isFinite(n)||n<0||n>1)throw new RangeError("Image quality must be between 0 and 1.");$(t.signal);const l=await z.resolvePlanAssets(e,{...t,format:"canvas"});e=l.plan;const i=[...l.diagnostics,...H.reportOutputDiagnostics(e,"canvas",t)],a=r==="jpeg"?"image/jpeg":"image/png",s=[],d=Math.min(e.pages.length-1,t.end??e.pages.length-1);for(let c=Math.max(0,t.start??0);c<=d;c++){$(t.signal);const u=await Se(e.pages[c],c,o,i);try{s.push(await lt(u,a,n,t.signal))}finally{u.width=0,u.height=0}}return $(t.signal),{blobs:s,diagnostics:i}}function lt(e,t,r,n){return $(n),new Promise((o,l)=>{const i=()=>l(n?.reason??new DOMException("The operation was aborted.","AbortError"));n?.addEventListener("abort",i,{once:!0});try{e.toBlob(a=>{n?.removeEventListener("abort",i),a?o(a):l(new Error("Canvas encoding failed; no empty image was emitted."))},t,r)}catch(a){n?.removeEventListener("abort",i),l(a)}})}function dt(e,t={}){if(typeof document>"u")throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");const r=t.dpr??(typeof devicePixelRatio=="number"?devicePixelRatio:1),n=t.dpi??96,o=n/96*ae,l=t.fontFamily??b.DEFAULT_FONT_FAMILY,i=t.measurer??O.heuristicMeasurer,a=Math.max(0,t.start??0),s=Math.min(e.pages.length-1,t.end??e.pages.length-1),d=[],c=H.reportOutputDiagnostics(e,"canvas",t);for(let u=a;u<=s;u++){const f=e.pages[u],{canvas:h,ctx:p}=Ee(f,r,n,t.maxCanvasPixels);for(const g of f.components){if(b.isImageBackedComponent(g)){const v={code:"async-image-required",severity:"warning",format:"canvas",pageIndex:u,componentIndex:f.components.indexOf(g),kind:g.kind,nid:g.nid,message:"Use renderPlanToCanvasAsync or renderPlanToImages to decode and include images."};c.push(v),t.onDiagnostic?.(v)}se(p,g,o,n,l,i)}d.push(h)}return{canvases:d,diagnostics:c}}async function ct(e,t={}){if(typeof document>"u")throw new Error("renderPlanToCanvasAsync 需要浏览器环境(Node 请使用 PDF 或 XLSX 输出)");$(t.signal);const r=await z.resolvePlanAssets(e,{...t,format:"canvas"});e=r.plan;const n=[...r.diagnostics,...H.reportOutputDiagnostics(e,"canvas",t)],o=[],l=Math.min(e.pages.length-1,t.end??e.pages.length-1);for(let i=Math.max(0,t.start??0);i<=l;i++)o.push(await Se(e.pages[i],i,t,n));return{canvases:o,diagnostics:n}}async function Se(e,t,r,n){const o=r.dpr??(typeof devicePixelRatio=="number"?devicePixelRatio:1),l=r.dpi??96,i=r.fontFamily??b.DEFAULT_FONT_FAMILY,a=await Pe(e,t,r,n);$(r.signal);const{canvas:s,ctx:d}=Ee(e,o,l,r.maxCanvasPixels);for(const c of e.components)se(d,c,l/25.4,l,i,r.measurer??O.heuristicMeasurer,a);return s}async function Pe(e,t,r,n){const o=r.imageLoader??Xe;return Qe(e,async(l,i)=>{try{return await o(l,i)}catch(a){if(i?.aborted)throw a;const s=e.components.findIndex(u=>u.imageData===l),d=e.components[s],c={code:"image-decode-failed",severity:"warning",format:"canvas",pageIndex:t,componentIndex:s,kind:d.kind,nid:d.nid,message:"Image decoding failed; raster output was cancelled instead of omitting the image."};throw n.push(c),r.onDiagnostic?.(c),a}},r.signal)}function ut(e,t={}){const r=t.dpr??(typeof devicePixelRatio=="number"?devicePixelRatio:1),n=t.dpi??96,o=n/96*ae,l=t.fontFamily??b.DEFAULT_FONT_FAMILY,i=t.measurer??O.heuristicMeasurer,a=t.overscan??1,s=t.gapPx??18,d=t.pagesPerFrame??1,c=e.pages.map(w=>w.pageHeightMm*o),u=Math.max(1,...e.pages.map(w=>w.pageWidthMm*o)),f={start:0,end:-1};let h=null,p=null,g=null,v=null,E=[],x=0,k=[],G=0,K=new AbortController;const ue=[];function Oe(){const w=h;w.innerHTML="",p=document.createElement("div"),p.style.cssText=`width:${u}px;margin:0 auto;`,g=document.createElement("div"),v=document.createElement("div"),p.appendChild(g),E=[];const S=Math.min(e.pages.length,3+a*2);for(let _=0;_<S;_++){const y=document.createElement("div");y.style.cssText=`margin:0 auto ${s}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`,p.appendChild(y),E.push(y)}p.appendChild(v),w.appendChild(p)}async function Ne(w,S){const _=G,y=await z.resolvePlanAssets(e,{...t,signal:K.signal,format:"canvas",start:S,end:S});ue.push(...y.diagnostics);const C=y.plan.pages[S],J=await Pe(C,S,{...t,signal:K.signal},ue);if(_!==G||!h)return;const{widthPx:ne,heightPx:oe}=Z(C,n);let N=w.firstElementChild;(!N||N.tagName!=="CANVAS")&&(N=document.createElement("canvas"),w.innerHTML="",w.appendChild(N));const fe=Te(C,r,n,t.maxCanvasPixels);N.width=fe.width,N.height=fe.height,N.style.width=`${ne}px`,N.style.height=`${oe}px`;const B=N.getContext("2d");if(B){B.setTransform(1,0,0,1,0,0),B.scale(r,r),B.fillStyle="#ffffff",B.fillRect(0,0,ne,oe);for(const $e of C.components)se(B,$e,o,n,l,i,J);N.dataset.canvasPage=String(S),w.style.height=`${oe}px`,w.style.width=`${ne}px`}}function De(w){G++,f.start=w.start,f.end=w.end,g.style.height=`${w.start*s+c.slice(0,w.start).reduce((y,C)=>y+C,0)}px`;const S=e.pages.length-1-w.end;v.style.height=`${S*s+c.slice(w.end+1).reduce((y,C)=>y+C,0)}px`;const _=w.end-w.start+1;E.forEach((y,C)=>{if(C<_){y.style.display="";const J=w.start+C;y.style.height=`${c[J]??0}px`}else y.style.display="none"}),k=[];for(let y=w.start;y<=w.end;y++){const C=E[y-w.start];if(!C)continue;C.firstElementChild?.dataset?.canvasPage!==String(y)&&k.push(y)}re()}function re(){x||k.length===0||(x=requestAnimationFrame(()=>{x=0;let w=Math.max(1,d);for(;k.length>0&&w-- >0;){const S=k.shift(),_=E[S-f.start];_&&Ne(_,S).catch(()=>{})}k.length>0&&re()}))}function U(){x||(x=requestAnimationFrame(()=>{x=0;const w=h,S=Me({pageHeightsPx:c,viewportHeightPx:w.clientHeight,scrollTopPx:w.scrollTop,overscan:a,gapPx:s});S.start!==f.start||S.end!==f.end?De(S):re()}))}let q=null;return{attach(w){if(typeof document>"u")throw new Error("createCanvasPager 需要浏览器环境(SSR 请在客户端钩子中调用 attach)");$(t.signal),K=new AbortController,t.signal?.addEventListener("abort",me,{once:!0}),H.reportOutputDiagnostics(e,"canvas",t),h=w,Oe(),w.addEventListener("scroll",U,{passive:!0}),typeof ResizeObserver<"u"&&(q=new ResizeObserver(()=>U()),q.observe(w)),U()},destroy(){G++,K.abort(),t.signal?.removeEventListener("abort",me),x&&cancelAnimationFrame(x),x=0,q?.disconnect(),q=null,h?.removeEventListener("scroll",U),k=[],p?.remove(),h=null},window(){return{...f}}};function me(){K.abort(t.signal?.reason)}}function le(e,t,r){let n,o;if(typeof e=="string"){const l=m.PAPER_SIZES[e];if(!l)throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(m.PAPER_SIZES).join("/")})`);n=l.widthMm,o=l.heightMm}else typeof e=="number"?(n=e,o=t??297):(n=e.widthMm,o=e.heightMm);return r?{widthMm:o,heightMm:n}:{widthMm:n,heightMm:o}}class Ce{constructor(){this.pages=[],this.pending=null,this.templateParams=void 0}params(t){return this.templateParams=t,this}page(t="a4",r={},n){this.collect();const l=n!=null&&!("margins"in n)&&!("landscape"in n)&&("marginTopMm"in n||"marginBottomMm"in n||"marginLeftMm"in n||"marginRightMm"in n)?{margins:n}:typeof r=="number"?n??{}:r,{widthMm:i,heightMm:a}=le(t,typeof r=="number"?r:void 0,l.landscape),s=l.margins??{};return this.pending=new Re(this,{widthMm:i,heightMm:a,marginTopMm:s.marginTopMm??10,marginBottomMm:s.marginBottomMm??10,marginLeftMm:s.marginLeftMm??10,marginRightMm:s.marginRightMm??10}),this.pending}collect(){this.pending&&(this.pages.push(this.pending.buildPage()),this.pending=null)}build(){if(this.collect(),this.pages.length===0)throw new Error("模板至少需要一页:先调用 .page() 添加内容");return this.templateParams?{params:this.templateParams,pages:this.pages}:{pages:this.pages}}}class Re{constructor(t,r){this.parent=t,this.page=r,this.components=[]}text(t,r={},n={}){return this.components.push({kind:"text",leftMm:r.leftMm??0,topMm:r.topMm??0,widthMm:r.widthMm??60,heightMm:r.heightMm??8,text:t,style:n}),this}list(t,r,n,o={}){return this.components.push({kind:"list",leftMm:r.leftMm??10,topMm:r.topMm??30,widthMm:r.widthMm??180,dataset:t,columns:n,...o}),this}rect(t,r={}){return this.components.push({kind:"rect",...t,style:r}),this}line(t,r,n,o={}){return this.components.push({kind:"line",leftMm:t,topMm:r,widthMm:n,heightMm:.5,style:o}),this}barcode(t,r){return this.components.push({kind:"barcode",leftMm:r.leftMm??0,topMm:r.topMm??0,widthMm:r.widthMm??40,heightMm:r.heightMm??12,fallbackText:t}),this}qrcode(t,r,n,o){return this.components.push({kind:"qrcode",leftMm:n,topMm:o,widthMm:r,heightMm:r,fallbackText:t}),this}buildPage(){return{...this.page,components:this.components}}done(){return this.parent}build(){return this.done().build()}}function mt(){return new Ce}function ft(e,t={}){return I.validateDatasetRows([],e),e.fields.map(r=>({field:r.field,header:`${r.label??r.field}${r.unit?` (${r.unit})`:""}`,semanticRole:r.semanticRole??(r.type==="number"||r.type==="decimal"?"measure":r.type==="date"?"date":r.enum?"dimension":"text"),...t[r.field]}))}function A(e,t,r=!1){if(!Number.isFinite(e)||(r?e<0:e<=0))throw new Error(`${t} 必须是有限${r?"非负":"正"}数`)}function Y(e,t,r){if(e!==void 0&&!["left","center","right","justify",...r?["auto"]:[]].includes(e))throw new Error(`${t} 必须是 left/center/right/justify${r?"/auto":""}`)}function ht(e){const t=e.layout??"page";if(t!=="page"&&t!=="wide")throw new Error("layout 必须是 page 或 wide");if(t==="wide"&&(e.paper!==void 0||e.landscape!==void 0))throw new Error('宽表布局不能同时指定 paper 或 landscape;标准纸型请使用 layout: "page"');if(t!=="wide"&&e.columnWidthMm!==void 0)throw new Error('columnWidthMm 仅适用于 layout: "wide"');const r=e.columnWidthMm??30;return A(r,"columnWidthMm"),{layout:t,columnWidthMm:r}}function gt(e){const t=e.paper===void 0?"a4":e.paper;if(typeof t!="string"&&(typeof t!="object"||t===null)||e.landscape!==void 0&&typeof e.landscape!="boolean")throw new Error("paper 必须是纸张预设名或 { widthMm, heightMm } 对象,landscape 必须是布尔值");if(typeof t=="string"&&!Object.prototype.hasOwnProperty.call(m.PAPER_SIZES,t))throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(m.PAPER_SIZES).join("/")})`);const r=le(t,void 0,e.landscape),n=r.widthMm,o=r.heightMm;return A(n,"纸张 widthMm"),A(o,"纸张 heightMm"),{widthMm:n,heightMm:o}}function pt(e){if(e.margins!==void 0&&(!e.margins||typeof e.margins!="object"||Array.isArray(e.margins)))throw new Error("margins 必须是页边距对象");const t=e.margins??{},r={marginTopMm:t.marginTopMm===void 0?10:t.marginTopMm,marginBottomMm:t.marginBottomMm===void 0?10:t.marginBottomMm,marginLeftMm:t.marginLeftMm===void 0?10:t.marginLeftMm,marginRightMm:t.marginRightMm===void 0?10:t.marginRightMm};for(const[n,o]of Object.entries(r))A(o,n,!0);return r}function wt(e,t){const r=e.dataset===void 0?"detail":e.dataset;if(typeof r!="string"||!r.trim())throw new Error("dataset 必须是非空字符串");if(e.title!==void 0&&typeof e.title!="string")throw new Error("title 必须是字符串");const n=e.titleHeightMm===void 0?10:e.titleHeightMm,o=e.titleGapMm===void 0?4:e.titleGapMm;A(n,"titleHeightMm"),A(o,"titleGapMm",!0);const l=e.title!==void 0&&e.title.length>0,i=l?n+o:0;if(i>=t)throw new Error("标题高度与间距占满页面,必须为表格保留可用高度");return{dataset:r,titleHeightMm:n,hasTitle:l,titleSpaceMm:i}}function vt(e){if(e.listOptions!==void 0&&(!e.listOptions||typeof e.listOptions!="object"||Array.isArray(e.listOptions)))throw new Error("listOptions 必须是列表配置对象");const t=e.listOptions??{};Y(t.align,"listOptions.align",!0),Y(t.headerAlign,"listOptions.headerAlign",!1);for(const r of["fontSizePt","rowHeightMm","paddingMm"]){const n=t[r];n!==void 0&&A(n,`listOptions.${r}`,r==="paddingMm")}return t}function bt(e){let t=0,r=0;for(const[n,o]of e.entries()){if(!o||typeof o.header!="string"||typeof o.field!="string"||!o.field.trim())throw new Error(`columns[${n}] 需要字符串 header 与非空 field`);Y(o.align,`columns[${n}].align`,!0),Y(o.headerAlign,`columns[${n}].headerAlign`,!1),o.flex!==void 0&&A(o.flex,`columns[${n}].flex`),o.widthMm!==void 0?(A(o.widthMm,`columns[${n}].widthMm`),t+=o.widthMm):r=Math.max(r,o.flex??1)}return{fixedWidthMm:t,maxFlex:r}}function yt(e,t,r,n){const{fixedWidthMm:o,maxFlex:l}=bt(e.columns);if(t==="page"&&o>n)throw new Error(`固定列宽 ${o}mm 超出页面可用宽度 ${n}mm`);const i=n-o;if(t==="page"&&l>0&&i<=0)throw new Error("固定列占满页面可用宽度,自动列需要正的剩余宽度");const a=l>0?e.columns.reduce((d,c)=>d+(c.widthMm===void 0?(c.flex??1)/l:0),0):0;return{columns:e.columns.map(({widthMm:d,flex:c,...u},f)=>{const h=d??(t==="wide"?r*(c??1):i*((c??1)/l)/a);return A(h,`columns[${f}] 分配后的 widthMm`),{...u,widthMm:h}}),fixedWidthMm:o,maxFlex:l}}function Mt(e){if(!e||typeof e!="object")throw new Error("标准明细模板需要 options 对象");if(!Array.isArray(e.columns)||e.columns.length===0)throw new Error("columns 至少需要一列");const{layout:t,columnWidthMm:r}=ht(e),n=gt(e);let o=n.widthMm;const l=n.heightMm,i=pt(e);let a=o-i.marginLeftMm-i.marginRightMm;const s=l-i.marginTopMm-i.marginBottomMm;if(t==="page"&&a<=0||s<=0)throw new Error("页边距占满纸张,必须保留正的可用宽度和高度");const{dataset:d,titleHeightMm:c,hasTitle:u,titleSpaceMm:f}=wt(e,s),h=vt(e),{columns:p,fixedWidthMm:g,maxFlex:v}=yt(e,t,r,a);t==="wide"&&(a=p.reduce((x,k)=>x+k.widthMm,0),A(a,"宽表总列宽"),o=a+i.marginLeftMm+i.marginRightMm,A(o,"宽表总宽度"));const E={widthMm:o,heightMm:l,...i,components:[],...t==="wide"?{layout:t}:{}};return u&&E.components.push({kind:"text",text:e.title,leftMm:i.marginLeftMm,topMm:i.marginTopMm,widthMm:a,heightMm:c,style:{fontSize:16,bold:!0,align:"center",verticalAlign:"middle",...e.titleStyle}}),E.components.push({align:"auto",headerAlign:"center",...h,kind:"list",...t==="wide"?{layout:t}:{},...u?{title:e.title}:{},dataset:d,columns:p,leftMm:i.marginLeftMm,topMm:i.marginTopMm+f,widthMm:t==="wide"||v>0?a:g}),e.params===void 0?{pages:[E]}:{params:e.params,pages:[E]}}function Tt(e){return e}class D extends Error{constructor(t,r){super(r),this.code=t,this.name="ReportTemplateStoreError"}}function L(e){return JSON.parse(JSON.stringify(e))}function R(e){if(!e?.aborted)return;const t=new Error("模板操作已取消");throw t.name="AbortError",t}function pe(e){const t=e?Number(e.revision):0;if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new D("history","修订号无效或已达上限");return String(t+1)}function Et(e,t={}){const r=async(i,a)=>{R(a);const s=await e.read(i,a);return R(a),s?L(s):void 0},n=async(i,a)=>{const s=await r(i,a.signal);if((s?.revision??null)!==a.expectedRevision)throw new D("conflict","模板已变化,请重新读取后提交");return s},o=async(i,a,s)=>{if(R(a.signal),!await e.compareAndSwap(i.id,a.expectedRevision,L(i),{signal:a.signal,...s?{publication:L(s)}:{}}))throw new D("conflict","模板已被其他请求更新");return L(i)},l=(i,a,s,d)=>{const c=pe(i),u=F.parseReportTemplate({...a,revision:c}),f={revision:c,document:u,publishedAt:(t.now?.()??new Date).toISOString()};return d!==void 0&&(f.restoredFrom=d),o({id:i.id,revision:c,publishedRevision:c,published:u},s,f)};return{list:async i=>{R(i);const a=await e.list(i);return R(i),L(a)},get:async(i,a={})=>{const s=await r(i,a.signal),d=a.draft?s?.draft:s?.published;return d?F.parseReportTemplate(d):void 0},history:async(i,a)=>{R(a);const s=await e.history(i,a);return R(a),L(s)},saveDraft:async(i,a)=>{R(a.signal);const s=F.parseReportTemplate(t.migrate?await t.migrate(i):i),d=await n(s.id,a),c=pe(d);return o({id:s.id,revision:c,draft:{...s,revision:c},...d?.publishedRevision?{publishedRevision:d.publishedRevision,published:d.published}:{}},a)},publish:async(i,a)=>{const s=await n(i,a);if(!s)throw new D("missing","模板不存在");if(!s.draft)throw new D("draft","没有可发布的草稿");return l(s,s.draft,a)},rollback:async(i,a,s)=>{const d=await n(i,s);if(!d)throw new D("missing","模板不存在");R(s.signal);const c=await e.getVersion(i,a,s.signal);if(!c)throw new D("history","历史修订不存在");return l(d,c.document,s,a)}}}function xt(){const e=new Map,t=new Map;return{read:async(r,n)=>{R(n);const o=e.get(r);return o?L(o):void 0},list:async r=>(R(r),Array.from(e.values(),({id:n,revision:o,publishedRevision:l})=>({id:n,revision:o,...l?{publishedRevision:l}:{}}))),history:async(r,n)=>(R(n),Array.from(t.get(r)?.values()??[],o=>L(o))),getVersion:async(r,n,o)=>{R(o);const l=t.get(r)?.get(n);return l?L(l):void 0},compareAndSwap:async(r,n,o,l)=>{if(R(l.signal),(e.get(r)?.revision??null)!==n)return!1;if(o.id!==r)throw new D("history","状态 ID 与存储 ID 不一致");const i=L(o),a=l.publication;if(a){const s=t.get(r)??new Map;if(s.has(a.revision)||a.revision!==o.revision||a.document.id!==r)throw new D("history","发布修订不可覆盖,且必须与状态修订和模板 ID 一致");s.set(a.revision,L(a)),t.set(r,s)}return e.set(r,i),!0}}}function ke(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function Ie(e,t,r){const n=e.grid;if(!n)return null;const o=n.cells[t];if(!o)return null;const i=j.resolveGridLayout(n,e.widthMm,e.heightMm).cells.filter(s=>s.ri===t).findIndex(s=>s.ci===r),a=o[i];return a?{cell:a,sourceColumnIndex:i}:null}function St(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function Pt(e,t){return e.valueType?e.valueType:typeof t=="number"?"number":typeof t=="boolean"?"boolean":t===null&&e.numberFormat&&/[0#?]/.test(e.numberFormat)?"number":"text"}function Ct(e,t){if(e.editable===!1)return"cell";if(e.formula!==void 0)return"formula";if(e.children?.length)return"complex";if(t.table&&t.table.role!=="body"&&e.editable!==!0)return"structure"}function Rt(e,t){const r=e.table;if(r)return{id:r.id,rowIndex:r.rowIndex+t.rowIndex,role:r.role,columnKey:r.columnKeys[t.columnIndex]}}function kt(e,t,r){if(e.source)return{...e.source};const n=t.table?.source,o=t.table?.columnKeys[r.columnIndex];if(!(!n||n.rowKey===void 0||o===void 0))return{...n,rowKey:n.rowKey,field:o}}function Ae(e,t,r){const n=St(r),o=Ct(r,e);return{address:{...t},cell:r,component:e,value:n,valueType:Pt(r,n),table:Rt(e,t),source:kt(r,e,t),editable:o===void 0,readOnlyReason:o}}function Q(e,t){if(!ke(t))return null;const r=e.pages[t.pageIndex]?.components[t.componentIndex];if(!r)return null;const n=Ie(r,t.rowIndex,t.columnIndex);return n?Ae(r,t,n.cell):null}function ee(e){const t=new Map;return r=>{if(!ke(r))return null;const n=e.pages[r.pageIndex]?.components[r.componentIndex];if(!n?.grid)return null;let o=t.get(n);if(!o){const i=new Map;o=new Map;for(const a of j.resolveGridLayout(n.grid,n.widthMm,n.heightMm).cells){const s=i.get(a.ri)??0;i.set(a.ri,s+1);const d=n.grid.cells[a.ri]?.[s];d&&o.set(`${a.ri}:${a.ci}`,d)}t.set(n,o)}const l=o.get(`${r.rowIndex}:${r.columnIndex}`);return l?Ae(n,r,l):null}}class T extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function It(e,t){let r=e.trim();const n=t&&r.endsWith("%");if(n&&(r=r.slice(0,-1).trim()),/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?(?:[eE][+-]?\d+)?$/.test(r)&&(r=r.replace(/,/g,"")),!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(r))throw new T("number");return Number(r)/(n?100:1)}function At(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new T("number");const r=typeof e=="number"?e:It(e,ve.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(r)||Number.isInteger(r)&&!Number.isSafeInteger(r))throw new T("number");return r}function Lt(e){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e=="boolean")return e;const t=String(e).trim().toLowerCase();if(["true","yes","是","1"].includes(t))return!0;if(["false","no","否","0"].includes(t))return!1;throw new T("boolean")}function de(e,t){return e.valueType==="number"?At(t,e):e.valueType==="boolean"?Lt(t):t===null?null:String(t)}function Ft(e,t){const r=t.cell.text,o=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(l=>l.includes(r??""));return o?o[e?0:1]:String(e)}function V(e,t){return t===null?"":typeof t=="boolean"?Ft(t,e):typeof t=="number"?ve.formatExcelNumber(t,e.cell.numberFormat):String(t)}function Ot(e,t,r){const n=Q(e,t);if(!n)throw new T("missing");return ce(n,r)}function ce(e,t){if(!e.editable)throw new T("readonly");const r=de(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:r,text:V(e,r)}}function Nt(e,t){const r=e.table,n=t.table;return!r||!n||r.columnKey===void 0?!1:r.id===n.id&&r.rowIndex===n.rowIndex&&r.role===n.role&&r.columnKey===n.columnKey}function Le(e,t,r){const n=e.grid,{rowIndex:o,columnIndex:l}=t.address,i=Ie(e,o,l),a=[...n.cells],s=[...a[o]],d=V(t,r.value),c={...i.cell,value:r.value,text:d,rawText:d};return s[i.sourceColumnIndex]=c,a[o]=s,{...e,grid:{...n,cells:a}}}function Dt(e,t){const r=e.table?.columnKeys,n=t.table?.columnKey;return r&&n!==void 0?r.flatMap((o,l)=>o===n?[l]:[]):[]}function $t(e,t,r,n,o,l){const i=t.table,a=o.table;if(!i||!a||i.id!==a.id||i.role!==a.role||!t.grid)return t;const s=a.rowIndex-i.rowIndex;if(s<0||s>=t.grid.cells.length)return t;let d=t;for(const c of Dt(t,o)){const u=Q(e,{pageIndex:r,componentIndex:n,rowIndex:s,columnIndex:c});u?.editable&&Nt(o,u)&&(d=Le(d,u,l))}return d}function _t(e,t,r,n,o,l){const i=o.address;return o.table?.columnKey!==void 0?$t(e,t,r,n,o,l):i.pageIndex===r&&i.componentIndex===n?Le(t,o,l):t}function Fe(e,t){const r=t.source;if(!r)return!1;const n=e.source;return!n||["datasetId","rowKey","field","revision","sourceToken"].some(o=>!Object.is(n[o],r[o]))}function zt(e,t){const r=Q(e,t.address);if(!r)throw new T("missing");if(!r.editable)throw new T("readonly");if(Fe(r,t))throw new T("conflict");if(!Object.is(r.value,t.previousValue)||(r.cell.text??"")!==t.previousText)throw new T("conflict");const n=de(r,t.value),o={...t,value:n,text:V(r,n)};if(Object.is(n,r.value)&&o.text===r.cell.text)return e;const l=e.pages.map((i,a)=>{const s=i.components.map((d,c)=>_t(e,d,a,c,r,o));return s.every((d,c)=>d===i.components[c])?i:{...i,components:s}});return{...e,pages:l}}function Ht(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function we(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):Ht(e.address)}function Bt(e,t){if(!t.length)return e;const r=new Map(t.map(s=>[we(s),s])),n=new Set(t.flatMap(s=>s.table?[s.table.id]:[])),o=new Set(t.map(s=>`${s.address.pageIndex}:${s.address.componentIndex}`)),l=ee(e);function i(s,d,c){const u=s.grid;if(!u||!o.has(`${d}:${c}`)&&!n.has(s.table?.id??""))return s;const f=new Map,h=new Map;for(const p of j.resolveGridLayout(u,s.widthMm,s.heightMm).cells){const g=h.get(p.ri)??0;h.set(p.ri,g+1);const v=l({pageIndex:d,componentIndex:c,rowIndex:p.ri,columnIndex:p.ci}),E=v&&r.get(we(v));if(!E||!v.editable)continue;const x=f.get(p.ri)??[...u.cells[p.ri]],k=V(v,E.value);Object.is(v.value,E.value)&&k===v.cell.text||(x[g]={...p.cell,value:E.value,text:k,rawText:k},f.set(p.ri,x))}return f.size?{...s,grid:{...u,cells:u.cells.map((p,g)=>f.get(g)??p)}}:s}const a=e.pages.map((s,d)=>{const c=s.components.map((u,f)=>i(u,d,f));return c.every((u,f)=>u===s.components[f])?s:{...s,components:c}});return a.every((s,d)=>s===e.pages[d])?e:{...e,pages:a}}function te(e){const t=e.source;if(t)return JSON.stringify([t.datasetId,t.rowKey,t.field]);const r=e.table;if(r?.columnKey!==void 0)return JSON.stringify([r.id,r.role,r.rowIndex,r.columnKey]);const n=e.address;return JSON.stringify([n.pageIndex,n.componentIndex,n.rowIndex,n.columnIndex])}function jt(e,t,r){if(typeof r!="string"||!r.trim()||!Array.isArray(t))throw new T("missing");if(t.length>1e4)throw new T("limit");const n=new Set,o=ee(e),l=t.map(({address:i,value:a})=>{const s=o(i);if(!s)throw new T("missing");const d=ce(s,a),c=te(d);if(n.has(c))throw new T("duplicate");return n.add(c),d});return{requestId:r,edits:l}}function Wt(e,t){if(t.edits.length>1e4)throw new T("limit");const r=ee(e),n=new Set,o=t.edits.map(l=>{const i=r(l.address);if(!i)throw new T("missing");const a=te(l);if(n.has(a))throw new T("duplicate");if(n.add(a),Fe(i,l)||!Object.is(i.value,l.previousValue)||(i.cell.text??"")!==l.previousText)throw new T("conflict");return ce(i,l.value)});return Bt(e,o)}function Kt(e){const t=new Map;for(const r of e){const n=te(r),o=t.get(n),l=o?{...r,previousValue:o.previousValue,previousText:o.previousText}:{...r};Object.is(l.previousValue,l.value)?t.delete(n):t.set(n,l)}return[...t.values()]}function Vt(e){return e.map(t=>t.map(r=>/[\t\r\n"]/.test(r)?`"${r.replace(/"/g,'""')}"`:r).join(" ")).join(`\r
7
- `)}function Gt(e,t){const r=e[e.length-1];e.length>1&&r?.length===1&&r[0]===""&&/[\r\n]$/.test(t)&&e.pop()}function Ut(e,t=1e4){if(e.length>4*1024*1024)throw new Error("Clipboard text limit exceeded");const r=[[]];let n="",o=!1,l=!1,i=0;function a(){if(++i>t)throw new Error("Clipboard cell limit exceeded");r[r.length-1].push(n),n="",l=!1}for(let s=0;s<e.length;s++){const d=e[s];if(o){if(d!=='"'){n+=d;continue}if(e[s+1]==='"'){n+='"',s++;continue}o=!1,l=!0;continue}if(d==='"'&&!n&&!l){o=!0;continue}if(d===" "){a();continue}if(d==="\r"||d===`
8
- `){a(),r.push([]),d==="\r"&&e[s+1]===`
9
- `&&s++;continue}if(l)throw new Error("Invalid quoted clipboard value");n+=d}if(o)throw new Error("Unclosed clipboard quote");return a(),Gt(r,e),r}function qt(e,t,r){if(!r||r.revision===void 0&&r.sourceToken===void 0)return e;const n=new Set(t.edits.flatMap(i=>i.source?[i.source.datasetId]:[]));if(!n.size)return e;function o(i){return!i.datasetId||!n.has(i.datasetId)||(r.revision===void 0||Object.is(r.revision,i.revision))&&(r.sourceToken===void 0||r.sourceToken===i.sourceToken)?i:{...i,...r.revision!==void 0?{revision:r.revision}:{},...r.sourceToken!==void 0?{sourceToken:r.sourceToken}:{}}}const l=e.pages.map(i=>{const a=i.components.map(s=>{const d=s.table?.source?o(s.table.source):void 0,c=s.table&&d!==s.table.source?{...s.table,source:d}:s.table,u=s.grid?.cells.map(h=>{const p=h.map(g=>{if(!g?.source)return g;const v=o(g.source);return v===g.source?g:{...g,source:v}});return p.some((g,v)=>g!==h[v])?p:h}),f=s.grid&&u?.some((h,p)=>h!==s.grid.cells[p])?{...s.grid,cells:u}:s.grid;return c!==s.table||f!==s.grid?{...s,table:c,grid:f}:s});return a.some((s,d)=>s!==i.components[d])?{...i,components:a}:i});return l.some((i,a)=>i!==e.pages[a])?{...e,pages:l}:e}exports.DEFAULT_BORDER_PT=b.DEFAULT_BORDER_PT;exports.DEFAULT_FONT_FAMILY=b.DEFAULT_FONT_FAMILY;exports.DEFAULT_FONT_PT=b.DEFAULT_FONT_PT;exports.DEFAULT_STROKE_COLOR=b.DEFAULT_STROKE_COLOR;exports.DEFAULT_TEXT_COLOR=b.DEFAULT_TEXT_COLOR;exports.LINE_HEIGHT=b.LINE_HEIGHT;exports.RENDER_PLAN_SCHEMA_VERSION=b.RENDER_PLAN_SCHEMA_VERSION;exports.SCHEMA_VERSION_MACH=b.SCHEMA_VERSION_MACH;exports.isImageBackedComponent=b.isImageBackedComponent;exports.isRichText=b.isRichText;exports.PaginatePageLimitError=I.PaginatePageLimitError;exports.ReportSourceError=I.ReportSourceError;exports.createReportSource=I.createReportSource;exports.datasetJsonSchema=I.datasetJsonSchema;exports.defineReport=I.defineReport;exports.evalStyleRule=I.evalStyleRule;exports.formatValue=I.formatValue;exports.paginateTemplate=I.paginateTemplate;exports.parseDateLocal=I.parseDateLocal;exports.toExcelNumberFormat=I.toExcelNumberFormat;exports.toNumber=I.toNumber;exports.validateDatasetRows=I.validateDatasetRows;exports.CSS_DPI=m.CSS_DPI;exports.MM_PER_INCH=m.MM_PER_INCH;exports.PAPER_SIZES=m.PAPER_SIZES;exports.mergeComponentStyles=m.mergeComponentStyles;exports.mmToPx=m.mmToPx;exports.mmToPxFactor=m.mmToPxFactor;exports.ptToPx=m.ptToPx;exports.pxToMm=m.pxToMm;exports.resolveBoxBorders=m.resolveBoxBorders;exports.resolveFontSize=m.resolveFontSize;exports.resolveLineHeight=m.resolveLineHeight;exports.resolveStroke=m.resolveStroke;exports.resolveTextColor=m.resolveTextColor;exports.round=m.round;exports.assertRenderPlan=X.assertRenderPlan;exports.validateComponent=X.validateComponent;exports.validatePage=X.validatePage;exports.validateRenderPlan=X.validateRenderPlan;exports.charWidthEm=O.charWidthEm;exports.createCanvasMeasurer=O.createCanvasMeasurer;exports.createHeuristicMeasurer=O.createHeuristicMeasurer;exports.heuristicMeasurer=O.heuristicMeasurer;exports.measureTextMm=O.measureTextMm;exports.wrapText=O.wrapText;exports.resolveGridLayout=j.resolveGridLayout;exports.OutputAssetError=z.OutputAssetError;exports.resolvePlanAssets=z.resolvePlanAssets;exports.inspectOutputCapabilities=H.inspectOutputCapabilities;exports.reportOutputDiagnostics=H.reportOutputDiagnostics;exports.REPORT_TEMPLATE_DOCUMENT_VERSION=F.REPORT_TEMPLATE_DOCUMENT_VERSION;exports.ReportTemplateError=F.ReportTemplateError;exports.createTemplateRegistry=F.createTemplateRegistry;exports.defineReportTemplate=F.defineReportTemplate;exports.parseReportTemplate=F.parseReportTemplate;exports.serializeReportTemplate=F.serializeReportTemplate;exports.validateReportTemplate=F.validateReportTemplate;exports.validateReportTemplateDocument=F.validateReportTemplateDocument;exports.ReportParamValidationError=W.ReportParamValidationError;exports.assertReportParams=W.assertReportParams;exports.isReportDate=W.isReportDate;exports.reportParamsJsonSchema=W.reportParamsJsonSchema;exports.validateReportParamDefinitions=W.validateReportParamDefinitions;exports.validateReportParams=W.validateReportParams;exports.PageBuilder=Re;exports.ReportCellEditError=T;exports.ReportTemplateStoreError=D;exports.TemplateBuilder=Ce;exports.applyReportCellEdit=zt;exports.applyReportCellEditBatch=Wt;exports.applyReportEditResult=qt;exports.classOf=P;exports.columnsFromContract=ft;exports.computePageWindow=Me;exports.createCanvasPager=ut;exports.createMemoryTemplateStore=xt;exports.createProviderReport=Tt;exports.createReportCellEdit=Ot;exports.createReportCellEditBatch=jt;exports.createReportCellResolver=ee;exports.createTableTemplate=Mt;exports.createTemplate=mt;exports.createTemplateManager=Et;exports.formatReportCellEdit=V;exports.formatReportClipboard=Vt;exports.getReportCellContext=Q;exports.measurePageSizePx=Z;exports.parseReportCellInput=de;exports.parseReportClipboard=Ut;exports.planFontSizePx=tt;exports.renderComponent=ie;exports.renderPage=ye;exports.renderPlan=Ye;exports.renderPlanToCanvas=dt;exports.renderPlanToCanvasAsync=ct;exports.renderPlanToImages=st;exports.reportCellEditKey=te;exports.resolvePaper=le;exports.summarizeReportCellEdits=Kt;
5
+ `):$.wrapText(t.text??"",t.widthMm,{fontSizePt:d.fontSizePt,bold:c.bold,italic:c.italic,fontFamily:c.fontFamily??a,letterSpacingPt:c.letterSpacing},s).join(`
6
+ `);Se(e,{text:u,fontSizePx:d.fontSizePx,bold:c.bold??!1,italic:c.italic,color:f.resolveTextColor(c),align:c.align??"left",lineHeight:f.resolveLineHeight(c),letterSpacingPx:f.ptToPx(c.letterSpacing??0,i)},n,r,o,l,c.fontFamily??a,c.verticalAlign)}function ce(e,t,n,r,o,l,i){const a=t.leftMm*n,s=t.topMm*n,c=t.widthMm*n,d=t.heightMm*n,u=t.style??{};if(y.isImageBackedComponent(t)){const m=i?.get(t.imageData);m?ot(e,m,a,s,c,d):pe(e,t,a,s,c,d);return}if(t.grid){ct(e,t.grid,t,a,s,c,d,n,r,o,l);return}switch(t.kind){case"text":{dt(e,t,a,s,c,d,r,o,l);break}case"rect":{const m=f.resolveStroke(u),h=f.resolveBoxBorders(u);u.backgroundColor&&(e.fillStyle=u.backgroundColor,e.fillRect(a,s,c,d)),h.inner&&(e.strokeStyle=m.color,e.lineWidth=f.ptToPx(m.widthPt,r),lt(e,h,a,s,c,d));break}case"line":{const m=f.resolveStroke({...u,borderColor:u.lineColor??u.borderColor});e.strokeStyle=m.color,e.lineWidth=f.ptToPx(m.widthPt,r),e.beginPath();const h=t.lineDirection==="up"?s+d:t.lineDirection==="down"?s:s+d/2,g=t.lineDirection==="up"?s:t.lineDirection==="down"?s+d:s+d/2;e.moveTo(a,h),e.lineTo(a+c,g),e.stroke();break}case"ellipse":{const m=f.resolveStroke(u);e.strokeStyle=m.color,e.lineWidth=f.ptToPx(m.widthPt,r),u.backgroundColor&&(e.fillStyle=u.backgroundColor,e.beginPath(),e.ellipse(a+c/2,s+d/2,c/2,d/2,0,0,Math.PI*2),e.fill()),e.beginPath(),e.ellipse(a+c/2,s+d/2,c/2,d/2,0,0,Math.PI*2),e.stroke();break}default:pe(e,t,a,s,c,d);break}}function pe(e,t,n,r,o,l){e.save(),e.strokeStyle="#94a3b8",e.strokeRect(n,r,o,l),e.fillStyle="#64748b",e.font="12px sans-serif",e.fillText(t.fallbackText??`[${t.kind}]`,n+3,r+14),e.restore()}async function ut(e,t={}){if(typeof document>"u")throw new Error("renderPlanToImages 需要浏览器环境(SSR/Node 请在客户端钩子中调用)");const{format:n="png",quality:r=.92,...o}=t;if(n!=="png"&&n!=="jpeg")throw new TypeError("Image format must be png or jpeg.");if(!Number.isFinite(r)||r<0||r>1)throw new RangeError("Image quality must be between 0 and 1.");F(t.signal);const l=await j.resolvePlanAssets(e,{...t,format:"canvas"});e=l.plan;const i=[...l.diagnostics,...D.reportOutputDiagnostics(e,"canvas",t)],a=n==="jpeg"?"image/jpeg":"image/png",s=[],c=Math.min(e.pages.length-1,t.end??e.pages.length-1);for(let d=Math.max(0,t.start??0);d<=c;d++){F(t.signal);const u=await Ce(e.pages[d],d,o,i);try{s.push(await mt(u,a,r,t.signal))}finally{u.width=0,u.height=0}await H.outputCheckpoint(t,s.length,c-Math.max(0,t.start??0)+1)}return F(t.signal),{blobs:s,diagnostics:i}}function mt(e,t,n,r){return F(r),new Promise((o,l)=>{const i=()=>l(r?.reason??new DOMException("The operation was aborted.","AbortError"));r?.addEventListener("abort",i,{once:!0});try{e.toBlob(a=>{r?.removeEventListener("abort",i),a?o(a):l(new Error("Canvas encoding failed; no empty image was emitted."))},t,n)}catch(a){r?.removeEventListener("abort",i),l(a)}})}function ft(e,t={}){if(F(t.signal),typeof document>"u")throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");const n=t.dpr??(typeof devicePixelRatio=="number"?devicePixelRatio:1),r=t.dpi??96,o=r/96*le,l=t.fontFamily??y.DEFAULT_FONT_FAMILY,i=t.measurer??$.heuristicMeasurer,a=Math.max(0,t.start??0),s=Math.min(e.pages.length-1,t.end??e.pages.length-1),c=[],d=D.reportOutputDiagnostics(e,"canvas",t),u=ht(e,a,s);for(const m of u)D.notifyOutputDiagnostic(m,t),d.push(m);if(t.fidelity==="strict"&&u.length)throw new D.OutputFidelityError(d);for(let m=a;m<=s;m++){F(t.signal);const h=e.pages[m],{canvas:g,ctx:p}=Ee(h,n,r,t.maxCanvasPixels);for(const b of h.components)ce(p,b,o,r,l,i);c.push(g)}return{canvases:c,diagnostics:d}}function ht(e,t,n){return n<t?[]:e.pages.slice(t,n+1).flatMap((r,o)=>r.components.flatMap((l,i)=>y.isImageBackedComponent(l)?[{code:"async-image-required",severity:"warning",format:"canvas",pageIndex:t+o,componentIndex:i,kind:l.kind,nid:l.nid,message:"Use renderPlanToCanvasAsync or renderPlanToImages to decode and include images."}]:[]))}async function gt(e,t={}){if(typeof document>"u")throw new Error("renderPlanToCanvasAsync 需要浏览器环境(Node 请使用 PDF 或 XLSX 输出)");F(t.signal);const n=await j.resolvePlanAssets(e,{...t,format:"canvas"});e=n.plan;const r=[...n.diagnostics,...D.reportOutputDiagnostics(e,"canvas",t)],o=[],l=Math.min(e.pages.length-1,t.end??e.pages.length-1);for(let i=Math.max(0,t.start??0);i<=l;i++)o.push(await Ce(e.pages[i],i,t,r));return{canvases:o,diagnostics:r}}async function Ce(e,t,n,r){const o=n.dpr??(typeof devicePixelRatio=="number"?devicePixelRatio:1),l=n.dpi??96,i=n.fontFamily??y.DEFAULT_FONT_FAMILY,a=await Pe(e,t,n,r);F(n.signal);const{canvas:s,ctx:c}=Ee(e,o,l,n.maxCanvasPixels);for(const d of e.components)ce(c,d,l/25.4,l,i,n.measurer??$.heuristicMeasurer,a);return s}async function Pe(e,t,n,r){const o=n.imageLoader??tt;return rt(e,async(l,i)=>{try{return await o(l,i)}catch(a){if(i?.aborted)throw a;const s=e.components.findIndex(u=>u.imageData===l),c=e.components[s],d={code:"image-decode-failed",severity:"warning",format:"canvas",pageIndex:t,componentIndex:s,kind:c.kind,nid:c.nid,message:"Image decoding failed; raster output was cancelled instead of omitting the image."};throw r.push(d),D.notifyOutputDiagnostic(d,n),a}},n.signal)}function pt(e,t={}){const n=t.dpr??(typeof devicePixelRatio=="number"?devicePixelRatio:1),r=t.dpi??96,o=r/96*le,l=t.fontFamily??y.DEFAULT_FONT_FAMILY,i=t.measurer??$.heuristicMeasurer,a=t.overscan??1,s=t.gapPx??18,c=t.pagesPerFrame??1,d=e.pages.map(w=>w.pageHeightMm*o),u=Math.max(1,...e.pages.map(w=>w.pageWidthMm*o)),m={start:0,end:-1};let h=null,g=null,p=null,b=null,E=[],S=0,k=[],U=0,K=new AbortController;const me=[];function _e(){const w=h;w.innerHTML="",g=document.createElement("div"),g.style.cssText=`width:${u}px;margin:0 auto;`,p=document.createElement("div"),b=document.createElement("div"),g.appendChild(p),E=[];const C=Math.min(e.pages.length,3+a*2);for(let B=0;B<C;B++){const M=document.createElement("div");M.style.cssText=`margin:0 auto ${s}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`,g.appendChild(M),E.push(M)}g.appendChild(b),w.appendChild(g)}async function ze(w,C){const B=U,M=await j.resolvePlanAssets(e,{...t,signal:K.signal,format:"canvas",start:C,end:C});me.push(...M.diagnostics);const R=M.plan.pages[C],J=await Pe(R,C,{...t,signal:K.signal},me);if(B!==U||!h)return;const{widthPx:ie,heightPx:ae}=Q(R,r);let _=w.firstElementChild;(!_||_.tagName!=="CANVAS")&&(_=document.createElement("canvas"),w.innerHTML="",w.appendChild(_));const he=xe(R,n,r,t.maxCanvasPixels);_.width=he.width,_.height=he.height,_.style.width=`${ie}px`,_.style.height=`${ae}px`;const W=_.getContext("2d");if(W){W.setTransform(1,0,0,1,0,0),W.scale(n,n),W.fillStyle="#ffffff",W.fillRect(0,0,ie,ae);for(const He of R.components)ce(W,He,o,r,l,i,J);_.dataset.canvasPage=String(C),w.style.height=`${ae}px`,w.style.width=`${ie}px`}}function Be(w){U++,m.start=w.start,m.end=w.end,p.style.height=`${w.start*s+d.slice(0,w.start).reduce((M,R)=>M+R,0)}px`;const C=e.pages.length-1-w.end;b.style.height=`${C*s+d.slice(w.end+1).reduce((M,R)=>M+R,0)}px`;const B=w.end-w.start+1;E.forEach((M,R)=>{if(R<B){M.style.display="";const J=w.start+R;M.style.height=`${d[J]??0}px`}else M.style.display="none"}),k=[];for(let M=w.start;M<=w.end;M++){const R=E[M-w.start];if(!R)continue;R.firstElementChild?.dataset?.canvasPage!==String(M)&&k.push(M)}oe()}function oe(){S||k.length===0||(S=requestAnimationFrame(()=>{S=0;let w=Math.max(1,c);for(;k.length>0&&w-- >0;){const C=k.shift(),B=E[C-m.start];B&&ze(B,C).catch(()=>{})}k.length>0&&oe()}))}function G(){S||(S=requestAnimationFrame(()=>{S=0;const w=h,C=Te({pageHeightsPx:d,viewportHeightPx:w.clientHeight,scrollTopPx:w.scrollTop,overscan:a,gapPx:s});C.start!==m.start||C.end!==m.end?Be(C):oe()}))}let Y=null;return{attach(w){if(typeof document>"u")throw new Error("createCanvasPager 需要浏览器环境(SSR 请在客户端钩子中调用 attach)");F(t.signal),K=new AbortController,t.signal?.addEventListener("abort",fe,{once:!0}),D.reportOutputDiagnostics(e,"canvas",t),h=w,_e(),w.addEventListener("scroll",G,{passive:!0}),typeof ResizeObserver<"u"&&(Y=new ResizeObserver(()=>G()),Y.observe(w)),G()},destroy(){U++,K.abort(),t.signal?.removeEventListener("abort",fe),S&&cancelAnimationFrame(S),S=0,Y?.disconnect(),Y=null,h?.removeEventListener("scroll",G),k=[],g?.remove(),h=null},window(){return{...m}}};function fe(){K.abort(t.signal?.reason)}}function de(e,t,n){let r,o;if(typeof e=="string"){const l=f.PAPER_SIZES[e];if(!l)throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(f.PAPER_SIZES).join("/")})`);r=l.widthMm,o=l.heightMm}else typeof e=="number"?(r=e,o=t??297):(r=e.widthMm,o=e.heightMm);return n?{widthMm:o,heightMm:r}:{widthMm:r,heightMm:o}}class Re{constructor(){this.pages=[],this.pending=null,this.templateParams=void 0}params(t){return this.templateParams=t,this}page(t="a4",n={},r){this.collect();const l=r!=null&&!("margins"in r)&&!("landscape"in r)&&("marginTopMm"in r||"marginBottomMm"in r||"marginLeftMm"in r||"marginRightMm"in r)?{margins:r}:typeof n=="number"?r??{}:n,{widthMm:i,heightMm:a}=de(t,typeof n=="number"?n:void 0,l.landscape),s=l.margins??{};return this.pending=new Ie(this,{widthMm:i,heightMm:a,marginTopMm:s.marginTopMm??10,marginBottomMm:s.marginBottomMm??10,marginLeftMm:s.marginLeftMm??10,marginRightMm:s.marginRightMm??10}),this.pending}collect(){this.pending&&(this.pages.push(this.pending.buildPage()),this.pending=null)}build(){if(this.collect(),this.pages.length===0)throw new Error("模板至少需要一页:先调用 .page() 添加内容");return this.templateParams?{params:this.templateParams,pages:this.pages}:{pages:this.pages}}}class Ie{constructor(t,n){this.parent=t,this.page=n,this.components=[]}text(t,n={},r={}){return this.components.push({kind:"text",leftMm:n.leftMm??0,topMm:n.topMm??0,widthMm:n.widthMm??60,heightMm:n.heightMm??8,text:t,style:r}),this}list(t,n,r,o={}){return this.components.push({kind:"list",leftMm:n.leftMm??10,topMm:n.topMm??30,widthMm:n.widthMm??180,dataset:t,columns:r,...o}),this}rect(t,n={}){return this.components.push({kind:"rect",...t,style:n}),this}line(t,n,r,o={}){return this.components.push({kind:"line",leftMm:t,topMm:n,widthMm:r,heightMm:.5,style:o}),this}barcode(t,n){return this.components.push({kind:"barcode",leftMm:n.leftMm??0,topMm:n.topMm??0,widthMm:n.widthMm??40,heightMm:n.heightMm??12,fallbackText:t}),this}qrcode(t,n,r,o){return this.components.push({kind:"qrcode",leftMm:r,topMm:o,widthMm:n,heightMm:n,fallbackText:t}),this}buildPage(){return{...this.page,components:this.components}}done(){return this.parent}build(){return this.done().build()}}function wt(){return new Re}function vt(e,t={}){return A.validateDatasetRows([],e),e.fields.map(n=>({field:n.field,header:`${n.label??n.field}${n.unit?` (${n.unit})`:""}`,semanticRole:n.semanticRole??(n.type==="number"||n.type==="decimal"?"measure":n.type==="date"?"date":n.enum?"dimension":"text"),...t[n.field]}))}function L(e,t,n=!1){if(!Number.isFinite(e)||(n?e<0:e<=0))throw new Error(`${t} 必须是有限${n?"非负":"正"}数`)}function X(e,t,n){if(e!==void 0&&!["left","center","right","justify",...n?["auto"]:[]].includes(e))throw new Error(`${t} 必须是 left/center/right/justify${n?"/auto":""}`)}function bt(e){const t=e.layout??"page";if(t!=="page"&&t!=="wide")throw new Error("layout 必须是 page 或 wide");if(t==="wide"&&(e.paper!==void 0||e.landscape!==void 0))throw new Error('宽表布局不能同时指定 paper 或 landscape;标准纸型请使用 layout: "page"');if(t!=="wide"&&e.columnWidthMm!==void 0)throw new Error('columnWidthMm 仅适用于 layout: "wide"');const n=e.columnWidthMm??30;return L(n,"columnWidthMm"),{layout:t,columnWidthMm:n}}function yt(e){const t=e.paper===void 0?"a4":e.paper;if(typeof t!="string"&&(typeof t!="object"||t===null)||e.landscape!==void 0&&typeof e.landscape!="boolean")throw new Error("paper 必须是纸张预设名或 { widthMm, heightMm } 对象,landscape 必须是布尔值");if(typeof t=="string"&&!Object.prototype.hasOwnProperty.call(f.PAPER_SIZES,t))throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(f.PAPER_SIZES).join("/")})`);const n=de(t,void 0,e.landscape),r=n.widthMm,o=n.heightMm;return L(r,"纸张 widthMm"),L(o,"纸张 heightMm"),{widthMm:r,heightMm:o}}function Mt(e){if(e.margins!==void 0&&(!e.margins||typeof e.margins!="object"||Array.isArray(e.margins)))throw new Error("margins 必须是页边距对象");const t=e.margins??{},n={marginTopMm:t.marginTopMm===void 0?10:t.marginTopMm,marginBottomMm:t.marginBottomMm===void 0?10:t.marginBottomMm,marginLeftMm:t.marginLeftMm===void 0?10:t.marginLeftMm,marginRightMm:t.marginRightMm===void 0?10:t.marginRightMm};for(const[r,o]of Object.entries(n))L(o,r,!0);return n}function Tt(e,t){const n=e.dataset===void 0?"detail":e.dataset;if(typeof n!="string"||!n.trim())throw new Error("dataset 必须是非空字符串");if(e.title!==void 0&&typeof e.title!="string")throw new Error("title 必须是字符串");const r=e.titleHeightMm===void 0?10:e.titleHeightMm,o=e.titleGapMm===void 0?4:e.titleGapMm;L(r,"titleHeightMm"),L(o,"titleGapMm",!0);const l=e.title!==void 0&&e.title.length>0,i=l?r+o:0;if(i>=t)throw new Error("标题高度与间距占满页面,必须为表格保留可用高度");return{dataset:n,titleHeightMm:r,hasTitle:l,titleSpaceMm:i}}function xt(e){if(e.listOptions!==void 0&&(!e.listOptions||typeof e.listOptions!="object"||Array.isArray(e.listOptions)))throw new Error("listOptions 必须是列表配置对象");const t=e.listOptions??{};X(t.align,"listOptions.align",!0),X(t.headerAlign,"listOptions.headerAlign",!1);for(const n of["fontSizePt","rowHeightMm","paddingMm"]){const r=t[n];r!==void 0&&L(r,`listOptions.${n}`,n==="paddingMm")}return t}function Et(e){let t=0,n=0;for(const[r,o]of e.entries()){if(!o||typeof o.header!="string"||typeof o.field!="string"||!o.field.trim())throw new Error(`columns[${r}] 需要字符串 header 与非空 field`);X(o.align,`columns[${r}].align`,!0),X(o.headerAlign,`columns[${r}].headerAlign`,!1),o.flex!==void 0&&L(o.flex,`columns[${r}].flex`),o.widthMm!==void 0?(L(o.widthMm,`columns[${r}].widthMm`),t+=o.widthMm):n=Math.max(n,o.flex??1)}return{fixedWidthMm:t,maxFlex:n}}function St(e,t,n,r){const{fixedWidthMm:o,maxFlex:l}=Et(e.columns);if(t==="page"&&o>r)throw new Error(`固定列宽 ${o}mm 超出页面可用宽度 ${r}mm`);const i=r-o;if(t==="page"&&l>0&&i<=0)throw new Error("固定列占满页面可用宽度,自动列需要正的剩余宽度");const a=l>0?e.columns.reduce((c,d)=>c+(d.widthMm===void 0?(d.flex??1)/l:0),0):0;return{columns:e.columns.map(({widthMm:c,flex:d,...u},m)=>{const h=c??(t==="wide"?n*(d??1):i*((d??1)/l)/a);return L(h,`columns[${m}] 分配后的 widthMm`),{...u,widthMm:h}}),fixedWidthMm:o,maxFlex:l}}function Ct(e){if(!e||typeof e!="object")throw new Error("标准明细模板需要 options 对象");if(!Array.isArray(e.columns)||e.columns.length===0)throw new Error("columns 至少需要一列");const{layout:t,columnWidthMm:n}=bt(e),r=yt(e);let o=r.widthMm;const l=r.heightMm,i=Mt(e);let a=o-i.marginLeftMm-i.marginRightMm;const s=l-i.marginTopMm-i.marginBottomMm;if(t==="page"&&a<=0||s<=0)throw new Error("页边距占满纸张,必须保留正的可用宽度和高度");const{dataset:c,titleHeightMm:d,hasTitle:u,titleSpaceMm:m}=Tt(e,s),h=xt(e),{columns:g,fixedWidthMm:p,maxFlex:b}=St(e,t,n,a);t==="wide"&&(a=g.reduce((S,k)=>S+k.widthMm,0),L(a,"宽表总列宽"),o=a+i.marginLeftMm+i.marginRightMm,L(o,"宽表总宽度"));const E={widthMm:o,heightMm:l,...i,components:[],...t==="wide"?{layout:t}:{}};return u&&E.components.push({kind:"text",text:e.title,leftMm:i.marginLeftMm,topMm:i.marginTopMm,widthMm:a,heightMm:d,style:{fontSize:16,bold:!0,align:"center",verticalAlign:"middle",...e.titleStyle}}),E.components.push({align:"auto",headerAlign:"center",...h,kind:"list",...t==="wide"?{layout:t}:{},...u?{title:e.title}:{},dataset:c,columns:g,leftMm:i.marginLeftMm,topMm:i.marginTopMm+m,widthMm:t==="wide"||b>0?a:p}),e.params===void 0?{pages:[E]}:{params:e.params,pages:[E]}}function Pt(e){return e}class z extends Error{constructor(t,n){super(n),this.code=t,this.name="ReportTemplateStoreError"}}function O(e){return JSON.parse(JSON.stringify(e))}function I(e){if(!e?.aborted)return;const t=new Error("模板操作已取消");throw t.name="AbortError",t}function we(e){const t=e?Number(e.revision):0;if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new z("history","修订号无效或已达上限");return String(t+1)}function Rt(e,t={}){const n=async(i,a)=>{I(a);const s=await e.read(i,a);return I(a),s?O(s):void 0},r=async(i,a)=>{const s=await n(i,a.signal);if((s?.revision??null)!==a.expectedRevision)throw new z("conflict","模板已变化,请重新读取后提交");return s},o=async(i,a,s)=>{if(I(a.signal),!await e.compareAndSwap(i.id,a.expectedRevision,O(i),{signal:a.signal,...s?{publication:O(s)}:{}}))throw new z("conflict","模板已被其他请求更新");return O(i)},l=(i,a,s,c)=>{const d=we(i),u=N.parseReportTemplate({...a,revision:d}),m={revision:d,document:u,publishedAt:(t.now?.()??new Date).toISOString()};return c!==void 0&&(m.restoredFrom=c),o({id:i.id,revision:d,publishedRevision:d,published:u},s,m)};return{list:async i=>{I(i);const a=await e.list(i);return I(i),O(a)},get:async(i,a={})=>{const s=await n(i,a.signal),c=a.draft?s?.draft:s?.published;return c?N.parseReportTemplate(c):void 0},history:async(i,a)=>{I(a);const s=await e.history(i,a);return I(a),O(s)},saveDraft:async(i,a)=>{I(a.signal);const s=N.parseReportTemplate(t.migrate?await t.migrate(i):i),c=await r(s.id,a),d=we(c);return o({id:s.id,revision:d,draft:{...s,revision:d},...c?.publishedRevision?{publishedRevision:c.publishedRevision,published:c.published}:{}},a)},publish:async(i,a)=>{const s=await r(i,a);if(!s)throw new z("missing","模板不存在");if(!s.draft)throw new z("draft","没有可发布的草稿");return l(s,s.draft,a)},rollback:async(i,a,s)=>{const c=await r(i,s);if(!c)throw new z("missing","模板不存在");I(s.signal);const d=await e.getVersion(i,a,s.signal);if(!d)throw new z("history","历史修订不存在");return l(c,d.document,s,a)}}}function It(){const e=new Map,t=new Map;return{read:async(n,r)=>{I(r);const o=e.get(n);return o?O(o):void 0},list:async n=>(I(n),Array.from(e.values(),({id:r,revision:o,publishedRevision:l})=>({id:r,revision:o,...l?{publishedRevision:l}:{}}))),history:async(n,r)=>(I(r),Array.from(t.get(n)?.values()??[],o=>O(o))),getVersion:async(n,r,o)=>{I(o);const l=t.get(n)?.get(r);return l?O(l):void 0},compareAndSwap:async(n,r,o,l)=>{if(I(l.signal),(e.get(n)?.revision??null)!==r)return!1;if(o.id!==n)throw new z("history","状态 ID 与存储 ID 不一致");const i=O(o),a=l.publication;if(a){const s=t.get(n)??new Map;if(s.has(a.revision)||a.revision!==o.revision||a.document.id!==n)throw new z("history","发布修订不可覆盖,且必须与状态修订和模板 ID 一致");s.set(a.revision,O(a)),t.set(n,s)}return e.set(n,i),!0}}}function ke(e){return!e||typeof e!="object"?!1:[e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex].every(t=>Number.isInteger(t)&&t>=0)}function Ae(e,t,n){const r=e.grid;if(!r)return null;const o=r.cells[t];if(!o)return null;const i=H.resolveGridLayout(r,e.widthMm,e.heightMm).cells.filter(s=>s.ri===t).findIndex(s=>s.ci===n),a=o[i];return a?{cell:a,sourceColumnIndex:i}:null}function kt(e){return e.value!==void 0?e.value:e.rawText??e.text??null}function At(e,t){return e.valueType?e.valueType:typeof t=="number"?"number":typeof t=="boolean"?"boolean":t===null&&e.numberFormat&&/[0#?]/.test(e.numberFormat)?"number":"text"}function Ft(e,t){if(e.editable===!1)return"cell";if(e.formula!==void 0)return"formula";if(e.children?.length)return"complex";if(t.table&&t.table.role!=="body"&&e.editable!==!0)return"structure"}function Lt(e,t){const n=e.table;if(n)return{id:n.id,rowIndex:n.rowIndex+t.rowIndex,role:n.role,columnKey:n.columnKeys[t.columnIndex]}}function Ot(e,t,n){if(e.source)return{...e.source};const r=t.table?.source,o=t.table?.columnKeys[n.columnIndex];if(!(!r||r.rowKey===void 0||o===void 0))return{...r,rowKey:r.rowKey,field:o}}function Fe(e,t,n){const r=kt(n),o=Ft(n,e);return{address:{...t},cell:n,component:e,value:r,valueType:At(n,r),table:Lt(e,t),source:Ot(n,e,t),editable:o===void 0,readOnlyReason:o}}function ee(e,t){if(!ke(t))return null;const n=e.pages[t.pageIndex]?.components[t.componentIndex];if(!n)return null;const r=Ae(n,t.rowIndex,t.columnIndex);return r?Fe(n,t,r.cell):null}function te(e){const t=new Map;return n=>{if(!ke(n))return null;const r=e.pages[n.pageIndex]?.components[n.componentIndex];if(!r?.grid)return null;let o=t.get(r);if(!o){const i=new Map;o=new Map;for(const a of H.resolveGridLayout(r.grid,r.widthMm,r.heightMm).cells){const s=i.get(a.ri)??0;i.set(a.ri,s+1);const c=r.grid.cells[a.ri]?.[s];c&&o.set(`${a.ri}:${a.ci}`,c)}t.set(r,o)}const l=o.get(`${n.rowIndex}:${n.columnIndex}`);return l?Fe(r,n,l):null}}class T extends Error{constructor(t){super(`Invalid report cell edit: ${t}`),this.code=t,this.name="ReportCellEditError"}}function Dt(e,t){let n=e.trim();const r=t&&n.endsWith("%");if(r&&(n=n.slice(0,-1).trim()),/^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d*)?(?:[eE][+-]?\d+)?$/.test(n)&&(n=n.replace(/,/g,"")),!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(n))throw new T("number");return Number(n)/(r?100:1)}function Nt(e,t){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e!="string"&&typeof e!="number")throw new T("number");const n=typeof e=="number"?e:Dt(e,be.isExcelPercentageFormat(t.cell.numberFormat));if(!Number.isFinite(n)||Number.isInteger(n)&&!Number.isSafeInteger(n))throw new T("number");return n}function $t(e){if(e===null||typeof e=="string"&&e.trim()==="")return null;if(typeof e=="boolean")return e;const t=String(e).trim().toLowerCase();if(["true","yes","是","1"].includes(t))return!0;if(["false","no","否","0"].includes(t))return!1;throw new T("boolean")}function ne(e,t){return e.valueType==="number"?Nt(t,e):e.valueType==="boolean"?$t(t):t===null?null:String(t)}function _t(e,t){const n=t.cell.text,o=[["是","否"],["TRUE","FALSE"],["True","False"],["true","false"],["1","0"]].find(l=>l.includes(n??""));return o?o[e?0:1]:String(e)}function V(e,t){return t===null?"":typeof t=="boolean"?_t(t,e):typeof t=="number"?be.formatExcelNumber(t,e.cell.numberFormat):String(t)}function zt(e,t,n){const r=ee(e,t);if(!r)throw new T("missing");return ue(r,n)}function ue(e,t){if(!e.editable)throw new T("readonly");const n=ne(e,t);return{address:{...e.address},table:e.table,source:e.source,previousValue:e.value,previousText:e.cell.text??"",value:n,text:V(e,n)}}function Bt(e,t){const n=e.table,r=t.table;return!n||!r||n.columnKey===void 0?!1:n.id===r.id&&n.rowIndex===r.rowIndex&&n.role===r.role&&n.columnKey===r.columnKey}function Le(e,t,n){const r=e.grid,{rowIndex:o,columnIndex:l}=t.address,i=Ae(e,o,l),a=[...r.cells],s=[...a[o]],c=V(t,n.value),d={...i.cell,value:n.value,text:c,rawText:c};return s[i.sourceColumnIndex]=d,a[o]=s,{...e,grid:{...r,cells:a}}}function Ht(e,t){const n=e.table?.columnKeys,r=t.table?.columnKey;return n&&r!==void 0?n.flatMap((o,l)=>o===r?[l]:[]):[]}function jt(e,t,n,r,o,l){const i=t.table,a=o.table;if(!i||!a||i.id!==a.id||i.role!==a.role||!t.grid)return t;const s=a.rowIndex-i.rowIndex;if(s<0||s>=t.grid.cells.length)return t;let c=t;for(const d of Ht(t,o)){const u=ee(e,{pageIndex:n,componentIndex:r,rowIndex:s,columnIndex:d});u?.editable&&Bt(o,u)&&(c=Le(c,u,l))}return c}function Wt(e,t,n,r,o,l){const i=o.address;return o.table?.columnKey!==void 0?jt(e,t,n,r,o,l):i.pageIndex===n&&i.componentIndex===r?Le(t,o,l):t}function Oe(e,t){const n=t.source;if(!n)return!1;const r=e.source;return!r||["datasetId","rowKey","field","revision","sourceToken"].some(o=>!Object.is(r[o],n[o]))}function qt(e,t){const n=ee(e,t.address);if(!n)throw new T("missing");if(!n.editable)throw new T("readonly");if(Oe(n,t))throw new T("conflict");if(!Object.is(n.value,t.previousValue)||(n.cell.text??"")!==t.previousText)throw new T("conflict");const r=ne(n,t.value),o={...t,value:r,text:V(n,r)};if(Object.is(r,n.value)&&o.text===n.cell.text)return e;const l=e.pages.map((i,a)=>{const s=i.components.map((c,d)=>Wt(e,c,a,d,n,o));return s.every((c,d)=>c===i.components[d])?i:{...i,components:s}});return{...e,pages:l}}function Kt(e){return JSON.stringify([e.pageIndex,e.componentIndex,e.rowIndex,e.columnIndex])}function ve(e){const t=e.table;return t?.columnKey!==void 0?JSON.stringify([t.id,t.role,t.rowIndex,t.columnKey]):Kt(e.address)}function Vt(e,t){if(!t.length)return e;const n=new Map(t.map(s=>[ve(s),s])),r=new Set(t.flatMap(s=>s.table?[s.table.id]:[])),o=new Set(t.map(s=>`${s.address.pageIndex}:${s.address.componentIndex}`)),l=te(e);function i(s,c,d){const u=s.grid;if(!u||!o.has(`${c}:${d}`)&&!r.has(s.table?.id??""))return s;const m=new Map,h=new Map;for(const g of H.resolveGridLayout(u,s.widthMm,s.heightMm).cells){const p=h.get(g.ri)??0;h.set(g.ri,p+1);const b=l({pageIndex:c,componentIndex:d,rowIndex:g.ri,columnIndex:g.ci}),E=b&&n.get(ve(b));if(!E||!b.editable)continue;const S=m.get(g.ri)??[...u.cells[g.ri]],k=V(b,E.value);Object.is(b.value,E.value)&&k===b.cell.text||(S[p]={...g.cell,value:E.value,text:k,rawText:k},m.set(g.ri,S))}return m.size?{...s,grid:{...u,cells:u.cells.map((g,p)=>m.get(p)??g)}}:s}const a=e.pages.map((s,c)=>{const d=s.components.map((u,m)=>i(u,c,m));return d.every((u,m)=>u===s.components[m])?s:{...s,components:d}});return a.every((s,c)=>s===e.pages[c])?e:{...e,pages:a}}function re(e){const t=e.source;if(t)return JSON.stringify([t.datasetId,t.rowKey,t.field]);const n=e.table;if(n?.columnKey!==void 0)return JSON.stringify([n.id,n.role,n.rowIndex,n.columnKey]);const r=e.address;return JSON.stringify([r.pageIndex,r.componentIndex,r.rowIndex,r.columnIndex])}function Ut(e,t,n){if(typeof n!="string"||!n.trim()||!Array.isArray(t))throw new T("missing");if(t.length>1e4)throw new T("limit");const r=new Set,o=te(e),l=t.map(({address:i,value:a})=>{const s=o(i);if(!s)throw new T("missing");const c=ue(s,a),d=re(c);if(r.has(d))throw new T("duplicate");return r.add(d),c});return{requestId:n,edits:l}}function Gt(e,t){if(t.edits.length>1e4)throw new T("limit");const n=te(e),r=new Set,o=t.edits.map(l=>{const i=n(l.address);if(!i)throw new T("missing");const a=re(l);if(r.has(a))throw new T("duplicate");if(r.add(a),Oe(i,l)||!Object.is(i.value,l.previousValue)||(i.cell.text??"")!==l.previousText)throw new T("conflict");return ue(i,l.value)});return Vt(e,o)}function Yt(e){const t=new Map;for(const n of e){const r=re(n),o=t.get(r),l=o?{...n,previousValue:o.previousValue,previousText:o.previousText}:{...n};Object.is(l.previousValue,l.value)?t.delete(r):t.set(r,l)}return[...t.values()]}function Jt(e){return e.map(t=>t.map(n=>/[\t\r\n"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n).join(" ")).join(`\r
7
+ `)}function Xt(e,t){const n=e[e.length-1];e.length>1&&n?.length===1&&n[0]===""&&/[\r\n]$/.test(t)&&e.pop()}function Zt(e,t=1e4){if(e.length>4*1024*1024)throw new Error("Clipboard text limit exceeded");const n=[[]];let r="",o=!1,l=!1,i=0;function a(){if(++i>t)throw new Error("Clipboard cell limit exceeded");n[n.length-1].push(r),r="",l=!1}for(let s=0;s<e.length;s++){const c=e[s];if(o){if(c!=='"'){r+=c;continue}if(e[s+1]==='"'){r+='"',s++;continue}o=!1,l=!0;continue}if(c==='"'&&!r&&!l){o=!0;continue}if(c===" "){a();continue}if(c==="\r"||c===`
8
+ `){a(),n.push([]),c==="\r"&&e[s+1]===`
9
+ `&&s++;continue}if(l)throw new Error("Invalid quoted clipboard value");r+=c}if(o)throw new Error("Unclosed clipboard quote");return a(),Xt(n,e),n}function Qt(e,t,n){if(!n||n.revision===void 0&&n.sourceToken===void 0)return e;const r=new Set(t.edits.flatMap(i=>i.source?[i.source.datasetId]:[]));if(!r.size)return e;function o(i){return!i.datasetId||!r.has(i.datasetId)||(n.revision===void 0||Object.is(n.revision,i.revision))&&(n.sourceToken===void 0||n.sourceToken===i.sourceToken)?i:{...i,...n.revision!==void 0?{revision:n.revision}:{},...n.sourceToken!==void 0?{sourceToken:n.sourceToken}:{}}}const l=e.pages.map(i=>{const a=i.components.map(s=>{const c=s.table?.source?o(s.table.source):void 0,d=s.table&&c!==s.table.source?{...s.table,source:c}:s.table,u=s.grid?.cells.map(h=>{const g=h.map(p=>{if(!p?.source)return p;const b=o(p.source);return b===p.source?p:{...p,source:b}});return g.some((p,b)=>p!==h[b])?g:h}),m=s.grid&&u?.some((h,g)=>h!==s.grid.cells[g])?{...s.grid,cells:u}:s.grid;return d!==s.table||m!==s.grid?{...s,table:d,grid:m}:s});return a.some((s,c)=>s!==i.components[c])?{...i,components:a}:i});return l.some((i,a)=>i!==e.pages[a])?{...e,pages:l}:e}class De extends Error{constructor(t,n,r){const o=typeof n.label=="string"?n.label:"单元格",l={definition:`${o}的编辑器配置无效`,type:`${o}的编辑器与数据类型不一致`,required:`${o}不能为空`,min:`${o}不能小于 ${r}`,max:`${o}不能大于 ${r}`,precision:`${o}最多保留 ${r} 位小数`,length:`${o}最多允许 ${r} 个字符`,choice:`${o}请选择有效选项`,date:`${o}请输入有效日期(YYYY-MM-DD)`};super(l[t]),this.code=t,this.field=n,this.expected=r,this.name="ReportCellFieldError"}}function v(e,t,n){throw new De(t,e,n)}function Ne(e){if(typeof e!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(e)||e.startsWith("0000-"))return!1;const t=new Date(`${e}T00:00:00.000Z`);return Number.isFinite(t.getTime())&&t.toISOString().slice(0,10)===e}function en(e){const[t="",n="0"]=String(e).toLowerCase().split("e");return Math.max(0,(t.split(".")[1]?.length??0)-Number(n))}function tn(e,t){e.min!==void 0&&t<e.min&&v(e,"min",e.min),e.max!==void 0&&t>e.max&&v(e,"max",e.max),e.precision!==void 0&&en(t)>e.precision&&v(e,"precision",e.precision)}function nn(e,t){Ne(t)||v(e,"date"),e.min!==void 0&&t<e.min&&v(e,"min",e.min),e.max!==void 0&&t>e.max&&v(e,"max",e.max)}function rn(e){[e.min,e.max].some(t=>t!==void 0&&!Number.isFinite(t))&&v(e,"definition"),e.min!==void 0&&e.max!==void 0&&e.min>e.max&&v(e,"definition"),e.precision!==void 0&&(!Number.isInteger(e.precision)||e.precision<0||e.precision>15)&&v(e,"definition")}function on(e){[e.min,e.max].some(t=>t!==void 0&&!Ne(t))&&v(e,"definition"),e.min!==void 0&&e.max!==void 0&&e.min>e.max&&v(e,"definition")}function an(e,t){(!Array.isArray(t.options)||!t.options.length)&&v(t,"definition");const n=e.valueType==="text"?"string":e.valueType,r=new Set;for(const o of t.options)(!o||typeof o.value!==n||typeof o.value=="number"&&!Number.isFinite(o.value))&&v(t,"definition"),o.label!==void 0&&typeof o.label!="string"&&v(t,"definition"),r.has(o.value)&&v(t,"definition"),r.add(o.value)}function sn(e){e.required!==void 0&&typeof e.required!="boolean"&&v(e,"definition"),[e.label,e.hint,e.unit].some(t=>t!==void 0&&typeof t!="string")&&v(e,"definition"),e.type==="boolean"&&[e.trueLabel,e.falseLabel].some(t=>t!==void 0&&typeof t!="string")&&v(e,"definition")}function $e(e,t){(!t||typeof t!="object"||Array.isArray(t)||!["text","number","boolean","enum","date"].includes(t.type))&&v(t??{type:"text"},"definition"),sn(t),(t.type==="number"||t.type==="boolean")&&e.valueType!==t.type&&v(t,"type"),(t.type==="text"||t.type==="date")&&e.valueType!=="text"&&v(t,"type"),t.type==="number"&&rn(t),t.type==="text"&&t.maxLength!==void 0&&(!Number.isInteger(t.maxLength)||t.maxLength<0)&&v(t,"definition"),t.type==="date"&&on(t),t.type==="enum"&&an(e,t)}function ln(e,t,n){if(!e.editable)throw new T("readonly");n&&$e(e,n);const r=ne(e,t);return n?(n.required&&typeof r=="string"&&!r.trim()&&v(n,"required"),r===null||r===""?(n.required&&v(n,"required"),r):(n.type==="number"&&tn(n,r),n.type==="date"&&nn(n,r),n.type==="text"&&n.maxLength!==void 0&&[...String(r)].length>n.maxLength&&v(n,"length",n.maxLength),n.type==="enum"&&!n.options.some(o=>Object.is(o.value,r))&&v(n,"choice"),r)):r}exports.DEFAULT_BORDER_PT=y.DEFAULT_BORDER_PT;exports.DEFAULT_FONT_FAMILY=y.DEFAULT_FONT_FAMILY;exports.DEFAULT_FONT_PT=y.DEFAULT_FONT_PT;exports.DEFAULT_STROKE_COLOR=y.DEFAULT_STROKE_COLOR;exports.DEFAULT_TEXT_COLOR=y.DEFAULT_TEXT_COLOR;exports.LINE_HEIGHT=y.LINE_HEIGHT;exports.RENDER_PLAN_SCHEMA_VERSION=y.RENDER_PLAN_SCHEMA_VERSION;exports.SCHEMA_VERSION_MACH=y.SCHEMA_VERSION_MACH;exports.isImageBackedComponent=y.isImageBackedComponent;exports.isRichText=y.isRichText;exports.PaginatePageLimitError=A.PaginatePageLimitError;exports.ReportSourceError=A.ReportSourceError;exports.createReportSource=A.createReportSource;exports.datasetJsonSchema=A.datasetJsonSchema;exports.defineReport=A.defineReport;exports.evalStyleRule=A.evalStyleRule;exports.formatValue=A.formatValue;exports.paginateTemplate=A.paginateTemplate;exports.parseDateLocal=A.parseDateLocal;exports.toExcelNumberFormat=A.toExcelNumberFormat;exports.toNumber=A.toNumber;exports.validateDatasetRows=A.validateDatasetRows;exports.CSS_DPI=f.CSS_DPI;exports.MM_PER_INCH=f.MM_PER_INCH;exports.PAPER_SIZES=f.PAPER_SIZES;exports.mergeComponentStyles=f.mergeComponentStyles;exports.mmToPx=f.mmToPx;exports.mmToPxFactor=f.mmToPxFactor;exports.ptToPx=f.ptToPx;exports.pxToMm=f.pxToMm;exports.resolveBoxBorders=f.resolveBoxBorders;exports.resolveFontSize=f.resolveFontSize;exports.resolveLineHeight=f.resolveLineHeight;exports.resolveStroke=f.resolveStroke;exports.resolveTextColor=f.resolveTextColor;exports.round=f.round;exports.assertRenderPlan=Z.assertRenderPlan;exports.validateComponent=Z.validateComponent;exports.validatePage=Z.validatePage;exports.validateRenderPlan=Z.validateRenderPlan;exports.charWidthEm=$.charWidthEm;exports.createCanvasMeasurer=$.createCanvasMeasurer;exports.createHeuristicMeasurer=$.createHeuristicMeasurer;exports.heuristicMeasurer=$.heuristicMeasurer;exports.measureTextMm=$.measureTextMm;exports.wrapText=$.wrapText;exports.resolveGridLayout=H.resolveGridLayout;exports.OutputAssetError=j.OutputAssetError;exports.resolvePlanAssets=j.resolvePlanAssets;exports.OutputFidelityError=D.OutputFidelityError;exports.inspectOutputCapabilities=D.inspectOutputCapabilities;exports.reportOutputDiagnostics=D.reportOutputDiagnostics;exports.REPORT_TEMPLATE_DOCUMENT_VERSION=N.REPORT_TEMPLATE_DOCUMENT_VERSION;exports.ReportTemplateError=N.ReportTemplateError;exports.createTemplateRegistry=N.createTemplateRegistry;exports.defineReportTemplate=N.defineReportTemplate;exports.parseReportTemplate=N.parseReportTemplate;exports.serializeReportTemplate=N.serializeReportTemplate;exports.validateReportTemplate=N.validateReportTemplate;exports.validateReportTemplateDocument=N.validateReportTemplateDocument;exports.ReportParamValidationError=q.ReportParamValidationError;exports.assertReportParams=q.assertReportParams;exports.isReportDate=q.isReportDate;exports.reportParamsJsonSchema=q.reportParamsJsonSchema;exports.validateReportParamDefinitions=q.validateReportParamDefinitions;exports.validateReportParams=q.validateReportParams;exports.PageBuilder=Ie;exports.ReportCellEditError=T;exports.ReportCellFieldError=De;exports.ReportTemplateStoreError=z;exports.TemplateBuilder=Re;exports.applyReportCellEdit=qt;exports.applyReportCellEditBatch=Gt;exports.applyReportEditResult=Qt;exports.classOf=P;exports.columnsFromContract=vt;exports.computePageWindow=Te;exports.createCanvasPager=pt;exports.createMemoryTemplateStore=It;exports.createProviderReport=Pt;exports.createReportCellEdit=zt;exports.createReportCellEditBatch=Ut;exports.createReportCellResolver=te;exports.createTableTemplate=Ct;exports.createTemplate=wt;exports.createTemplateManager=Rt;exports.formatReportCellEdit=V;exports.formatReportClipboard=Jt;exports.getReportCellContext=ee;exports.measurePageSizePx=Q;exports.parseReportCellFieldInput=ln;exports.parseReportCellInput=ne;exports.parseReportClipboard=Zt;exports.planFontSizePx=it;exports.renderComponent=se;exports.renderPage=Me;exports.renderPlan=et;exports.renderPlanToCanvas=ft;exports.renderPlanToCanvasAsync=gt;exports.renderPlanToImages=ut;exports.reportCellEditKey=re;exports.resolvePaper=de;exports.summarizeReportCellEdits=Yt;exports.validateReportCellFieldDefinition=$e;
package/dist/index.d.cts CHANGED
@@ -485,7 +485,7 @@ export declare class OutputAssetError extends Error {
485
485
  }
486
486
 
487
487
  export declare interface OutputDiagnostic {
488
- code: "missing-image" | "unsupported-component" | "unsupported-image-format" | "rich-text-flattened" | "nested-components-omitted" | "async-image-required" | "image-decode-failed" | "asset-render-failed" | "asset-budget-exceeded";
488
+ code: "missing-image" | "unsupported-component" | "unsupported-image-format" | "unsupported-style" | "rich-text-flattened" | "nested-components-omitted" | "async-image-required" | "image-decode-failed" | "asset-render-failed" | "asset-budget-exceeded";
489
489
  severity: "warning";
490
490
  format: OutputFormat;
491
491
  pageIndex: number;
@@ -497,13 +497,27 @@ export declare interface OutputDiagnostic {
497
497
  message: string;
498
498
  }
499
499
 
500
- export declare interface OutputDiagnosticOptions {
500
+ export declare interface OutputDiagnosticOptions extends OutputTaskOptions {
501
501
  /** Structured fidelity diagnostics; rendering never silently invents missing content. */
502
502
  onDiagnostic?: (diagnostic: OutputDiagnostic) => void;
503
+ /** Reject known unsupported content before creating an incomplete file. Default warn. */
504
+ fidelity?: "warn" | "strict";
505
+ }
506
+
507
+ export declare class OutputFidelityError extends Error {
508
+ readonly diagnostics: readonly OutputDiagnostic[];
509
+ readonly code = "output-fidelity";
510
+ constructor(diagnostics: readonly OutputDiagnostic[]);
503
511
  }
504
512
 
505
513
  export declare type OutputFormat = "dom" | "canvas" | "pdf" | "xlsx";
506
514
 
515
+ /** Stage counts are exact completed units; encoding libraries may remain indeterminate. */
516
+ export declare interface OutputTaskOptions {
517
+ signal?: AbortSignal;
518
+ onProgress?: (completed: number, total: number) => void;
519
+ }
520
+
507
521
  export declare class PageBuilder {
508
522
  private readonly parent;
509
523
  private readonly page;
@@ -579,6 +593,9 @@ export declare type PaperName = keyof typeof PAPER_SIZES;
579
593
  /** 日历日字符串 → 本地 Date(不含时间的纯日期,杜绝 UTC 偏移) */
580
594
  export declare function parseDateLocal(input: string): Date | null;
581
595
 
596
+ /** Core type parsing is authoritative; field controls add restrictions, never coerce IDs or bypass readonly. */
597
+ export declare function parseReportCellFieldInput(context: ReportCellContext, input: ReportCellValue, field?: ReportCellFieldOptions): ReportCellValue;
598
+
582
599
  /** 严格解析编辑输入;文本列不隐式推断数值,清空数值/布尔列得到 null。 */
583
600
  export declare function parseReportCellInput(context: ReportCellContext, input: ReportCellValue): ReportCellValue;
584
601
 
@@ -708,6 +725,11 @@ export declare interface ReportCellAddress {
708
725
  columnIndex: number;
709
726
  }
710
727
 
728
+ export declare interface ReportCellChoice {
729
+ value: Exclude<ReportCellValue, null>;
730
+ label?: string;
731
+ }
732
+
711
733
  export declare interface ReportCellContext {
712
734
  address: ReportCellAddress;
713
735
  cell: Readonly<GridCell>;
@@ -740,6 +762,45 @@ export declare type ReportCellEditErrorCode = "missing" | "readonly" | "number"
740
762
 
741
763
  export declare function reportCellEditKey(edit: Pick<ReportCellEdit, "address" | "source" | "table">): string;
742
764
 
765
+ declare interface ReportCellFieldBase {
766
+ /** Presentation only; it never grants write permission. */
767
+ label?: string;
768
+ hint?: string;
769
+ unit?: string;
770
+ required?: boolean;
771
+ }
772
+
773
+ /** Shared structured validation for browser editors, pasted values and backend adapters. */
774
+ export declare class ReportCellFieldError extends Error {
775
+ readonly code: ReportCellFieldErrorCode;
776
+ readonly field: ReportCellFieldOptions;
777
+ readonly expected?: string | number | undefined;
778
+ constructor(code: ReportCellFieldErrorCode, field: ReportCellFieldOptions, expected?: string | number | undefined);
779
+ }
780
+
781
+ export declare type ReportCellFieldErrorCode = "definition" | "type" | "required" | "min" | "max" | "precision" | "length" | "choice" | "date";
782
+
783
+ export declare type ReportCellFieldOptions = ReportCellFieldBase & ({
784
+ type: "text";
785
+ maxLength?: number;
786
+ } | {
787
+ type: "number";
788
+ min?: number;
789
+ max?: number;
790
+ precision?: number;
791
+ } | {
792
+ type: "boolean";
793
+ trueLabel?: string;
794
+ falseLabel?: string;
795
+ } | {
796
+ type: "enum";
797
+ options: readonly ReportCellChoice[];
798
+ } | {
799
+ type: "date";
800
+ min?: string;
801
+ max?: string;
802
+ });
803
+
743
804
  export declare interface ReportCellInput {
744
805
  address: ReportCellAddress;
745
806
  value: ReportCellValue;
@@ -824,7 +885,7 @@ export declare interface ReportFetcher {
824
885
  getParamDefs?: (reportIds: string[]) => ReportParamDef[];
825
886
  }
826
887
 
827
- export declare interface ReportFetchInput {
888
+ export declare interface ReportFetchInput extends ReportTaskMonitoring {
828
889
  reportIds: string[];
829
890
  params: Record<string, string>;
830
891
  signal?: AbortSignal;
@@ -963,6 +1024,25 @@ export declare class ReportSourceError extends Error {
963
1024
  constructor(code: ReportSourceError["code"], message: string, cause?: unknown);
964
1025
  }
965
1026
 
1027
+ /** 阶段事件只包含可序列化值;不表示估算百分比,也不包含业务数据。 */
1028
+ export declare interface ReportTaskEvent {
1029
+ taskId: string;
1030
+ correlationId?: string;
1031
+ stage: "query" | "validate" | "layout" | "encode";
1032
+ status: "started" | "completed" | "failed";
1033
+ reportId?: string;
1034
+ completed?: number;
1035
+ total?: number;
1036
+ }
1037
+
1038
+ export declare interface ReportTaskMonitoring {
1039
+ taskId?: string;
1040
+ correlationId?: string;
1041
+ onEvent?: ReportTaskObserver;
1042
+ }
1043
+
1044
+ export declare type ReportTaskObserver = (event: ReportTaskEvent) => void;
1045
+
966
1046
  export declare interface ReportTemplate {
967
1047
  schemaVersion?: string;
968
1048
  /** 参数定义(可选;宿主也可经 ReportPreview 的 paramDefs prop 提供,prop 优先) */
@@ -1282,6 +1362,9 @@ export declare function validatePage(page: unknown, path: string, errors: Valida
1282
1362
 
1283
1363
  export declare function validateRenderPlan(input: unknown): ValidationResult;
1284
1364
 
1365
+ /** Check configuration before opening an input, including JSON/JavaScript callers. */
1366
+ export declare function validateReportCellFieldDefinition(context: ReportCellContext, field: ReportCellFieldOptions): void;
1367
+
1285
1368
  /** 模板参数配置错误也统一返回结构化问题,不让无效默认值或边界静默进入后端。 */
1286
1369
  export declare function validateReportParamDefinitions(defs: readonly ReportParamDef[]): ReportParamIssue[];
1287
1370
 
package/dist/index.d.ts CHANGED
@@ -485,7 +485,7 @@ export declare class OutputAssetError extends Error {
485
485
  }
486
486
 
487
487
  export declare interface OutputDiagnostic {
488
- code: "missing-image" | "unsupported-component" | "unsupported-image-format" | "rich-text-flattened" | "nested-components-omitted" | "async-image-required" | "image-decode-failed" | "asset-render-failed" | "asset-budget-exceeded";
488
+ code: "missing-image" | "unsupported-component" | "unsupported-image-format" | "unsupported-style" | "rich-text-flattened" | "nested-components-omitted" | "async-image-required" | "image-decode-failed" | "asset-render-failed" | "asset-budget-exceeded";
489
489
  severity: "warning";
490
490
  format: OutputFormat;
491
491
  pageIndex: number;
@@ -497,13 +497,27 @@ export declare interface OutputDiagnostic {
497
497
  message: string;
498
498
  }
499
499
 
500
- export declare interface OutputDiagnosticOptions {
500
+ export declare interface OutputDiagnosticOptions extends OutputTaskOptions {
501
501
  /** Structured fidelity diagnostics; rendering never silently invents missing content. */
502
502
  onDiagnostic?: (diagnostic: OutputDiagnostic) => void;
503
+ /** Reject known unsupported content before creating an incomplete file. Default warn. */
504
+ fidelity?: "warn" | "strict";
505
+ }
506
+
507
+ export declare class OutputFidelityError extends Error {
508
+ readonly diagnostics: readonly OutputDiagnostic[];
509
+ readonly code = "output-fidelity";
510
+ constructor(diagnostics: readonly OutputDiagnostic[]);
503
511
  }
504
512
 
505
513
  export declare type OutputFormat = "dom" | "canvas" | "pdf" | "xlsx";
506
514
 
515
+ /** Stage counts are exact completed units; encoding libraries may remain indeterminate. */
516
+ export declare interface OutputTaskOptions {
517
+ signal?: AbortSignal;
518
+ onProgress?: (completed: number, total: number) => void;
519
+ }
520
+
507
521
  export declare class PageBuilder {
508
522
  private readonly parent;
509
523
  private readonly page;
@@ -579,6 +593,9 @@ export declare type PaperName = keyof typeof PAPER_SIZES;
579
593
  /** 日历日字符串 → 本地 Date(不含时间的纯日期,杜绝 UTC 偏移) */
580
594
  export declare function parseDateLocal(input: string): Date | null;
581
595
 
596
+ /** Core type parsing is authoritative; field controls add restrictions, never coerce IDs or bypass readonly. */
597
+ export declare function parseReportCellFieldInput(context: ReportCellContext, input: ReportCellValue, field?: ReportCellFieldOptions): ReportCellValue;
598
+
582
599
  /** 严格解析编辑输入;文本列不隐式推断数值,清空数值/布尔列得到 null。 */
583
600
  export declare function parseReportCellInput(context: ReportCellContext, input: ReportCellValue): ReportCellValue;
584
601
 
@@ -708,6 +725,11 @@ export declare interface ReportCellAddress {
708
725
  columnIndex: number;
709
726
  }
710
727
 
728
+ export declare interface ReportCellChoice {
729
+ value: Exclude<ReportCellValue, null>;
730
+ label?: string;
731
+ }
732
+
711
733
  export declare interface ReportCellContext {
712
734
  address: ReportCellAddress;
713
735
  cell: Readonly<GridCell>;
@@ -740,6 +762,45 @@ export declare type ReportCellEditErrorCode = "missing" | "readonly" | "number"
740
762
 
741
763
  export declare function reportCellEditKey(edit: Pick<ReportCellEdit, "address" | "source" | "table">): string;
742
764
 
765
+ declare interface ReportCellFieldBase {
766
+ /** Presentation only; it never grants write permission. */
767
+ label?: string;
768
+ hint?: string;
769
+ unit?: string;
770
+ required?: boolean;
771
+ }
772
+
773
+ /** Shared structured validation for browser editors, pasted values and backend adapters. */
774
+ export declare class ReportCellFieldError extends Error {
775
+ readonly code: ReportCellFieldErrorCode;
776
+ readonly field: ReportCellFieldOptions;
777
+ readonly expected?: string | number | undefined;
778
+ constructor(code: ReportCellFieldErrorCode, field: ReportCellFieldOptions, expected?: string | number | undefined);
779
+ }
780
+
781
+ export declare type ReportCellFieldErrorCode = "definition" | "type" | "required" | "min" | "max" | "precision" | "length" | "choice" | "date";
782
+
783
+ export declare type ReportCellFieldOptions = ReportCellFieldBase & ({
784
+ type: "text";
785
+ maxLength?: number;
786
+ } | {
787
+ type: "number";
788
+ min?: number;
789
+ max?: number;
790
+ precision?: number;
791
+ } | {
792
+ type: "boolean";
793
+ trueLabel?: string;
794
+ falseLabel?: string;
795
+ } | {
796
+ type: "enum";
797
+ options: readonly ReportCellChoice[];
798
+ } | {
799
+ type: "date";
800
+ min?: string;
801
+ max?: string;
802
+ });
803
+
743
804
  export declare interface ReportCellInput {
744
805
  address: ReportCellAddress;
745
806
  value: ReportCellValue;
@@ -824,7 +885,7 @@ export declare interface ReportFetcher {
824
885
  getParamDefs?: (reportIds: string[]) => ReportParamDef[];
825
886
  }
826
887
 
827
- export declare interface ReportFetchInput {
888
+ export declare interface ReportFetchInput extends ReportTaskMonitoring {
828
889
  reportIds: string[];
829
890
  params: Record<string, string>;
830
891
  signal?: AbortSignal;
@@ -963,6 +1024,25 @@ export declare class ReportSourceError extends Error {
963
1024
  constructor(code: ReportSourceError["code"], message: string, cause?: unknown);
964
1025
  }
965
1026
 
1027
+ /** 阶段事件只包含可序列化值;不表示估算百分比,也不包含业务数据。 */
1028
+ export declare interface ReportTaskEvent {
1029
+ taskId: string;
1030
+ correlationId?: string;
1031
+ stage: "query" | "validate" | "layout" | "encode";
1032
+ status: "started" | "completed" | "failed";
1033
+ reportId?: string;
1034
+ completed?: number;
1035
+ total?: number;
1036
+ }
1037
+
1038
+ export declare interface ReportTaskMonitoring {
1039
+ taskId?: string;
1040
+ correlationId?: string;
1041
+ onEvent?: ReportTaskObserver;
1042
+ }
1043
+
1044
+ export declare type ReportTaskObserver = (event: ReportTaskEvent) => void;
1045
+
966
1046
  export declare interface ReportTemplate {
967
1047
  schemaVersion?: string;
968
1048
  /** 参数定义(可选;宿主也可经 ReportPreview 的 paramDefs prop 提供,prop 优先) */
@@ -1282,6 +1362,9 @@ export declare function validatePage(page: unknown, path: string, errors: Valida
1282
1362
 
1283
1363
  export declare function validateRenderPlan(input: unknown): ValidationResult;
1284
1364
 
1365
+ /** Check configuration before opening an input, including JSON/JavaScript callers. */
1366
+ export declare function validateReportCellFieldDefinition(context: ReportCellContext, field: ReportCellFieldOptions): void;
1367
+
1285
1368
  /** 模板参数配置错误也统一返回结构化问题,不让无效默认值或边界静默进入后端。 */
1286
1369
  export declare function validateReportParamDefinitions(defs: readonly ReportParamDef[]): ReportParamIssue[];
1287
1370