@agile-team/mach-report 0.7.0 → 0.9.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 (42) hide show
  1. package/LICENSE +107 -0
  2. package/dist/ReportPreview-BFTfls8h.js +923 -0
  3. package/dist/ReportPreview-D6VHDUvR.cjs +6 -0
  4. package/dist/format.d.ts +48 -0
  5. package/dist/grid-geometry-BXpOxznT.cjs +1 -0
  6. package/dist/grid-geometry-Bs8QXz1X.js +65 -0
  7. package/dist/index.cjs +6 -6
  8. package/dist/index.d.cts +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +858 -660
  11. package/dist/layout/paginate.d.ts +30 -2
  12. package/dist/pdf.cjs +46 -46
  13. package/dist/pdf.js +8 -7
  14. package/dist/{plugin-Cl-IqCqx.cjs → plugin-9eBK7khj.cjs} +1 -1
  15. package/dist/{plugin-Dp3kKWiQ.js → plugin-vi2GjP43.js} +3 -3
  16. package/dist/style-6ihHKVCM.js +192 -0
  17. package/dist/style-Xq08-IsV.cjs +3 -0
  18. package/dist/style.css +1 -1
  19. package/dist/vue/ReportPreview.d.ts +13 -0
  20. package/dist/vue/ReportToolbar.d.ts +20 -3
  21. package/dist/vue/async.d.cts +16 -0
  22. package/dist/vue/async.d.ts +16 -0
  23. package/dist/vue/composables/useHighlight.d.ts +8 -0
  24. package/dist/vue/composables/usePageWindow.d.ts +0 -3
  25. package/dist/vue/composables/usePrintExport.d.ts +8 -0
  26. package/dist/vue/composables/useReportSearch.d.ts +72 -0
  27. package/dist/vue/config.d.ts +17 -1
  28. package/dist/vue/plugin.d.ts +16 -0
  29. package/dist/vue-async.cjs +1 -1
  30. package/dist/vue-async.js +3 -3
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.js +35 -33
  33. package/dist/xlsx/render-xlsx.d.ts +20 -0
  34. package/dist/xlsx.cjs +30 -0
  35. package/dist/xlsx.d.cts +5 -0
  36. package/dist/xlsx.d.ts +5 -0
  37. package/dist/xlsx.js +22648 -0
  38. package/package.json +15 -2
  39. package/dist/ReportPreview-CrVeTKu1.cjs +0 -6
  40. package/dist/ReportPreview-DgsOdO4y.js +0 -559
  41. package/dist/style-B3vxGDZd.cjs +0 -3
  42. package/dist/style-B7Xfo5I-.js +0 -255
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agile-team/mach-report",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "MachReport 报表引擎单包:RenderPlan 模型 + 分页 + DOM/Canvas/PDF 渲染 + 动态 SQL + 管理端 API + Vue 3 契约组件(零运行时依赖;./vue 为框架子路径,vue 为可选 peer)",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -70,7 +70,17 @@
70
70
  "default": "./dist/vue-async.cjs"
71
71
  }
72
72
  },
73
- "./vue/style.css": "./dist/style.css"
73
+ "./vue/style.css": "./dist/style.css",
74
+ "./xlsx": {
75
+ "import": {
76
+ "types": "./dist/xlsx.d.ts",
77
+ "default": "./dist/xlsx.js"
78
+ },
79
+ "require": {
80
+ "types": "./dist/xlsx.d.cts",
81
+ "default": "./dist/xlsx.cjs"
82
+ }
83
+ }
74
84
  },
75
85
  "publishConfig": {
76
86
  "access": "public"
@@ -93,6 +103,7 @@
93
103
  "@pdf-lib/fontkit": "^1.1.1",
94
104
  "@vitejs/plugin-vue": "^6.0.9",
95
105
  "@vue/test-utils": "^2.4.0",
106
+ "exceljs": "^4.4.0",
96
107
  "node-sql-parser": "^5.4.0",
97
108
  "pdf-lib": "^1.17.1",
98
109
  "typescript": "^5.9.0",
@@ -101,6 +112,8 @@
101
112
  "vue": "^3.5.0",
102
113
  "vue-tsc": "^3.0.0"
103
114
  },
115
+ "license": "SEE LICENSE IN LICENSE",
116
+ "author": "ChenyCHENYU (Agile Team)",
104
117
  "scripts": {
105
118
  "build": "vite build && node scripts/copy-dcts.mjs",
106
119
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\""
@@ -1,6 +0,0 @@
1
- "use strict";const e=require("vue"),N=require("@agile-team/mach-report"),E=require("./plugin-Cl-IqCqx.cjs");function Z(t,n,r={}){const o=r.pxPerMm??3.7795275590551185,a=r.gapPx??18,s=e.ref(0),c=e.ref(800),v=e.computed(()=>(t.value?.pages??[]).map(l=>l.pageHeightMm*o)),b=e.computed(()=>{const l=t.value?.pages??[];let p=0,i=0;for(const d of l)p+=d.pageHeightMm*o+a,i=Math.max(i,d.pageWidthMm*o);return{w:i,h:p}}),x=e.computed(()=>N.computePageWindow({pageHeightsPx:v.value,viewportHeightPx:c.value/n.value,scrollTopPx:s.value/n.value,overscan:1,gapPx:a})),P=e.computed(()=>{const l=t.value;if(!l)return[];const{start:p,end:i}=x.value;return i<p?[]:l.pages.slice(p,i+1).map((d,m)=>({page:d,index:p+m}))});function u(l,p){let i=0;return d=>{i||(i=requestAnimationFrame(()=>{if(i=0,s.value=d.scrollTop,c.value=d.clientHeight||800,p.value<=0)return;const m=d.querySelectorAll(".mrp-page-holder");if(!m.length)return;const M=d.getBoundingClientRect().top+56;let y=1;m.forEach(k=>{k.getBoundingClientRect().top<=M&&(y=Number(k.dataset.page??1))}),l.value=Math.max(1,Math.min(p.value,y))}))}}return{pageHeightsPx:v,contentSize:b,windowRange:x,visiblePages:P,scrollTop:s,viewportHeight:c,makeScrollHandler:u,refreshViewport(l){l&&(c.value=l.clientHeight||800)}}}function X(t){const n=e.ref(1),r=e.ref("fit");function o(){requestAnimationFrame(()=>{const s=t();!s||!s.viewport||(n.value=Math.min(1,Math.max(.3,(s.viewport.clientWidth-48)/Math.max(1,s.pageWidthPx))))})}function a(s){s==="fit"?(r.value="fit",o()):(r.value="raw",n.value=s/100)}return{zoom:n,zoomMode:r,applyFitZoom:o,setZoom:a}}const K=8;function Y(){return new Promise(t=>setTimeout(t,0))}function H(t){return`p${Math.round(t.pageWidthMm)}x${Math.round(t.pageHeightMm)}`}function D(t){const n=new Map;t.pages.forEach(c=>{n.has(H(c))||n.set(H(c),c)});const a=`<!doctype html><html><head><meta charset="utf-8"><style>${`.mr-page{margin:0 auto;page-break-after:always;}
2
- .mr-page tr{break-inside:avoid;page-break-inside:avoid;}
3
- .mr-comp{break-inside:avoid;page-break-inside:avoid;}
4
- ${[...n.values()].map(c=>`@page ${H(c)}{size:${Math.round(c.pageWidthMm)}mm ${Math.round(c.pageHeightMm)}mm;margin:0;}`).join(`
5
- `)}
6
- body{margin:0;background:#fff;}`}</style></head><body>`,s=t.pages.map(c=>{const v=N.renderPage(c,96,{},document);return v.style.page=H(c),v.outerHTML});return{head:a,pageChunks:s}}function J(t,n){let r=null,o=!1,a=null;function s(){r?.remove(),r=null}function c(u,l){const p=URL.createObjectURL(u),i=document.createElement("a");i.href=p,i.download=l,i.click(),setTimeout(()=>URL.revokeObjectURL(p),1e4)}async function v(){if(o)return;const u=t.value;if(!u||u.pages.length===0)return;o=!0,s();const{head:l,pageChunks:p}=D(u);r=document.createElement("iframe"),r.style.cssText="position:fixed;right:0;bottom:0;width:0;height:0;border:0;visibility:hidden;",document.body.appendChild(r);const i=r;try{const d=i.contentDocument;d.open(),d.write(l);for(let m=0;m<p.length;m++)if(d.write(p[m]),m%K===K-1&&await Y(),i!==r)return;d.write("</body></html>"),d.close(),await Y(),i.contentWindow?.focus(),i.contentWindow?.print()}catch{n.onError("调用打印失败,请改用导出 PDF")}finally{o=!1}}async function b(){if(a)return a;const u=t.value;if(!(!u||u.pages.length===0))return a=(async()=>{try{const l=await n.getPdfExporter()(u);c(new Blob([l],{type:"application/pdf"}),"mach-report.pdf")}catch(l){n.onError(l instanceof Error?`PDF 导出失败: ${l.message}`:"PDF 导出失败")}finally{a=null}})(),a}function x(u){const l=t.value;if(!l||l.pages.length===0)return;if(u==="pdf"){b();return}const{head:p,pageChunks:i}=D(l),d=`${p}${i.join("")}</body></html>`;c(new Blob([d],{type:"text/html;charset=utf-8"}),`mach-report.${u==="html"?"html":u}`)}function P(){const u=t.value;if(!u||u.pages.length===0)return;const{head:l,pageChunks:p}=D(u),i=`${l}${p.join("")}</body></html>`,d=new Blob([i],{type:"text/html;charset=utf-8"}),m=URL.createObjectURL(d),M=window.open(m,"_blank");if(!M){n.onError("浏览器拦截了弹窗,请允许弹窗后重试"),URL.revokeObjectURL(m);return}setTimeout(()=>M.print(),400),setTimeout(()=>URL.revokeObjectURL(m),1e4)}return{print:v,exportAs:x,openPdfWindow:P,releasePrintFrame:s}}const be={class:"mrp-toolbar"},ye={class:"mrp-title"},Ee=["disabled"],xe={class:"mrp-pageinfo"},ke=["disabled"],Be=e.defineComponent({__name:"ReportToolbar",props:{pageCount:{},currentPage:{},zoomMode:{},zoom:{},showExport:{type:Boolean},showPrint:{type:Boolean},showPdfWindow:{type:Boolean},messages:{}},emits:["goto","zoom","export","print","pdf-window"],setup(t){function n(r,o,a){return r.replace("{cur}",String(o)).replace("{total}",String(a))}return(r,o)=>(e.openBlock(),e.createElementBlock("div",be,[e.createElementVNode("span",ye,e.toDisplayString(t.messages.title),1),t.pageCount>0?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("button",{class:"mrp-nav",type:"button",disabled:t.currentPage<=1,onClick:o[0]||(o[0]=a=>r.$emit("goto",t.currentPage-1))},e.toDisplayString(t.messages.prevPage),9,Ee),e.createElementVNode("span",xe,e.toDisplayString(n(t.messages.pageInfo,t.currentPage,t.pageCount)),1),e.createElementVNode("button",{class:"mrp-nav",type:"button",disabled:t.currentPage>=t.pageCount,onClick:o[1]||(o[1]=a=>r.$emit("goto",t.currentPage+1))},e.toDisplayString(t.messages.nextPage),9,ke)],64)):e.createCommentVNode("",!0),o[9]||(o[9]=e.createElementVNode("span",{class:"mrp-spacer"},null,-1)),e.createElementVNode("button",{class:e.normalizeClass(["mrp-nav",{"mrp-active":t.zoomMode==="fit"}]),type:"button",onClick:o[2]||(o[2]=a=>r.$emit("zoom","fit"))},e.toDisplayString(t.messages.fitWidth),3),e.createElementVNode("button",{class:e.normalizeClass(["mrp-nav",{"mrp-active":t.zoomMode==="raw"&&Math.round(t.zoom*100)===100}]),type:"button",onClick:o[3]||(o[3]=a=>r.$emit("zoom",100))}," 100% ",2),e.createElementVNode("button",{class:e.normalizeClass(["mrp-nav",{"mrp-active":t.zoomMode==="raw"&&Math.round(t.zoom*100)===150}]),type:"button",onClick:o[4]||(o[4]=a=>r.$emit("zoom",150))}," 150% ",2),t.showExport?(e.openBlock(),e.createElementBlock("button",{key:1,class:"mrp-nav",type:"button",onClick:o[5]||(o[5]=a=>r.$emit("export","html"))},e.toDisplayString(t.messages.exportHtml),1)):e.createCommentVNode("",!0),t.showExport?(e.openBlock(),e.createElementBlock("button",{key:2,class:"mrp-nav",type:"button",onClick:o[6]||(o[6]=a=>r.$emit("export","pdf"))},e.toDisplayString(t.messages.exportPdf),1)):e.createCommentVNode("",!0),t.showPrint?(e.openBlock(),e.createElementBlock("button",{key:3,class:"mrp-nav",type:"button",onClick:o[7]||(o[7]=a=>r.$emit("print"))},e.toDisplayString(t.messages.print),1)):e.createCommentVNode("",!0),t.showPdfWindow?(e.openBlock(),e.createElementBlock("button",{key:4,class:"mrp-nav",type:"button",onClick:o[8]||(o[8]=a=>r.$emit("pdf-window"))},e.toDisplayString(t.messages.pdfWindow),1)):e.createCommentVNode("",!0)]))}}),Q=(t,n)=>{const r=t.__vccOpts||t;for(const[o,a]of n)r[o]=a;return r},_=Q(Be,[["__scopeId","data-v-2bfb2c61"]]),ee={title:"报表预览",prevPage:"‹ 上一页",nextPage:"下一页 ›",pageInfo:"{cur} / {total}",fitWidth:"适宽",exportHtml:"导出 HTML",exportPdf:"导出 PDF",print:"打印",pdfWindow:"PDF 窗口",loading:"报表渲染中…",empty:"暂无预览数据",errorPrefix:"",retry:"重试"},te={shellBg:"#525659",shellFg:"#e8e8e8",toolbarBg:"#323639",toolbarBorder:"#22252a",toolbarFg:"#e8e8e8",btnFg:"#cfcfcf",btnBorder:"#4a4d52",btnHoverBg:"#414549",btnHoverFg:"#ffffff",btnActiveBg:"#2d5fb8"};function Me(t){return t}function Re(t){return t}const S={showExport:!0,showPrint:!0,showPdfWindow:!0,gapPx:18,pdfFontUrl:"/simhei.ttf"};function oe(t,n){const r=n?t?.presets?.[n]:t?.defaultPreset?t?.presets?.[t.defaultPreset]:void 0,o={...t?.defaults,...r};return{showExport:o.showExport??S.showExport,showPrint:o.showPrint??S.showPrint,showPdfWindow:o.showPdfWindow??S.showPdfWindow,gapPx:o.gapPx??S.gapPx,pdfFontUrl:o.pdfFontUrl??S.pdfFontUrl,theme:{...te,...o.theme},messages:{...ee,...o.messages}}}function ne(t){const n={};return t.shellBg!=null&&(n["--mrp-shell-bg"]=t.shellBg),t.shellFg!=null&&(n["--mrp-shell-fg"]=t.shellFg),t.toolbarBg!=null&&(n["--mrp-toolbar-bg"]=t.toolbarBg),t.toolbarBorder!=null&&(n["--mrp-toolbar-border"]=t.toolbarBorder),t.toolbarFg!=null&&(n["--mrp-toolbar-fg"]=t.toolbarFg),t.btnFg!=null&&(n["--mrp-btn-fg"]=t.btnFg),t.btnBorder!=null&&(n["--mrp-btn-border"]=t.btnBorder),t.btnHoverBg!=null&&(n["--mrp-btn-hover-bg"]=t.btnHoverBg),t.btnHoverFg!=null&&(n["--mrp-btn-hover-fg"]=t.btnHoverFg),t.btnActiveBg!=null&&(n["--mrp-btn-active-bg"]=t.btnActiveBg),n}function Ce(t){const n=e.inject(E.MACH_REPORT_CONFIG_KEY,null),r=e.computed(()=>{const o=n?.value??null,a="defaults"in t&&"presets"in t?t:{defaults:t,presets:{}};return o?{defaults:{...o.defaults,...a.defaults},presets:{...o.presets,...a.presets},defaultPreset:a.defaultPreset??o.defaultPreset}:a});e.provide(E.MACH_REPORT_CONFIG_KEY,r)}function re(){return e.inject(E.MACH_REPORT_CONFIG_KEY,e.computed(()=>null))}class F extends Error{constructor(n,r,o){super(r),this.name="MachReportError",this.code=n,this.cause=o}}function ae(t){return t instanceof F?{code:t.code,cause:t.cause}:{code:"render",cause:t}}const $e={key:0,class:"mrp-state"},Se={key:1,class:"mrp-state mrp-error"},Fe={key:2,class:"mrp-state"},Te=["data-page"],ze={class:"mrp-overlay"},W=96/25.4,He=e.defineComponent({__name:"ReportPreview",props:{tempId:{type:[String,Array],default:null},furnitureTempId:{type:String,default:""},params:{type:Object,default:()=>({})},height:{type:String,default:"100vh"},autoLoad:{type:Boolean,default:!0},showExport:{type:Boolean,default:void 0},showPrint:{type:Boolean,default:void 0},showPdfWindow:{type:Boolean,default:void 0},gapPx:{type:Number,default:void 0},messages:{type:Object,default:void 0},preset:{type:String,default:void 0},fetcher:{type:Function,default:null}},emits:["loaded","error"],setup(t,{expose:n,emit:r}){e.useCssVars(h=>({v8289d092:u.value+"px"}));const o=t,a=r,s=e.shallowRef(null),c=e.ref(!1),v=e.ref(""),b=e.ref(1),x=e.ref(null),P=e.ref(null),u=e.computed(()=>Math.max(0,ce.value)),l=e.inject(E.MACH_REPORT_FETCHER_KEY,null),i=e.inject(E.MACH_REPORT_PDF_EXPORTER_KEY,null)??E.createDefaultPdfExporter({fontUrl:"/simhei.ttf"}),d=e.computed(()=>E.normalizeTempIds(o.tempId)),m=e.computed(()=>s.value?.pages.length??0),M=re(),y=e.computed(()=>oe(M.value,o.preset)),k=e.computed(()=>({...y.value.messages,...o.messages})),se=e.computed(()=>o.showExport??y.value.showExport),ie=e.computed(()=>o.showPrint??y.value.showPrint),ue=e.computed(()=>o.showPdfWindow??y.value.showPdfWindow),ce=e.computed(()=>o.gapPx??y.value.gapPx),de=e.computed(()=>({height:o.height,...ne(y.value.theme)})),{zoom:R,zoomMode:pe,applyFitZoom:U,setZoom:fe}=X(()=>({viewport:P.value,pageWidthPx:(s.value?.pages[0]?.pageWidthMm??210)*W})),me=Z(s,R,{pxPerMm:W,gapPx:u.value}),{contentSize:L,windowRange:T,visiblePages:ge,makeScrollHandler:ve,refreshViewport:G}=me,he=ve(b,m);function V(){s.value=null,b.value=1}let z=0;async function C(){const h=++z,w=o.fetcher??l;if(d.value.length===0){v.value="缺少报表模板 ID",V(),a("error",v.value,{code:"param"});return}if(!w){v.value="未提供渲染数据源 fetcher",V(),a("error",v.value,{code:"config"});return}c.value=!0,v.value="",V();try{const f=await w({tempIds:d.value,furnitureTempId:o.furnitureTempId||void 0,params:{...o.params}});if(h!==z)return;const g=N.validateRenderPlan(f);if(!g.ok){const B=g.errors.slice(0,3).map($=>`${$.path}: ${$.message}`).join("; ");throw new F("validate",`渲染计划校验失败(${g.errors.length} 处): ${B}`)}g.warnings.length>0&&console.warn("[mach-report] 渲染计划告警:",g.warnings),s.value=f,b.value=1,P.value&&(P.value.scrollTop=0),U(),a("loaded",f.pages.length)}catch(f){if(h!==z)return;const g=f instanceof F?f:new F("fetch",f instanceof Error?f.message:"预览加载失败",f);v.value=g.message,a("error",g.message,ae(g))}finally{h===z&&(c.value=!1)}}function A(h){if(m.value<=0)return;const w=Math.max(1,Math.min(m.value,h));b.value=w;const f=P.value;if(!f)return;let g=0;for(let B=0;B<w-1;B++)g+=(s.value?.pages[B]?.pageHeightMm??0)*W+u.value;f.scrollTop=g*R.value}const{print:O,exportAs:I,openPdfWindow:j,releasePrintFrame:we}=J(s,{getPdfExporter:()=>i,onError:h=>a("error",h,{code:"print"})}),Pe={reload:C,print:O,exportAs:I,openPdfWindow:j,gotoPage:A};e.provide(E.MACH_REPORT_CONTROLLER_KEY,Pe),e.watchEffect(()=>{const h=s.value;if(!h)return;const w=x.value;if(!w)return;w.querySelectorAll(".mrp-page-holder").forEach(g=>{const B=Number(g.dataset.page??0)-1,$=h.pages[B];!$||g.childElementCount>0||(g.style.width=`${$.pageWidthMm*W}px`,g.appendChild(N.renderPage($,96,{},document)))})},{flush:"post"});function q(){G(P.value),U()}return e.onMounted(()=>{window.addEventListener("resize",q),G(P.value),o.autoLoad&&C()}),e.onUnmounted(()=>{window.removeEventListener("resize",q),we()}),e.watch(()=>[o.tempId,o.furnitureTempId,JSON.stringify(o.params)],()=>{o.autoLoad&&C()}),e.watch(()=>o.fetcher??l,()=>{o.autoLoad&&C()}),n({reload:C,print:O,exportAs:I,openPdfWindow:j,gotoPage:A}),(h,w)=>(e.openBlock(),e.createElementBlock("div",{class:"mach-report-preview",style:e.normalizeStyle(de.value)},[e.createVNode(_,{"page-count":m.value,"current-page":b.value,"zoom-mode":e.unref(pe),zoom:e.unref(R),"show-export":se.value,"show-print":ie.value,"show-pdf-window":ue.value,messages:k.value,onGoto:A,onZoom:e.unref(fe),onExport:w[0]||(w[0]=f=>e.unref(I)(f)),onPrint:e.unref(O),onPdfWindow:e.unref(j)},null,8,["page-count","current-page","zoom-mode","zoom","show-export","show-print","show-pdf-window","messages","onZoom","onPrint","onPdfWindow"]),e.createElementVNode("div",{ref_key:"viewportRef",ref:P,class:"mrp-body",onScrollPassive:w[1]||(w[1]=f=>e.unref(he)(f.target))},[c.value?(e.openBlock(),e.createElementBlock("div",$e,e.toDisplayString(k.value.loading),1)):v.value?(e.openBlock(),e.createElementBlock("div",Se,[e.createTextVNode(e.toDisplayString(v.value)+" ",1),e.createElementVNode("button",{class:"mrp-retry",type:"button",onClick:C},e.toDisplayString(k.value.retry),1)])):!s.value||m.value===0?(e.openBlock(),e.createElementBlock("div",Fe,e.toDisplayString(k.value.empty),1)):(e.openBlock(),e.createElementBlock("div",{key:3,class:"mrp-scale",style:e.normalizeStyle({width:`${e.unref(L).w*e.unref(R)}px`,height:`${e.unref(L).h*e.unref(R)}px`})},[e.createElementVNode("div",{ref_key:"containerRef",ref:x,class:"mrp-scale-inner",style:e.normalizeStyle({transform:`scale(${e.unref(R)})`,transformOrigin:"top left",width:`${e.unref(L).w}px`})},[e.unref(T).padTopPx>0?(e.openBlock(),e.createElementBlock("div",{key:0,class:"mrp-spacer-top",style:e.normalizeStyle({height:`${e.unref(T).padTopPx}px`}),"aria-hidden":"true"},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(ge),f=>(e.openBlock(),e.createElementBlock("div",{key:f.index,class:"mrp-page-holder","data-page":f.index+1},null,8,Te))),128)),e.unref(T).padBottomPx>0?(e.openBlock(),e.createElementBlock("div",{key:1,class:"mrp-spacer-bottom",style:e.normalizeStyle({height:`${e.unref(T).padBottomPx}px`}),"aria-hidden":"true"},null,4)):e.createCommentVNode("",!0)],4)],4))],544),e.createElementVNode("div",ze,[e.renderSlot(h.$slots,"default",{},void 0,!0)])],4))}}),le=Q(He,[["__scopeId","data-v-6e07f84a"]]),We=Object.freeze(Object.defineProperty({__proto__:null,default:le},Symbol.toStringTag,{value:"Module"}));exports.DEFAULT_MESSAGES=ee;exports.DEFAULT_THEME=te;exports.MachReportError=F;exports.ReportPreview=le;exports.ReportPreview$1=We;exports.ReportToolbar=_;exports.buildPrintDocument=D;exports.defineMachReportConfig=Me;exports.defineMachReportPreset=Re;exports.provideMachReportConfig=Ce;exports.resolveConfig=oe;exports.themeToCssVars=ne;exports.toErrorDetail=ae;exports.useMachReportConfig=re;exports.usePageWindow=Z;exports.usePrintExport=J;exports.useZoom=X;
@@ -1,559 +0,0 @@
1
- import { ref as k, computed as h, defineComponent as ae, openBlock as w, createElementBlock as b, createElementVNode as E, toDisplayString as x, Fragment as se, createCommentVNode as T, normalizeClass as X, inject as N, provide as le, useCssVars as xe, shallowRef as Ee, watchEffect as Me, onMounted as Re, onUnmounted as $e, watch as oe, normalizeStyle as L, createVNode as ke, unref as m, createTextVNode as Ce, renderList as Fe, renderSlot as Be } from "vue";
2
- import { computePageWindow as Te, renderPage as ie, validateRenderPlan as ze } from "@agile-team/mach-report";
3
- import { a as Q, b as We, c as Se, n as He, M as Le, e as Ae } from "./plugin-Dp3kKWiQ.js";
4
- function Oe(e, o, n = {}) {
5
- const t = n.pxPerMm ?? 3.7795275590551185, r = n.gapPx ?? 18, s = k(0), u = k(800), v = h(
6
- () => (e.value?.pages ?? []).map((a) => a.pageHeightMm * t)
7
- ), R = h(() => {
8
- const a = e.value?.pages ?? [];
9
- let c = 0, l = 0;
10
- for (const d of a)
11
- c += d.pageHeightMm * t + r, l = Math.max(l, d.pageWidthMm * t);
12
- return { w: l, h: c };
13
- }), C = h(
14
- () => Te({
15
- pageHeightsPx: v.value,
16
- viewportHeightPx: u.value / o.value,
17
- scrollTopPx: s.value / o.value,
18
- overscan: 1,
19
- gapPx: r
20
- })
21
- ), M = h(() => {
22
- const a = e.value;
23
- if (!a) return [];
24
- const { start: c, end: l } = C.value;
25
- return l < c ? [] : a.pages.slice(c, l + 1).map((d, f) => ({ page: d, index: c + f }));
26
- });
27
- function i(a, c) {
28
- let l = 0;
29
- return (d) => {
30
- l || (l = requestAnimationFrame(() => {
31
- if (l = 0, s.value = d.scrollTop, u.value = d.clientHeight || 800, c.value <= 0) return;
32
- const f = d.querySelectorAll(".mrp-page-holder");
33
- if (!f.length) return;
34
- const z = d.getBoundingClientRect().top + 56;
35
- let $ = 1;
36
- f.forEach((F) => {
37
- F.getBoundingClientRect().top <= z && ($ = Number(F.dataset.page ?? 1));
38
- }), a.value = Math.max(1, Math.min(c.value, $));
39
- }));
40
- };
41
- }
42
- return {
43
- pageHeightsPx: v,
44
- contentSize: R,
45
- windowRange: C,
46
- visiblePages: M,
47
- scrollTop: s,
48
- viewportHeight: u,
49
- makeScrollHandler: i,
50
- refreshViewport(a) {
51
- a && (u.value = a.clientHeight || 800);
52
- }
53
- };
54
- }
55
- function Ie(e) {
56
- const o = k(1), n = k("fit");
57
- function t() {
58
- requestAnimationFrame(() => {
59
- const s = e();
60
- !s || !s.viewport || (o.value = Math.min(
61
- 1,
62
- Math.max(0.3, (s.viewport.clientWidth - 48) / Math.max(1, s.pageWidthPx))
63
- ));
64
- });
65
- }
66
- function r(s) {
67
- s === "fit" ? (n.value = "fit", t()) : (n.value = "raw", o.value = s / 100);
68
- }
69
- return { zoom: o, zoomMode: n, applyFitZoom: t, setZoom: r };
70
- }
71
- const ne = 8;
72
- function re() {
73
- return new Promise((e) => setTimeout(e, 0));
74
- }
75
- function j(e) {
76
- return `p${Math.round(e.pageWidthMm)}x${Math.round(e.pageHeightMm)}`;
77
- }
78
- function J(e) {
79
- const o = /* @__PURE__ */ new Map();
80
- e.pages.forEach((u) => {
81
- o.has(j(u)) || o.set(j(u), u);
82
- });
83
- const r = `<!doctype html><html><head><meta charset="utf-8"><style>${`.mr-page{margin:0 auto;page-break-after:always;}
84
- .mr-page tr{break-inside:avoid;page-break-inside:avoid;}
85
- .mr-comp{break-inside:avoid;page-break-inside:avoid;}
86
- ${[...o.values()].map(
87
- (u) => `@page ${j(u)}{size:${Math.round(u.pageWidthMm)}mm ${Math.round(u.pageHeightMm)}mm;margin:0;}`
88
- ).join(`
89
- `)}
90
- body{margin:0;background:#fff;}`}</style></head><body>`, s = e.pages.map((u) => {
91
- const v = ie(u, 96, {}, document);
92
- return v.style.page = j(u), v.outerHTML;
93
- });
94
- return { head: r, pageChunks: s };
95
- }
96
- function je(e, o) {
97
- let n = null, t = !1, r = null;
98
- function s() {
99
- n?.remove(), n = null;
100
- }
101
- function u(i, a) {
102
- const c = URL.createObjectURL(i), l = document.createElement("a");
103
- l.href = c, l.download = a, l.click(), setTimeout(() => URL.revokeObjectURL(c), 1e4);
104
- }
105
- async function v() {
106
- if (t) return;
107
- const i = e.value;
108
- if (!i || i.pages.length === 0) return;
109
- t = !0, s();
110
- const { head: a, pageChunks: c } = J(i);
111
- n = document.createElement("iframe"), n.style.cssText = "position:fixed;right:0;bottom:0;width:0;height:0;border:0;visibility:hidden;", document.body.appendChild(n);
112
- const l = n;
113
- try {
114
- const d = l.contentDocument;
115
- d.open(), d.write(a);
116
- for (let f = 0; f < c.length; f++)
117
- if (d.write(c[f]), f % ne === ne - 1 && await re(), l !== n) return;
118
- d.write("</body></html>"), d.close(), await re(), l.contentWindow?.focus(), l.contentWindow?.print();
119
- } catch {
120
- o.onError("调用打印失败,请改用导出 PDF");
121
- } finally {
122
- t = !1;
123
- }
124
- }
125
- async function R() {
126
- if (r) return r;
127
- const i = e.value;
128
- if (!(!i || i.pages.length === 0))
129
- return r = (async () => {
130
- try {
131
- const a = await o.getPdfExporter()(i);
132
- u(
133
- new Blob([a], { type: "application/pdf" }),
134
- "mach-report.pdf"
135
- );
136
- } catch (a) {
137
- o.onError(a instanceof Error ? `PDF 导出失败: ${a.message}` : "PDF 导出失败");
138
- } finally {
139
- r = null;
140
- }
141
- })(), r;
142
- }
143
- function C(i) {
144
- const a = e.value;
145
- if (!a || a.pages.length === 0) return;
146
- if (i === "pdf") {
147
- R();
148
- return;
149
- }
150
- const { head: c, pageChunks: l } = J(a), d = `${c}${l.join("")}</body></html>`;
151
- u(new Blob([d], { type: "text/html;charset=utf-8" }), `mach-report.${i === "html" ? "html" : i}`);
152
- }
153
- function M() {
154
- const i = e.value;
155
- if (!i || i.pages.length === 0) return;
156
- const { head: a, pageChunks: c } = J(i), l = `${a}${c.join("")}</body></html>`, d = new Blob([l], { type: "text/html;charset=utf-8" }), f = URL.createObjectURL(d), z = window.open(f, "_blank");
157
- if (!z) {
158
- o.onError("浏览器拦截了弹窗,请允许弹窗后重试"), URL.revokeObjectURL(f);
159
- return;
160
- }
161
- setTimeout(() => z.print(), 400), setTimeout(() => URL.revokeObjectURL(f), 1e4);
162
- }
163
- return {
164
- print: v,
165
- exportAs: C,
166
- openPdfWindow: M,
167
- releasePrintFrame: s
168
- };
169
- }
170
- const Ue = { class: "mrp-toolbar" }, De = { class: "mrp-title" }, Ne = ["disabled"], Ve = { class: "mrp-pageinfo" }, Ge = ["disabled"], Ke = /* @__PURE__ */ ae({
171
- __name: "ReportToolbar",
172
- props: {
173
- pageCount: {},
174
- currentPage: {},
175
- zoomMode: {},
176
- zoom: {},
177
- showExport: { type: Boolean },
178
- showPrint: { type: Boolean },
179
- showPdfWindow: { type: Boolean },
180
- messages: {}
181
- },
182
- emits: ["goto", "zoom", "export", "print", "pdf-window"],
183
- setup(e) {
184
- function o(n, t, r) {
185
- return n.replace("{cur}", String(t)).replace("{total}", String(r));
186
- }
187
- return (n, t) => (w(), b("div", Ue, [
188
- E("span", De, x(e.messages.title), 1),
189
- e.pageCount > 0 ? (w(), b(se, { key: 0 }, [
190
- E("button", {
191
- class: "mrp-nav",
192
- type: "button",
193
- disabled: e.currentPage <= 1,
194
- onClick: t[0] || (t[0] = (r) => n.$emit("goto", e.currentPage - 1))
195
- }, x(e.messages.prevPage), 9, Ne),
196
- E("span", Ve, x(o(e.messages.pageInfo, e.currentPage, e.pageCount)), 1),
197
- E("button", {
198
- class: "mrp-nav",
199
- type: "button",
200
- disabled: e.currentPage >= e.pageCount,
201
- onClick: t[1] || (t[1] = (r) => n.$emit("goto", e.currentPage + 1))
202
- }, x(e.messages.nextPage), 9, Ge)
203
- ], 64)) : T("", !0),
204
- t[9] || (t[9] = E("span", { class: "mrp-spacer" }, null, -1)),
205
- E("button", {
206
- class: X(["mrp-nav", { "mrp-active": e.zoomMode === "fit" }]),
207
- type: "button",
208
- onClick: t[2] || (t[2] = (r) => n.$emit("zoom", "fit"))
209
- }, x(e.messages.fitWidth), 3),
210
- E("button", {
211
- class: X(["mrp-nav", { "mrp-active": e.zoomMode === "raw" && Math.round(e.zoom * 100) === 100 }]),
212
- type: "button",
213
- onClick: t[3] || (t[3] = (r) => n.$emit("zoom", 100))
214
- }, " 100% ", 2),
215
- E("button", {
216
- class: X(["mrp-nav", { "mrp-active": e.zoomMode === "raw" && Math.round(e.zoom * 100) === 150 }]),
217
- type: "button",
218
- onClick: t[4] || (t[4] = (r) => n.$emit("zoom", 150))
219
- }, " 150% ", 2),
220
- e.showExport ? (w(), b("button", {
221
- key: 1,
222
- class: "mrp-nav",
223
- type: "button",
224
- onClick: t[5] || (t[5] = (r) => n.$emit("export", "html"))
225
- }, x(e.messages.exportHtml), 1)) : T("", !0),
226
- e.showExport ? (w(), b("button", {
227
- key: 2,
228
- class: "mrp-nav",
229
- type: "button",
230
- onClick: t[6] || (t[6] = (r) => n.$emit("export", "pdf"))
231
- }, x(e.messages.exportPdf), 1)) : T("", !0),
232
- e.showPrint ? (w(), b("button", {
233
- key: 3,
234
- class: "mrp-nav",
235
- type: "button",
236
- onClick: t[7] || (t[7] = (r) => n.$emit("print"))
237
- }, x(e.messages.print), 1)) : T("", !0),
238
- e.showPdfWindow ? (w(), b("button", {
239
- key: 4,
240
- class: "mrp-nav",
241
- type: "button",
242
- onClick: t[8] || (t[8] = (r) => n.$emit("pdf-window"))
243
- }, x(e.messages.pdfWindow), 1)) : T("", !0)
244
- ]));
245
- }
246
- }), ue = (e, o) => {
247
- const n = e.__vccOpts || e;
248
- for (const [t, r] of o)
249
- n[t] = r;
250
- return n;
251
- }, Ze = /* @__PURE__ */ ue(Ke, [["__scopeId", "data-v-2bfb2c61"]]), qe = {
252
- title: "报表预览",
253
- prevPage: "‹ 上一页",
254
- nextPage: "下一页 ›",
255
- pageInfo: "{cur} / {total}",
256
- fitWidth: "适宽",
257
- exportHtml: "导出 HTML",
258
- exportPdf: "导出 PDF",
259
- print: "打印",
260
- pdfWindow: "PDF 窗口",
261
- loading: "报表渲染中…",
262
- empty: "暂无预览数据",
263
- errorPrefix: "",
264
- retry: "重试"
265
- }, Ye = {
266
- shellBg: "#525659",
267
- shellFg: "#e8e8e8",
268
- toolbarBg: "#323639",
269
- toolbarBorder: "#22252a",
270
- toolbarFg: "#e8e8e8",
271
- btnFg: "#cfcfcf",
272
- btnBorder: "#4a4d52",
273
- btnHoverBg: "#414549",
274
- btnHoverFg: "#ffffff",
275
- btnActiveBg: "#2d5fb8"
276
- };
277
- function ct(e) {
278
- return e;
279
- }
280
- function pt(e) {
281
- return e;
282
- }
283
- const A = {
284
- showExport: !0,
285
- showPrint: !0,
286
- showPdfWindow: !0,
287
- gapPx: 18,
288
- pdfFontUrl: "/simhei.ttf"
289
- };
290
- function Xe(e, o) {
291
- const n = o ? e?.presets?.[o] : e?.defaultPreset ? e?.presets?.[e.defaultPreset] : void 0, t = { ...e?.defaults, ...n };
292
- return {
293
- showExport: t.showExport ?? A.showExport,
294
- showPrint: t.showPrint ?? A.showPrint,
295
- showPdfWindow: t.showPdfWindow ?? A.showPdfWindow,
296
- gapPx: t.gapPx ?? A.gapPx,
297
- pdfFontUrl: t.pdfFontUrl ?? A.pdfFontUrl,
298
- theme: { ...Ye, ...t.theme },
299
- messages: { ...qe, ...t.messages }
300
- };
301
- }
302
- function Je(e) {
303
- const o = {};
304
- return e.shellBg != null && (o["--mrp-shell-bg"] = e.shellBg), e.shellFg != null && (o["--mrp-shell-fg"] = e.shellFg), e.toolbarBg != null && (o["--mrp-toolbar-bg"] = e.toolbarBg), e.toolbarBorder != null && (o["--mrp-toolbar-border"] = e.toolbarBorder), e.toolbarFg != null && (o["--mrp-toolbar-fg"] = e.toolbarFg), e.btnFg != null && (o["--mrp-btn-fg"] = e.btnFg), e.btnBorder != null && (o["--mrp-btn-border"] = e.btnBorder), e.btnHoverBg != null && (o["--mrp-btn-hover-bg"] = e.btnHoverBg), e.btnHoverFg != null && (o["--mrp-btn-hover-fg"] = e.btnHoverFg), e.btnActiveBg != null && (o["--mrp-btn-active-bg"] = e.btnActiveBg), o;
305
- }
306
- function ft(e) {
307
- const o = N(Q, null), n = h(() => {
308
- const t = o?.value ?? null, r = "defaults" in e && "presets" in e ? e : { defaults: e, presets: {} };
309
- return t ? {
310
- defaults: { ...t.defaults, ...r.defaults },
311
- presets: { ...t.presets, ...r.presets },
312
- defaultPreset: r.defaultPreset ?? t.defaultPreset
313
- } : r;
314
- });
315
- le(Q, n);
316
- }
317
- function Qe() {
318
- return N(Q, h(() => null));
319
- }
320
- class D extends Error {
321
- constructor(o, n, t) {
322
- super(n), this.name = "MachReportError", this.code = o, this.cause = t;
323
- }
324
- }
325
- function _e(e) {
326
- return e instanceof D ? { code: e.code, cause: e.cause } : { code: "render", cause: e };
327
- }
328
- const et = {
329
- key: 0,
330
- class: "mrp-state"
331
- }, tt = {
332
- key: 1,
333
- class: "mrp-state mrp-error"
334
- }, ot = {
335
- key: 2,
336
- class: "mrp-state"
337
- }, nt = ["data-page"], rt = { class: "mrp-overlay" }, U = 96 / 25.4, at = /* @__PURE__ */ ae({
338
- __name: "ReportPreview",
339
- props: {
340
- tempId: {
341
- type: [String, Array],
342
- default: null
343
- },
344
- furnitureTempId: { type: String, default: "" },
345
- params: {
346
- type: Object,
347
- default: () => ({})
348
- },
349
- height: { type: String, default: "100vh" },
350
- autoLoad: { type: Boolean, default: !0 },
351
- /** 以下显隐/间距不传时走配置中心(preset > defaults > 内置缺省) */
352
- showExport: { type: Boolean, default: void 0 },
353
- showPrint: { type: Boolean, default: void 0 },
354
- showPdfWindow: { type: Boolean, default: void 0 },
355
- /** 页间距(px);不传走配置中心 */
356
- gapPx: { type: Number, default: void 0 },
357
- /** 工具栏/状态文案覆写(不传走配置中心 messages) */
358
- messages: { type: Object, default: void 0 },
359
- /** 启用的 preset 名(不传用配置中心 defaultPreset) */
360
- preset: { type: String, default: void 0 },
361
- fetcher: {
362
- type: Function,
363
- default: null
364
- }
365
- },
366
- emits: ["loaded", "error"],
367
- setup(e, { expose: o, emit: n }) {
368
- xe((P) => ({
369
- v8289d092: i.value + "px"
370
- }));
371
- const t = e, r = n, s = Ee(null), u = k(!1), v = k(""), R = k(1), C = k(null), M = k(null), i = h(() => Math.max(0, fe.value)), a = N(We, null), l = N(Se, null) ?? Ae({ fontUrl: "/simhei.ttf" }), d = h(() => He(t.tempId)), f = h(() => s.value?.pages.length ?? 0), z = Qe(), $ = h(() => Xe(z.value, t.preset)), F = h(() => ({
372
- ...$.value.messages,
373
- ...t.messages
374
- })), de = h(() => t.showExport ?? $.value.showExport), ce = h(() => t.showPrint ?? $.value.showPrint), pe = h(() => t.showPdfWindow ?? $.value.showPdfWindow), fe = h(() => t.gapPx ?? $.value.gapPx), me = h(() => ({
375
- height: t.height,
376
- ...Je($.value.theme)
377
- })), { zoom: W, zoomMode: ge, applyFitZoom: _, setZoom: ve } = Ie(() => ({
378
- viewport: M.value,
379
- pageWidthPx: (s.value?.pages[0]?.pageWidthMm ?? 210) * U
380
- })), he = Oe(s, W, {
381
- pxPerMm: U,
382
- gapPx: i.value
383
- }), { contentSize: V, windowRange: O, visiblePages: we, makeScrollHandler: be, refreshViewport: ee } = he, Pe = be(R, f);
384
- function G() {
385
- s.value = null, R.value = 1;
386
- }
387
- let I = 0;
388
- async function S() {
389
- const P = ++I, y = t.fetcher ?? a;
390
- if (d.value.length === 0) {
391
- v.value = "缺少报表模板 ID", G(), r("error", v.value, { code: "param" });
392
- return;
393
- }
394
- if (!y) {
395
- v.value = "未提供渲染数据源 fetcher", G(), r("error", v.value, { code: "config" });
396
- return;
397
- }
398
- u.value = !0, v.value = "", G();
399
- try {
400
- const p = await y({
401
- tempIds: d.value,
402
- furnitureTempId: t.furnitureTempId || void 0,
403
- params: { ...t.params }
404
- });
405
- if (P !== I) return;
406
- const g = ze(p);
407
- if (!g.ok) {
408
- const B = g.errors.slice(0, 3).map((H) => `${H.path}: ${H.message}`).join("; ");
409
- throw new D(
410
- "validate",
411
- `渲染计划校验失败(${g.errors.length} 处): ${B}`
412
- );
413
- }
414
- g.warnings.length > 0 && console.warn("[mach-report] 渲染计划告警:", g.warnings), s.value = p, R.value = 1, M.value && (M.value.scrollTop = 0), _(), r("loaded", p.pages.length);
415
- } catch (p) {
416
- if (P !== I) return;
417
- const g = p instanceof D ? p : new D(
418
- "fetch",
419
- p instanceof Error ? p.message : "预览加载失败",
420
- p
421
- );
422
- v.value = g.message, r("error", g.message, _e(g));
423
- } finally {
424
- P === I && (u.value = !1);
425
- }
426
- }
427
- function K(P) {
428
- if (f.value <= 0) return;
429
- const y = Math.max(1, Math.min(f.value, P));
430
- R.value = y;
431
- const p = M.value;
432
- if (!p) return;
433
- let g = 0;
434
- for (let B = 0; B < y - 1; B++)
435
- g += (s.value?.pages[B]?.pageHeightMm ?? 0) * U + i.value;
436
- p.scrollTop = g * W.value;
437
- }
438
- const { print: Z, exportAs: q, openPdfWindow: Y, releasePrintFrame: ye } = je(s, {
439
- getPdfExporter: () => l,
440
- onError: (P) => r("error", P, { code: "print" })
441
- });
442
- le(Le, { reload: S, print: Z, exportAs: q, openPdfWindow: Y, gotoPage: K }), Me(() => {
443
- const P = s.value;
444
- if (!P) return;
445
- const y = C.value;
446
- if (!y) return;
447
- y.querySelectorAll(".mrp-page-holder").forEach((g) => {
448
- const B = Number(g.dataset.page ?? 0) - 1, H = P.pages[B];
449
- !H || g.childElementCount > 0 || (g.style.width = `${H.pageWidthMm * U}px`, g.appendChild(ie(H, 96, {}, document)));
450
- });
451
- }, { flush: "post" });
452
- function te() {
453
- ee(M.value), _();
454
- }
455
- return Re(() => {
456
- window.addEventListener("resize", te), ee(M.value), t.autoLoad && S();
457
- }), $e(() => {
458
- window.removeEventListener("resize", te), ye();
459
- }), oe(
460
- () => [t.tempId, t.furnitureTempId, JSON.stringify(t.params)],
461
- () => {
462
- t.autoLoad && S();
463
- }
464
- ), oe(
465
- () => t.fetcher ?? a,
466
- () => {
467
- t.autoLoad && S();
468
- }
469
- ), o({ reload: S, print: Z, exportAs: q, openPdfWindow: Y, gotoPage: K }), (P, y) => (w(), b("div", {
470
- class: "mach-report-preview",
471
- style: L(me.value)
472
- }, [
473
- ke(Ze, {
474
- "page-count": f.value,
475
- "current-page": R.value,
476
- "zoom-mode": m(ge),
477
- zoom: m(W),
478
- "show-export": de.value,
479
- "show-print": ce.value,
480
- "show-pdf-window": pe.value,
481
- messages: F.value,
482
- onGoto: K,
483
- onZoom: m(ve),
484
- onExport: y[0] || (y[0] = (p) => m(q)(p)),
485
- onPrint: m(Z),
486
- onPdfWindow: m(Y)
487
- }, null, 8, ["page-count", "current-page", "zoom-mode", "zoom", "show-export", "show-print", "show-pdf-window", "messages", "onZoom", "onPrint", "onPdfWindow"]),
488
- E("div", {
489
- ref_key: "viewportRef",
490
- ref: M,
491
- class: "mrp-body",
492
- onScrollPassive: y[1] || (y[1] = (p) => m(Pe)(p.target))
493
- }, [
494
- u.value ? (w(), b("div", et, x(F.value.loading), 1)) : v.value ? (w(), b("div", tt, [
495
- Ce(x(v.value) + " ", 1),
496
- E("button", {
497
- class: "mrp-retry",
498
- type: "button",
499
- onClick: S
500
- }, x(F.value.retry), 1)
501
- ])) : !s.value || f.value === 0 ? (w(), b("div", ot, x(F.value.empty), 1)) : (w(), b("div", {
502
- key: 3,
503
- class: "mrp-scale",
504
- style: L({ width: `${m(V).w * m(W)}px`, height: `${m(V).h * m(W)}px` })
505
- }, [
506
- E("div", {
507
- ref_key: "containerRef",
508
- ref: C,
509
- class: "mrp-scale-inner",
510
- style: L({ transform: `scale(${m(W)})`, transformOrigin: "top left", width: `${m(V).w}px` })
511
- }, [
512
- m(O).padTopPx > 0 ? (w(), b("div", {
513
- key: 0,
514
- class: "mrp-spacer-top",
515
- style: L({ height: `${m(O).padTopPx}px` }),
516
- "aria-hidden": "true"
517
- }, null, 4)) : T("", !0),
518
- (w(!0), b(se, null, Fe(m(we), (p) => (w(), b("div", {
519
- key: p.index,
520
- class: "mrp-page-holder",
521
- "data-page": p.index + 1
522
- }, null, 8, nt))), 128)),
523
- m(O).padBottomPx > 0 ? (w(), b("div", {
524
- key: 1,
525
- class: "mrp-spacer-bottom",
526
- style: L({ height: `${m(O).padBottomPx}px` }),
527
- "aria-hidden": "true"
528
- }, null, 4)) : T("", !0)
529
- ], 4)
530
- ], 4))
531
- ], 544),
532
- E("div", rt, [
533
- Be(P.$slots, "default", {}, void 0, !0)
534
- ])
535
- ], 4));
536
- }
537
- }), st = /* @__PURE__ */ ue(at, [["__scopeId", "data-v-6e07f84a"]]), mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
538
- __proto__: null,
539
- default: st
540
- }, Symbol.toStringTag, { value: "Module" }));
541
- export {
542
- qe as D,
543
- D as M,
544
- st as R,
545
- Ye as a,
546
- Ze as b,
547
- J as c,
548
- ct as d,
549
- pt as e,
550
- _e as f,
551
- Oe as g,
552
- je as h,
553
- Ie as i,
554
- mt as j,
555
- ft as p,
556
- Xe as r,
557
- Je as t,
558
- Qe as u
559
- };
@@ -1,3 +0,0 @@
1
- "use strict";const D="#333333",N="#000000",F="1.0.0-mach",y="mach-local",V="jh4j-compatible";function C(t=96){return t/25.4}function j(t,e=96){return(t||0)*C(e)}function $(t,e=96){return t/C(e)}function k(t,e=96){return t*e/72}function W(t,e){const i=10**e;return Math.round(t*i)/i}const G={a3:{widthMm:297,heightMm:420},a4:{widthMm:210,heightMm:297},a5:{widthMm:148,heightMm:210},b4:{widthMm:250,heightMm:353},b5:{widthMm:176,heightMm:250}},v=F;function J(t){if(t&&t.code!=null&&t.code!==200)throw new Error(String(t.message||"渲染计划加载失败"));const e=t?.data?.pages;return{schemaVersion:v,pages:Array.isArray(e)?e:[]}}function K(t){return(t.kind==="image"||t.kind==="barcode"||t.kind==="qrcode"||t.kind==="chart")&&!!t.imageData}function Z(t){return t.kind==="text"&&Array.isArray(t.richParagraphs)&&t.richParagraphs.length>0}const b=/[\u3000-\u9fff\uff00-\uffef]/,M=new Uint8Array(128);{for(const t of"iljtf.,:;'`|!()[]")M[t.charCodeAt(0)]=1;for(const t of"mwMW@")M[t.charCodeAt(0)]=2;for(let t=48;t<=57;t++)M[t]=3;for(let t=65;t<=90;t++)M[t]=4;M[32]=5}const X=[.54,.26,.95,.59,.67,.3];function z(t){const e=t.charCodeAt(0);return e<128?X[M[e]]:b.test(t)?1:/[A-Z]/.test(t)?.67:.54}const T={measureMm(t,e){const{fontSizePt:i,bold:s=!1,letterSpacingPt:f=0}=e,o=25.4/72;let a=0;for(const r of t)a+=z(r);return s&&(a*=1.04),(a*i+f*t.length)*o}};function q(){return T}function Q(t,e){return T.measureMm(t,e)}function Y(t){let e;return{measureMm(i,s){if(e===void 0&&(e=t()),!e)return T.measureMm(i,s);const f=s.fontSizePt*96/72;return e.font=`${s.bold?"bold ":""}${f}px sans-serif`,e.measureText(i).width*25.4/96}}}function tt(t,e,i){const s=[];let f="",o=0;const a=()=>{f&&(s.push({text:f,widthMm:o,cjk:!1}),f="",o=0)};for(const r of t){if(r===`
2
- `){a(),s.push({text:`
3
- `,widthMm:0,cjk:!1,br:!0});continue}if(r===" "){a(),s.push({text:r,widthMm:i.measureMm(r,e),cjk:!1,space:!0});continue}if(b.test(r)){a(),s.push({text:r,widthMm:i.measureMm(r,e),cjk:!0});continue}f+=r,o+=i.measureMm(r,e)}return a(),s}function et(t,e,i,s=T){if(!t)return[""];const f=[];let o="",a=0;const r=()=>{f.push(o),o="",a=0};for(const h of tt(t,i,s)){if(h.br){r();continue}if(a+h.widthMm<=e){o+=h.text,a+=h.widthMm;continue}if(h.space){r();continue}if(h.cjk){o.length>0&&r(),o=h.text,a=h.widthMm;continue}if(o.length>0&&r(),h.widthMm<=e){o=h.text,a=h.widthMm;continue}for(const _ of h.text){const E=s.measureMm(_,i);a+E>e&&o.length>0&&r(),o+=_,a+=E}}return r(),f}function O(t,e){const i=t.length;if(i===0)return[];const s=t.reduce((r,h)=>r+h,0),f=s>0&&e>0?e/s:1,o=[];let a=0;for(let r=0;r<i;r++){const h=Math.max(0,t[r]*f);o.push({pos:a,size:h}),a+=h}return o}function nt(t,e,i){const s=t.cells??[],f=Math.max(s.length,1),o=t.colWidthsMm?.length??Math.max(1,...s.map(n=>Array.isArray(n)?n.length:0)),a=t.colWidthsMm?.length?O(t.colWidthsMm,e):Array.from({length:o},(n,c)=>({pos:e*c/o,size:e/o})),r=n=>n<=0?0:n>=o?a[a.length-1].pos+a[a.length-1].size:a[n].pos,h=t.rowHeightsMm?.length?O(t.rowHeightsMm,i):Array.from({length:f},(n,c)=>({pos:i*c/f,size:i/f})),_=n=>n<=0?0:n>=f?h[h.length-1].pos+h[h.length-1].size:h[n].pos,E=new Set,g=(n,c)=>`${n}:${c}`,w=[],R=new Set,x=new Set,L=(n,c)=>`v${n}:${c}`,I=(n,c)=>`h${n}:${c}`;s.forEach((n,c)=>{if(!Array.isArray(n))return;let u=0;for(const m of n){for(;u<o&&E.has(g(c,u));)u++;if(u>=o)break;const B=Math.max(1,Math.min(m?.colSpan??1,o-u)),U=Math.max(1,m?.rowSpan??1),P=Math.min(f,c+U),S=Math.min(o,u+B);for(let l=c;l<P;l++)for(let d=u;d<S;d++)E.add(g(l,d));for(let l=u+1;l<S;l++)for(let d=c;d<P;d++)R.add(L(l,d));for(let l=c+1;l<P;l++)for(let d=u;d<S;d++)x.add(I(l,d));const p=r(u),H=_(c);w.push({ri:c,ci:u,cell:m??{},xMm:p,yMm:H,widthMm:r(S)-p,heightMm:_(P)-H}),u=S}});const A=[];for(let n=1;n<o;n++){let c=-1;for(let u=0;u<=f;u++){const m=u<f&&!R.has(L(n,u));m&&c<0&&(c=u),!m&&c>=0&&(A.push({kind:"v",pos:r(n),from:_(c),to:_(u)}),c=-1)}}for(let n=1;n<f;n++){let c=-1;for(let u=0;u<=o;u++){const m=u<o&&!x.has(I(n,u));m&&c<0&&(c=u),!m&&c>=0&&(A.push({kind:"h",pos:_(n),from:r(c),to:r(u)}),c=-1)}}return{columns:a,rows:h,cells:w,edges:A}}function ot(t,e=96,i=10.5){if(t?.fontSizePx!=null)return{fontSizePt:t.fontSizePx*72/e,fontSizePx:t.fontSizePx};const s=t?.fontSize??i;return{fontSizePt:s,fontSizePx:k(s,e)}}function rt(t,e=D){return{color:t?.borderColor??t?.lineColor??e,widthPt:t?.lineWidthPt??.75}}function ct(t,e=N){return t?.color??e}function st(t){return t?.lineHeight??1.35}function it(t){const e=t?.borderTop!==!1,i=t?.borderRight!==!1,s=t?.borderBottom!==!1,f=t?.borderLeft!==!1;return{top:e,right:i,bottom:s,left:f,inner:e||i||s||f}}exports.CSS_DPI=96;exports.DEFAULT_BORDER_PT=.75;exports.DEFAULT_FONT_PT=10.5;exports.DEFAULT_STROKE_COLOR=D;exports.DEFAULT_TEXT_COLOR=N;exports.LINE_HEIGHT=1.35;exports.MM_PER_INCH=25.4;exports.PAPER_SIZES=G;exports.RENDER_PLAN_SCHEMA_VERSION=v;exports.SCHEMA_VERSION_JH4J=V;exports.SCHEMA_VERSION_LOCAL=y;exports.SCHEMA_VERSION_MACH=F;exports.charWidthEm=z;exports.createCanvasMeasurer=Y;exports.createHeuristicMeasurer=q;exports.heuristicMeasurer=T;exports.isImageBackedComponent=K;exports.isRichText=Z;exports.measureTextMm=Q;exports.mmToPx=j;exports.mmToPxFactor=C;exports.ptToPx=k;exports.pxToMm=$;exports.resolveBoxBorders=it;exports.resolveFontSize=ot;exports.resolveGridLayout=nt;exports.resolveLineHeight=st;exports.resolveStroke=rt;exports.resolveTextColor=ct;exports.round=W;exports.toRenderPlan=J;exports.wrapText=et;