Files
qhmes/deploy-qhmes/frontend/js/printNativeViaPrintDot-CW0hqAEQ.js
2026-05-15 11:34:12 +08:00

70 lines
45 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/jspdf.es.min-CY_STL60.js","js/index-BI6CMai0.js","js/vue-vendor-C7Zq48Yl.js","js/antd-vue-vendor-BPnV8VqP.js","js/vxe-table-vendor-B88kchpX.js","assets/index-CaK6YpON.css","js/browser-B0xVgIeL.js"])))=>i.map(i=>d[i]);
var Rt=Object.defineProperty,zt=Object.defineProperties;var Wt=Object.getOwnPropertyDescriptors;var rt=Object.getOwnPropertySymbols;var gt=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var G=Math.pow,ut=(t,e,r)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,H=(t,e)=>{for(var r in e||(e={}))gt.call(e,r)&&ut(t,r,e[r]);if(rt)for(var r of rt(e))pt.call(e,r)&&ut(t,r,e[r]);return t},_=(t,e)=>zt(t,Wt(e));var at=(t,e)=>{var r={};for(var a in t)gt.call(t,a)&&e.indexOf(a)<0&&(r[a]=t[a]);if(t!=null&&rt)for(var a of rt(t))e.indexOf(a)<0&&pt.call(t,a)&&(r[a]=t[a]);return r};var O=(t,e,r)=>new Promise((a,o)=>{var s=c=>{try{d(r.next(c))}catch(b){o(b)}},u=c=>{try{d(r.throw(c))}catch(b){o(b)}},d=c=>c.done?a(c.value):Promise.resolve(c.value).then(s,u);d((r=r.apply(t,e)).next())});import{r as Dt,e as Et}from"./vue-vendor-C7Zq48Yl.js";import{d as bt}from"./antd-vue-vendor-BPnV8VqP.js";import{Q as It}from"./browser-INOPQ3v-.js";import{b as Lt}from"./tableMerge-CpKVscEF.js";import{g as tt,r as nt,n as ct}from"./tableBuilder-lOY0L2dW.js";import{n as qt}from"./freeTableGrid-BXWKfNhh.js";import{r as Ot,b as Ut}from"./freeTableBorders-DHo40MDb.js";import{r as jt,a as Kt,b as Vt}from"./freeTableTracks-CfeiVurn.js";import{_ as yt}from"./index-BI6CMai0.js";function ot(t,e){const r=t.bindField;if(r)return String(r).split(".").reduce((a,o)=>a==null?void 0:a[o],e||{})}function Yt(t,e,r=1,a=1){var s,u,d,c;const o=ot(t,e);if(o!=null&&t.type!=="pageNo")return t.type==="date"?bt(o).format(t.format||"YYYY-MM-DD"):String(o);if(t.type==="date")return bt().format(t.format||"YYYY-MM-DD");if(t.type==="pageNo")return t.text.replace("{{pageNo}}",String(r)).replace("{{totalPages}}",String(a));if((s=t.text)!=null&&s.startsWith("{{")&&((u=t.text)!=null&&u.endsWith("}}"))){const b=t.text.replaceAll("{","").replaceAll("}","").trim();return String((d=tt(e||{},b))!=null?d:"")}return String((c=t.text)!=null?c:"")}function Gt(t,e){return O(this,null,function*(){const r=Math.max(1,Number((t==null?void 0:t.rowCount)||1)),a=Math.max(1,Number((t==null?void 0:t.colCount)||1)),o=Math.max(.01,Number(t==null?void 0:t.w)||.01),s=Math.max(.01,Number(t==null?void 0:t.h)||.01),u=jt(t),d=Kt(t),c=String((t==null?void 0:t.borderColor)||"#d9d9d9"),b=Math.max(1,Number((t==null?void 0:t.borderWidth)||1)),m=`<colgroup>${u.map(n=>`<col style="width:${n}mm;box-sizing:border-box" />`).join("")}</colgroup>`,i=qt(r,a,(t==null?void 0:t.cells)||[]),h=(yield Promise.all(Array.from({length:r},(n,y)=>O(null,null,function*(){var S;const f=(S=d[y])!=null?S:s/r,p=(yield Promise.all(i.filter(g=>g.row===y).sort((g,T)=>g.col-T.col).map(g=>O(null,null,function*(){var Y,J,Q;const T=Math.max(1,Number(g.rowspan||1)),C=Math.max(1,Number(g.colspan||1)),l=String((g==null?void 0:g.bindField)||"").trim(),x=l?(Y=tt(e||{},l))!=null?Y:"":(J=g==null?void 0:g.text)!=null?J:"",$=String(x!=null?x:""),P=String((g==null?void 0:g.contentType)||"text"),M=P==="number"||P==="amount"?it(x,g):$,W=yield Tt(P,P==="image"||P==="qrcode"||P==="barcode"?$:M,g),v=String((g==null?void 0:g.align)||"left"),E=String((g==null?void 0:g.verticalAlign)||"middle"),R=Math.max(8,Number((g==null?void 0:g.fontSize)||((Q=t.style)==null?void 0:Q.fontSize)||12)),q=String((g==null?void 0:g.color)||"#111111"),U=String((g==null?void 0:g.backgroundColor)||"#ffffff"),k=T>1?` rowspan="${T}"`:"",B=C>1?` colspan="${C}"`:"",I=`width:${u.slice(g.col,g.col+C).reduce((j,et)=>j+et,0)}mm;`,A=Ot(t,i,g,g.row,g.col,T,C,r,a),D=Vt(t,g.row,g.col,T,C,r,a),N=Ut(A,b,c,D),z=g.autoWrap===!1;return`<td${k}${B} style="box-sizing:border-box;${N}${I}padding:2mm;text-align:${v};vertical-align:${E};font-size:${R}px;color:${q};background:${U};white-space:${z?"nowrap":"normal"};word-break:${z?"normal":"break-all"};overflow-wrap:${z?"normal":"anywhere"};line-height:${z?`${f}mm`:"1.3"};">${W}</td>`})))).join("");return`<tr style="height:${f}mm;box-sizing:border-box">${p}</tr>`})))).join("");return`<table style="width:${o}mm;border-collapse:collapse;border-spacing:0;table-layout:fixed;box-sizing:border-box;">${m}<tbody>${h}</tbody></table>`})}function Jt(t,e){return O(this,null,function*(){const r=nt(t,e),a=ct(t),o=Math.max(1,Number((t==null?void 0:t.fixedRows)||5)),s=Qt(r,o),u=s.length?s:[[]],d=String(t.footerTotalMode||"overall");return Promise.all(u.map((c,b)=>{const m=b===u.length-1;return St(t,a,c,d==="page"?!0:m,d==="page"?c:r)}))})}function St(s,u,d,c){return O(this,arguments,function*(t,e,r,a,o=r){const b=Lt(r,t.columns,t.mergeColumnKeys||[],t.strictGrouping!==!1),m=t.showHeader?Xt(t,e):"",i=(yield Promise.all(r.map((n,y)=>O(null,null,function*(){const f=(yield Promise.all(e.map(p=>O(null,null,function*(){var w;const S=p.bindField||p.field,g=b[`${y}_${S}`];if(g===0)return"";const T=g&&g>1?` rowspan="${g}"`:"",C=(w=tt(n||{},S))!=null?w:"",l=String(p.contentType||"text"),x=ht(p)?it(C,p):String(C),$=yield Tt(l,x,p),P=p!=null&&p.useCustomFontSize?Number((p==null?void 0:p.fontSize)||12):Number(t.bodyFontSize||12),M=lt(p,x,Number((p==null?void 0:p.width)||30),t.rowHeight||8,P);return`<td${T} style="border:1px solid #222;padding:2mm;text-align:${p.align||"left"};font-family:${p.fontFamily||"inherit"};font-size:${M}px;color:${p.fontColor||"#111111"};white-space:${p.autoWrap===!1?"nowrap":"normal"};word-break:${p.autoWrap===!1?"normal":"break-all"};overflow-wrap:${p.autoWrap===!1?"normal":"anywhere"};line-height:${p.autoWrap===!1?`${t.rowHeight||8}mm`:"1.3"};">${$}</td>`})))).join("");return`<tr style="min-height:${t.rowHeight}mm;">${f}</tr>`})))).join(""),h=a?te(o,e,t):"";return`<table style="width:100%;border-collapse:collapse;table-layout:fixed;"><thead>${m}</thead><tbody>${i}</tbody>${h}</table>`})}function Qt(t,e){const r=Math.max(1,Number(e||1)),a=[];for(let o=0;o<t.length;o+=r)a.push(t.slice(o,o+r));return a}function Xt(t,e){const r=Zt(t,e),a=Math.max(1,r.length),o=(t.headerHeight||10)/a;return r.map(s=>{const u=s.map(d=>{const c=e[d.col]||{},b=e.slice(d.col,d.col+d.colspan).reduce((h,n)=>h+Number((n==null?void 0:n.width)||0),0),m=o*Number(d.rowspan||1),i=lt(c,String((d==null?void 0:d.title)||""),Number(b||(c==null?void 0:c.width)||30),m,Number(t.headerFontSize||12));return`<th rowspan="${d.rowspan}" colspan="${d.colspan}" style="border:1px solid #222;padding:2mm;text-align:${d.align||c.align||"center"};font-weight:600;width:${d.widthPercent}%;background:${t.headerBgColor||"#f5f5f5"};color:${c.fontColor||t.headerTextColor||"#111111"};font-family:${c.fontFamily||"inherit"};font-size:${i}px;white-space:${c.autoWrap===!1?"nowrap":"normal"};word-break:${c.autoWrap===!1?"normal":"break-all"};overflow-wrap:${c.autoWrap===!1?"normal":"anywhere"};line-height:${c.autoWrap===!1?`${m}mm`:"1.3"};">${d.title||""}</th>`}).join("");return`<tr style="height:${o}mm;">${u}</tr>`}).join("")}function Zt(t,e){var b,m;const r=e.length;if(!r)return[];if(t.enableMultiHeader!==!0)return[e.map((i,h)=>({row:0,col:h,rowspan:1,colspan:1,title:String((i==null?void 0:i.title)||""),align:(i==null?void 0:i.align)||"center",widthPercent:Number((i==null?void 0:i.widthPercent)||0)}))];const a=t==null?void 0:t.headerConfig,o=Math.max(1,Number((a==null?void 0:a.rowCount)||1)),s=Array.from({length:o},()=>Array.from({length:r},()=>null)),u=[];(Array.isArray(a==null?void 0:a.cells)&&Number((a==null?void 0:a.colCount)||0)===r?a.cells:[]).forEach(i=>{const h=Math.max(0,Number((i==null?void 0:i.row)||0)),n=Math.max(0,Number((i==null?void 0:i.col)||0)),y=Math.max(1,Number((i==null?void 0:i.rowspan)||1)),f=Math.max(1,Number((i==null?void 0:i.colspan)||1));if(h>=o||n>=r||s[h][n])return;const p=Math.min(o,h+y),S=Math.min(r,n+f);for(let T=h;T<p;T+=1)for(let C=n;C<S;C+=1)if(s[T][C])return;const g={row:h,col:n,rowspan:p-h,colspan:S-n,title:String((i==null?void 0:i.title)||""),align:String((i==null?void 0:i.align)||"center")};for(let T=h;T<p;T+=1)for(let C=n;C<S;C+=1)s[T][C]=g;u.push(g)});for(let i=0;i<o;i+=1)for(let h=0;h<r;h+=1){if(s[i][h])continue;const n={row:i,col:h,rowspan:1,colspan:1,title:i===o-1?String(((b=e[h])==null?void 0:b.title)||""):"",align:((m=e[h])==null?void 0:m.align)||"center"};s[i][h]=n,u.push(n)}const c=Array.from({length:o},()=>[]);return u.forEach(i=>{if(s[i.row][i.col]!==i)return;const h=e.slice(i.col,i.col+i.colspan).reduce((n,y)=>n+Number((y==null?void 0:y.widthPercent)||0),0);c[i.row].push(_(H({},i),{widthPercent:h}))}),c.forEach(i=>i.sort((h,n)=>h.col-n.col)),c}function $t(t,e){return O(this,null,function*(){const r=String(t||"empty");return It.toDataURL(r,{errorCorrectionLevel:(e==null?void 0:e.qrLevel)||"M",margin:0,type:(e==null?void 0:e.qrRenderType)||"image/png",width:220})})}function Tt(t,e,r){return O(this,null,function*(){const a=String(e||""),o=(r==null?void 0:r.fillCell)!==!1,s=Math.max(10,Math.min(100,Number((r==null?void 0:r.contentScale)||100)));if(t==="image")return`<img src="${a||`https://via.placeholder.com/180x80.png?text=${encodeURIComponent((r==null?void 0:r.title)||"Image")}`}" style="display:block;margin:0 auto;max-width:100%;max-height:100%;object-fit:${(r==null?void 0:r.imageFit)||"contain"};width:${o?"100%":`${s}%`};height:${o?"100%":`${s}%`};" />`;if(t==="qrcode")try{return`<img src="${yield $t(a,r)}" style="display:block;margin:0 auto;max-width:100%;max-height:100%;object-fit:contain;width:${o?"100%":`${s}%`};height:${o?"100%":`${s}%`};" />`}catch(u){return`<div style="display:flex;align-items:center;justify-content:center;border:1px dashed #999;width:${o?"100%":`${s}%`};height:${o?"100%":`${s}%`};margin:0 auto;">QR:${a}</div>`}return t==="barcode"?`<div style="display:flex;align-items:center;justify-content:center;border:1px dashed #999;width:${o?"100%":`${s}%`};height:${o?"100%":`${Math.max(20,s*.6)}%`};margin:0 auto;">BAR:${a}</div>`:a})}function lt(t,e,r,a,o){const s=Number(o||12);if(!(t!=null&&t.autoFitFont))return s;const u=Math.max(1,r*3.7795275591),d=Math.max(1,a*3.7795275591),c=Math.max(1,e.length),b=u/Math.max(1,c*.62),m=(t==null?void 0:t.autoWrap)===!1?d*.55:d*.36,i=Math.min(s,b,m);return Math.max(8,Math.round(i))}function ht(t){const e=String((t==null?void 0:t.contentType)||"text");return e==="number"||e==="amount"}function it(t,e){var u;const r=Number(t);if(!Number.isFinite(r))return String(t!=null?t:"");const a=Math.max(0,Math.min(6,Number((u=e==null?void 0:e.decimalPlaces)!=null?u:2))),s=((e==null?void 0:e.roundHalfUp)===!1?Math.trunc(r*G(10,a))/G(10,a):Number(r.toFixed(a))).toLocaleString(void 0,{minimumFractionDigits:a,maximumFractionDigits:a});return String((e==null?void 0:e.contentType)||"text")==="amount"?`${(e==null?void 0:e.amountType)==="USD"?"$":(e==null?void 0:e.amountType)==="EUR"?"EUR ":"¥"}${s}`:s}function te(t,e,r){var d;if((r==null?void 0:r.footerShowTotal)===!1)return"";const a=String((r==null?void 0:r.footerLabelColumnKey)||((d=e==null?void 0:e[0])==null?void 0:d.key)||""),o=String((r==null?void 0:r.footerLabelText)||"合计"),s=(r==null?void 0:r.footerLabelCenter)===!1?"left":"center";return`<tfoot><tr>${e.map((c,b)=>{if(ht(c)&&(c!=null&&c.enableFooterTotal)){const m=(c==null?void 0:c.bindField)||(c==null?void 0:c.field),i=t.reduce((h,n)=>{const y=Number(tt(n||{},m));return h+(Number.isFinite(y)?y:0)},0);return`<td style="border:1px solid #222;padding:2mm;font-weight:600;text-align:${c.align||"left"};background:#fafafa;">${it(i,c)}</td>`}return String((c==null?void 0:c.key)||"")===a||!a&&b===0?`<td style="border:1px solid #222;padding:2mm;font-weight:600;background:#fafafa;text-align:${s};">${o}</td>`:'<td style="border:1px solid #222;padding:2mm;background:#fafafa;"></td>'}).join("")}</tr></tfoot>`}function ee(t,e){return O(this,null,function*(){const r=he(t,e),a=t.page.height*r,o=Nt(t),s=o.enabled,u=o.visible,d=Pt(t),c=[...t.elements].sort((n,y)=>n.zIndex-y.zIndex),b=(yield Promise.all(c.map(n=>O(null,null,function*(){var W,v,E,R,q,U,k;if(n.visible===!1)return"";const y=n.type==="reportFooter",f=n.type==="reportHeader",p=f&&n.printRepeated===!0,S=ue(n,o.headerId,d);if(!u&&S)return"";const g=S&&s,T=f||y?0:n.x,C=f?0:y&&n.printAtPageBottom===!0?Math.max(0,t.page.height-n.h):n.y,x=["position:absolute",`width:${f||y?t.page.width:n.w}mm`,`height:${n.h}mm`,`font-size:${((W=n.style)==null?void 0:W.fontSize)||12}px`,`font-weight:${((v=n.style)==null?void 0:v.fontWeight)||400}`,`color:${((E=n.style)==null?void 0:E.color)||"#111"}`,`line-height:${((R=n.style)==null?void 0:R.lineHeight)||1.4}`,`text-align:${((q=n.style)==null?void 0:q.textAlign)||"left"}`,`background:${((U=n.style)==null?void 0:U.backgroundColor)||"transparent"}`,(k=n.style)!=null&&k.borderWidth?`border:${n.style.borderWidth}px solid ${n.style.borderColor||"#222"}`:"","overflow:hidden"].filter(Boolean).join(";"),$=B=>[`left:${T}mm`,`top:${B}mm`,x].join(";");if(n.type==="table"||n.type==="detailTable"){if(String(n.tableHeightMode||"autoPage")==="fixedRows")return(yield Jt(n,e)).map((L,V)=>{const K=mt(t,V,C,Number(n.h||1),s,d,r);return`<div class="qhmes-native-table-chunk" style="${$(K)};overflow:visible;height:auto;">${L}</div>`}).join("");const F=ct(n),I=Ct(n,t,e,{repeatHeaderBandMm:d,repeatHeaderEnabled:s}),A=nt(n,e),D=String(n.footerTotalMode||"overall");return(yield Promise.all(I.map((z,L)=>O(null,null,function*(){const V=L===I.length-1;return St(n,F,z,D==="page"?!0:V,D==="page"?z:A)})))).map((z,L)=>`<div class="qhmes-native-table-chunk" style="${$(mt(t,L,C,Number(n.h||1),s,d,r))};overflow:visible;height:auto;">${z}</div>`).join("")}if(n.type==="freeTable"){const B=n.printRepeated===!0&&r>1,F=B?Array.from({length:r},(A,D)=>D+1):[1];return(yield Promise.all(F.map(A=>O(null,null,function*(){const D=C+(B?(A-1)*t.page.height:0),N=yield Gt(n,e);return`<div style="${$(D)};overflow:visible;">${N}</div>`})))).join("")}const P=(p||g)&&r>1,M=P?Array.from({length:r},(B,F)=>F+1):[1];return(yield Promise.all(M.map(B=>O(null,null,function*(){var I,A,D;const F=C+(P?(B-1)*t.page.height:0);if(n.type==="qrcode"){const N=(I=ot(n,e))!=null?I:n.value;try{return`<img src="${yield $t(String(N!=null?N:""),n)}" style="${$(F)};object-fit:contain;" />`}catch(z){return`<div style="${$(F)};display:flex;align-items:center;justify-content:center;border:1px dashed #999;">二维码:${N!=null?N:""}</div>`}}if(n.type==="barcode"){const N=(A=ot(n,e))!=null?A:n.value;return`<div style="${$(F)};display:flex;align-items:center;justify-content:center;border:1px dashed #999;">条形码:${N!=null?N:""}</div>`}if(n.type==="image"){const N=n;return`<img src="${((D=ot(n,e))!=null?D:N.src)||""}" style="${$(F)};object-fit:${N.fit||"contain"};" />`}return`<div style="${$(F)};white-space:pre-wrap;">${Yt(n,e,B,r)}</div>`})))).join("")})))).join(""),m=r>1?Array.from({length:r-1}).map((n,y)=>`<div style="position:absolute;left:0;top:${(y+1)*t.page.height}mm;width:${t.page.width}mm;height:0;page-break-before:always;"></div>`).join(""):"",i=r>1?Array.from({length:r-1},(n,y)=>`<div class="qhmes-native-screen-page-sep" aria-hidden="true" style="position:absolute;left:0;width:100%;top:${(y+1)*t.page.height}mm;pointer-events:none;z-index:10000;"></div>`).join(""):"",h=re(t.page.margin);return`<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<style>
@page { size: ${t.page.width}mm ${t.page.height}mm; margin: ${h}; }
html, body { margin: 0; padding: 0; overflow: visible; }
* {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
@media screen {
html { background: #525659; }
body {
margin: 0;
padding: 28px 20px 48px;
background: #525659;
min-height: 100vh;
box-sizing: border-box;
}
.qhmes-native-print-root {
margin: 0 auto;
position: relative;
box-shadow:
0 1px 2px rgba(0, 0, 0, 0.14),
0 4px 12px rgba(0, 0, 0, 0.1),
0 12px 28px rgba(0, 0, 0, 0.08);
background: #fff;
border-radius: 1px;
}
/* 分页缝隙:仿多页纸张之间的装订区 */
.qhmes-native-screen-page-sep {
height: 14px;
margin-top: -7px;
margin-left: -10px;
width: calc(100% + 20px);
background: #525659;
border: none;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.qhmes-native-table-chunk table {
border-collapse: collapse;
}
.qhmes-native-table-chunk thead {
display: table-header-group;
}
.qhmes-native-table-chunk tbody tr {
break-inside: avoid;
}
}
@media print {
html, body {
background: transparent !important;
padding: 0 !important;
}
.qhmes-native-print-root { box-shadow: none !important; }
.qhmes-native-screen-page-sep { display: none !important; }
}
</style>
</head>
<body>
<div class="qhmes-native-print-root" style="--qhmes-page-h:${t.page.height}mm;position:relative;width:${t.page.width}mm;min-height:${a}mm;height:auto;overflow:visible;box-sizing:border-box;">
${b}
${m}
${i}
</div>
</body>
</html>`})}function re(t){if(!Array.isArray(t)||t.length<4)return"0mm";const e=Math.max(0,Number(t[0]||0)),r=Math.max(0,Number(t[1]||0)),a=Math.max(0,Number(t[2]||0)),o=Math.max(0,Number(t[3]||0));return`${e}mm ${r}mm ${a}mm ${o}mm`}function ae(t){var r;const e=(r=t.page)==null?void 0:r.margin;return!Array.isArray(e)||e.length<4?0:Math.max(0,Number(e[0]||0))}function oe(t){var s,u;const e=Math.max(1,Number(((s=t.page)==null?void 0:s.height)||297)),r=(u=t.page)==null?void 0:u.margin;if(!Array.isArray(r)||r.length<4)return e;const a=Math.max(0,Number(r[0]||0)),o=Math.max(0,Number(r[2]||0));return Math.max(10,e-a-o)}function vt(t,e){const a=Number(e.y||0)+Math.max(.01,Number(e.h||1));return t.elements.some(o=>!((o==null?void 0:o.type)!=="freeTable"||(o==null?void 0:o.visible)===!1||o.printRepeated!==!0||Number(o.y||0)>=a-.02))}function mt(t,e,r,a,o,s,u){var i;const d=Math.max(1,Number(((i=t.page)==null?void 0:i.height)||297)),c=e*d;if(e===0||u>1&&vt(t,{y:r,h:a}))return c+Math.max(0,r);const m=ae(t)+(o&&s>0?Math.max(0,s):0);return c+m}const ne=96/25.4,st=ne,ie=1.4,se=1.03;function de(t){return t>=11904&&t<=40959||t>=12352&&t<=12543||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65519}function fe(t,e,r){if(!t.length)return 1;let a=0;for(const s of t){const u=s.codePointAt(0);de(u)?a+=1:/\s/.test(s)?a+=.22:a+=.62}a=Math.max(.01,a);const o=Math.max(1.8,e/Math.max(1,r)*.97);return Math.max(1,Math.ceil(a/o))}function ce(t,e,r){const a=Math.max(.01,Number(t.rowHeight||8));let o=a;const s=4,u=1.25;for(const d of r){const c=d.bindField||d.field,b=tt(e||{},c),m=String(d.contentType||"text"),i=Math.max(1,Number(d.width||30)),h=d.autoWrap===!1,n=d!=null&&d.useCustomFontSize?Number((d==null?void 0:d.fontSize)||12):Number(t.bodyFontSize||12),y=ht(d)?it(b,d):String(b!=null?b:""),f=lt(d,y,i,t.rowHeight||8,n);if(m==="qrcode"||m==="barcode"){const x=(d==null?void 0:d.fillCell)!==!1,$=Math.max(10,Math.min(100,Number((d==null?void 0:d.contentScale)||100))),P=x?i*.93:i*($/100)*.93;o=Math.max(o,P+s+u);continue}if(m==="image"){const x=(d==null?void 0:d.fillCell)!==!1,$=Math.max(10,Math.min(100,Number((d==null?void 0:d.contentScale)||100))),P=x?i*.65:i*($/100)*.65;o=Math.max(o,P+s+u*.6);continue}if(h){o=Math.max(o,a);continue}const p=y;if(!p.length){o=Math.max(o,a);continue}const S=i*st,g=Math.max(8,S-2*st*2),T=fe(p,g,f),C=f*1.3,l=T*C/st;o=Math.max(o,l+s,a)}return Math.max(a,o)}function X(t){return Math.max(.01,t*se)}function le(t,e,r){let a=0;const o=Math.min(e+r,t.length);for(let s=e;s<o;s+=1)a+=X(t[s]);return a}function Ct(t,e,r,a){const o=nt(t,r);if(!o.length)return[[]];const s=ct(t),u=o.map(l=>ce(t,l,s)),d=oe(e),c=Math.max(0,Number(t.y||0)),b=Math.max(.01,Number(t.rowHeight||8)),m=t.showHeader?Math.max(0,Number(t.headerHeight||10)):0,i=String(t.footerTotalMode||"overall"),h=t.footerShowTotal===!1,n=!h&&i==="page",y=!h&&i==="overall",f=Math.max(b,6),p=a.repeatHeaderEnabled&&a.repeatHeaderBandMm>0?Math.max(0,a.repeatHeaderBandMm):0,S=vt(e,t),g=[];let T=0,C=0;for(;T<o.length;){const l=o.length-T,x=C===0?d-c-m:S?Math.max(b,d-c-m):Math.max(b,d-m-p),$=Math.max(b,x-ie);let P=$;n&&(P=Math.max(b,$-f));let M=0,w=0;for(;M<l&&w+X(u[T+M])<=P+.02;)w+=X(u[T+M]),M+=1;if(y&&!n&&l<=M){if(le(u,T,l)+f<=$+.02){g.push(o.slice(T,T+l));break}for(P=Math.max(b,$-f),M=0,w=0;M<l&&w+X(u[T+M])<=P+.02;)w+=X(u[T+M]),M+=1}if(M===0&&(M=1),g.push(o.slice(T,T+M)),T+=M,C+=1,C>5e3)break}return g.length?g:[[]]}function he(t,e){const r=Nt(t),a=r.enabled?Pt(t):0,o=t.elements.filter(s=>s.type==="table"||s.type==="detailTable").map(s=>{const u=nt(s,e);if(String((s==null?void 0:s.tableHeightMode)||"autoPage")!=="fixedRows"){const b=Ct(s,t,e,{repeatHeaderBandMm:a,repeatHeaderEnabled:r.enabled});return Math.max(1,b.length)}const c=Math.max(1,Number((s==null?void 0:s.fixedRows)||5));return Math.max(1,Math.ceil(u.length/c))});return Math.max(1,...o)}function Nt(t){const e=t.elements.find(r=>r.type==="reportHeader");return e?e.visible===!1?{visible:!1,enabled:!1,headerId:String(e.id||"")}:{visible:!0,enabled:e.printRepeated===!0,headerId:String(e.id||"")}:{visible:!0,enabled:!1,headerId:""}}function Pt(t){const e=t.elements.find(r=>r.type==="reportHeader");return Math.max(0,Number((e==null?void 0:e.h)||0))}function ue(t,e,r){if(t.type==="reportHeader")return!0;if(t.type==="reportFooter")return!1;const a=String(t.bandId||"");if(e&&a===e)return!0;const o=String(t.region||"");if(o==="header")return!0;if(o==="body"||o==="footer"||r<=0)return!1;const s=Number(t.y||0),u=s+Number(t.h||0);return s<r&&u<=r+.2}function ge(){return{fieldMap:{},tableSources:["mainTable","detailList"],params:[],detailTables:[]}}function pe(t){return{id:t.id,component:t.type,bindField:t.bindField||"",region:t.region||"",bandId:t.bandId||"",rect:{x:t.x,y:t.y,w:t.w,h:t.h,zIndex:t.zIndex},style:H({},t.style||{}),payload:t.type==="image"?{src:t.src,fit:t.fit}:t.type==="table"||t.type==="detailTable"?{source:t.source,mergeColumnKeys:t.mergeColumnKeys||[],strictGrouping:t.strictGrouping!==!1,enableMultiHeader:t.enableMultiHeader===!0,tableHeightMode:t.tableHeightMode,fixedRows:t.fixedRows,showHeader:t.showHeader,rowHeight:t.rowHeight,headerHeight:t.headerHeight,headerFontSize:t.headerFontSize,bodyFontSize:t.bodyFontSize,headerBgColor:t.headerBgColor,headerTextColor:t.headerTextColor,footerLabelColumnKey:t.footerLabelColumnKey,footerLabelText:t.footerLabelText,footerLabelCenter:t.footerLabelCenter,footerShowTotal:t.footerShowTotal!==!1,footerTotalMode:t.footerTotalMode||"overall",headerConfig:t.headerConfig,columns:t.columns}:t.type==="freeTable"?{printRepeated:t.printRepeated===!0,rowCount:Number(t.rowCount||1),colCount:Number(t.colCount||1),borderColor:t.borderColor||"#d9d9d9",borderWidth:Number(t.borderWidth||1),outerBorderLineStyle:t.outerBorderLineStyle||"solid",innerBorderHorizontalLineStyle:t.innerBorderHorizontalLineStyle||"solid",innerBorderVerticalLineStyle:t.innerBorderVerticalLineStyle||"solid",colWidths:Array.isArray(t.colWidths)?[...t.colWidths]:void 0,rowHeights:Array.isArray(t.rowHeights)?[...t.rowHeights]:void 0,outerBorder:t.outerBorder,innerBorder:t.innerBorder,cells:Array.isArray(t.cells)?t.cells.map(e=>({row:e.row,col:e.col,rowspan:Math.max(1,Number((e==null?void 0:e.rowspan)||1)),colspan:Math.max(1,Number((e==null?void 0:e.colspan)||1)),text:e.text,bindField:e.bindField,contentType:e.contentType||"text",fillCell:e.fillCell,contentScale:e.contentScale,imageFit:e.imageFit,qrLevel:e.qrLevel,qrRenderType:e.qrRenderType,barcodeFormat:e.barcodeFormat,decimalPlaces:e.decimalPlaces,roundHalfUp:e.roundHalfUp,amountType:e.amountType,autoWrap:e.autoWrap,autoFitFont:e.autoFitFont,align:e.align,verticalAlign:e.verticalAlign,fontSize:e.fontSize,color:e.color,backgroundColor:e.backgroundColor,hideBorderTop:e.hideBorderTop,hideBorderRight:e.hideBorderRight,hideBorderBottom:e.hideBorderBottom,hideBorderLeft:e.hideBorderLeft})):[]}:t.type==="reportHeader"||t.type==="reportFooter"?{text:t.text,bookmarkText:t.bookmarkText,keepTogether:t.keepTogether,centerWithDetail:t.centerWithDetail,refreshPage:t.refreshPage,visible:t.visible,stretch:t.stretch,shrink:t.shrink,printRepeated:t.printRepeated,printAtPageBottom:t.printAtPageBottom,removeBlankWhenNoData:t.removeBlankWhenNoData}:t.type==="qrcode"||t.type==="barcode"?{value:t.value}:{text:t.text,format:t.format}}}function be(t){return{engine:"native-template-style",version:"1.0.0",page:H({},t.page),elements:t.elements.map(e=>pe(e)),dataBinding:t.dataBinding||ge()}}function We(t,e=2){return JSON.stringify(be(t),null,e)}function De(t,e){const r=(l,x)=>Math.floor(Math.random()*(x-l+1))+l,a=l=>l[r(0,Math.max(0,l.length-1))],o=["标准件","不锈钢","铝板","铜件","塑胶件","辅料","组件"],s=["用于产线组装的关键部件需按工艺要求进行批次追溯与检验记录","该物料用于连续生产流程建议结合库存周转与批次有效期进行动态补料","本条数据为模拟长文本主要用于验证列宽变化后自动换行与字号自适应效果"],u=(l,x)=>`${l}_${a(o)}_${x+1}`,d=(l,x)=>`${l}_${x+1}_${a(s)}`,c=(l,x,$)=>$&&Math.random()<.45?d(l,x):u(l,x),b=l=>String(l||"").replace(/[^a-zA-Z0-9]/g,"_").replace(/_+/g,"_").replace(/^_+|_+$/g,"")||"CODE",m=l=>`QR_${b(l)}_${r(1e5,999999)}`,i=l=>`BAR${r(1e11,999999999999)}${b(l).slice(0,6).toUpperCase()}`,h=(l,x,$)=>$?`${l}_合并组${x+1}_${a(s)}`:`${l}_合并组${x+1}_${a(o)}`,n=l=>{var P;let x={};try{x=JSON.parse(e||"{}")}catch(M){x={}}if(!Array.isArray(x==null?void 0:x.elements))return Array.isArray(l==null?void 0:l.columns)?l.columns:[];const $=x.elements.find(M=>{const w=String((M==null?void 0:M.component)||"");return(M==null?void 0:M.id)===(l==null?void 0:l.id)&&(w==="table"||w==="detailTable")});return Array.isArray((P=$==null?void 0:$.payload)==null?void 0:P.columns)?$.payload.columns:Array.isArray(l==null?void 0:l.columns)?l.columns:[]},y=l=>{var W;const x=Array.isArray(l==null?void 0:l.cells)?l.cells:[];let $={};try{$=JSON.parse(e||"{}")}catch(v){$={}}if(!Array.isArray($==null?void 0:$.elements))return x;const P=$.elements.find(v=>(v==null?void 0:v.id)===(l==null?void 0:l.id)&&String((v==null?void 0:v.component)||"")==="freeTable"),M=(W=P==null?void 0:P.payload)==null?void 0:W.cells;if(!Array.isArray(M)||!M.length)return x;const w=new Map;return x.forEach(v=>{var R,q;const E=`${Number((R=v==null?void 0:v.row)!=null?R:0)}_${Number((q=v==null?void 0:v.col)!=null?q:0)}`;w.set(E,H({},v))}),M.forEach(v=>{var q,U;const E=`${Number((q=v==null?void 0:v.row)!=null?q:0)}_${Number((U=v==null?void 0:v.col)!=null?U:0)}`,R=w.get(E)||{};w.set(E,H(H({},R),v))}),Array.from(w.values())},f={},p=/{{\s*([\w.]+)\s*}}/g,S=(l,x,$)=>{const P=String(x||"").split(".").filter(Boolean);if(!P.length)return;let M=l;for(let w=0;w<P.length-1;w+=1){const W=P[w];(!M[W]||typeof M[W]!="object")&&(M[W]={}),M=M[W]}M[P[P.length-1]]=$},g=(l,x)=>{if(l)return String(x||"").split(".").filter(Boolean).reduce(($,P)=>$==null?void 0:$[P],l)};let T=1,C=1;return t.forEach(l=>{if(l.type==="table"||l.type==="detailTable"){const M=l.source||"mainTable",w=n(l),W=Array.isArray(l.mergeColumnKeys)?l.mergeColumnKeys:[],v=l.strictGrouping!==!1,E=W.map(k=>w.find(B=>String((B==null?void 0:B.key)||"")===String(k||""))).filter(Boolean).map(k=>String((k==null?void 0:k.bindField)||(k==null?void 0:k.field)||"")).filter(Boolean),R=r(6,10),q=[],U=Array.from({length:R}).map((k,B)=>{const F={},I=B>0?q[B-1]||{}:null;return w.forEach((A,D)=>{var Q;const N=String((A==null?void 0:A.bindField)||(A==null?void 0:A.field)||`field${D+1}`),z=(A==null?void 0:A.autoWrap)!==!1,L=String((A==null?void 0:A.contentType)||"text"),V=c(N,B,z),K=E.findIndex(j=>j===N),Y=K>=0,J=!v||K<=0||E.slice(0,K).every(j=>g(I,j)===g(F,j));if(Y&&B>0&&I&&J&&Math.random()<.5){const j=g(I,N);S(F,N,j!=null?j:h(N,r(0,3),z))}else if(Y)S(F,N,h(N,r(0,3),z));else if(L==="image")S(F,N,`https://picsum.photos/seed/${encodeURIComponent(`${N}_${B+1}`)}/260/120`);else if(L==="qrcode")S(F,N,m(N));else if(L==="barcode")S(F,N,i(N));else if(L==="number"||L==="amount"){const j=Math.max(0,Math.min(6,Number((Q=A==null?void 0:A.decimalPlaces)!=null?Q:2))),et=r(100,5e4)+Math.random(),_t=(A==null?void 0:A.roundHalfUp)===!1?Math.trunc(et*G(10,j))/G(10,j):Number(et.toFixed(j));S(F,N,_t)}else S(F,N,V)}),q.push(F),F});f[M]=U;return}if(l.type==="freeTable"){y(l).forEach((w,W)=>{var U;const v=String((w==null?void 0:w.bindField)||"").trim();if(!v||v in f)return;const E=String((w==null?void 0:w.text)||"").trim(),R=String((w==null?void 0:w.contentType)||"text"),q=(w==null?void 0:w.autoWrap)!==!1;if(R==="image")f[v]=`https://picsum.photos/seed/${encodeURIComponent(`${v}_ft`)}/260/120`;else if(R==="qrcode")f[v]=m(v||`ft${W}`);else if(R==="barcode")f[v]=i(v||`ft${W}`);else if(R==="number"||R==="amount"){const k=Math.max(0,Math.min(6,Number((U=w==null?void 0:w.decimalPlaces)!=null?U:2))),B=r(100,5e4)+Math.random(),F=(w==null?void 0:w.roundHalfUp)===!1?Math.trunc(B*G(10,k))/G(10,k):Number(B.toFixed(k));f[v]=F}else f[v]=E||c(v,0,q)});return}if(l.type==="qrcode"){const M=String(l.bindField||"").trim(),w=M||`qrcodeValue${T}`;f[w]=m(M||`qrcode${T}`),T+=1;return}if(l.type==="barcode"){const M=String(l.bindField||"").trim(),w=M||`barcodeValue${C}`;f[w]=i(M||`barcode${C}`),C+=1;return}const x=String(l.bindField||"").trim();x&&!(x in f)&&(l.type==="image"?f[x]="https://via.placeholder.com/180x80.png?text=Image":l.type==="date"?f[x]="2026-01-01":f[x]=`${x}_示例值`);const $=String(l.text||"");Array.from($.matchAll(p)).forEach(M=>{const w=String((M==null?void 0:M[1])||"").split(".")[0];w&&(w in f||(f[w]=`${w}_示例值`))})}),Object.keys(f).length||(f.docNo="DOC-001",f.orderNo="ORDER-001",f.mainTable=[{field1:"值1",field2:"值2",field3:"值3"}]),f}const dt=3.7795275591;function Z(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function Ht(){return{engine:"native",version:"1.0.0",page:{width:210,height:297,unit:"mm",margin:[10,10,10,10],gridSize:2},elements:[],dataBinding:{fieldMap:{},tableSources:["mainTable","detailList"],params:[],detailTables:[]}}}function ye(){return[{key:Z("col"),title:"列1",field:"field1",bindField:"field1",width:30,align:"left",contentType:"text",fontFamily:"",fontSize:12,useCustomFontSize:!1,fontColor:"#111111",autoFitFont:!1,autoWrap:!0,fillCell:!0,contentScale:100,imageFit:"contain",qrLevel:"M",qrRenderType:"image/png",barcodeFormat:"CODE128",decimalPlaces:2,roundHalfUp:!0,amountType:"CNY",enableFooterTotal:!1,mergeByValue:!1},{key:Z("col"),title:"列2",field:"field2",bindField:"field2",width:30,align:"left",contentType:"text",fontFamily:"",fontSize:12,useCustomFontSize:!1,fontColor:"#111111",autoFitFont:!1,autoWrap:!0,fillCell:!0,contentScale:100,imageFit:"contain",qrLevel:"M",qrRenderType:"image/png",barcodeFormat:"CODE128",decimalPlaces:2,roundHalfUp:!0,amountType:"CNY",enableFooterTotal:!1,mergeByValue:!1},{key:Z("col"),title:"列3",field:"field3",bindField:"field3",width:30,align:"left",contentType:"text",fontFamily:"",fontSize:12,useCustomFontSize:!1,fontColor:"#111111",autoFitFont:!1,autoWrap:!0,fillCell:!0,contentScale:100,imageFit:"contain",qrLevel:"M",qrRenderType:"image/png",barcodeFormat:"CODE128",decimalPlaces:2,roundHalfUp:!0,amountType:"CNY",enableFooterTotal:!1,mergeByValue:!1}]}function me(t,e,r="List1"){const a={id:Z(t),type:t,bindField:"",region:"body",bandId:"",x:20,y:20,w:60,h:12,zIndex:e};return t==="title"?_(H({},a),{type:t,text:"标题",h:14,style:{fontSize:20,fontWeight:700,textAlign:"center"}}):t==="subtitle"?_(H({},a),{type:t,text:"副标题",style:{fontSize:14,textAlign:"center"}}):t==="text"?_(H({},a),{type:t,text:"文本内容",style:{fontSize:12}}):t==="date"?_(H({},a),{type:t,text:"日期",format:"YYYY-MM-DD",style:{fontSize:12}}):t==="pageNo"?_(H({},a),{type:t,text:"第 {{pageNo}} / {{totalPages}} 页",style:{fontSize:12}}):t==="reportHeader"?_(H({},a),{type:t,x:10,y:10,w:190,h:16,region:"header",text:"",bookmarkText:"",keepTogether:!0,centerWithDetail:!0,refreshPage:"none",visible:!0,stretch:!1,shrink:!1,printRepeated:!1,style:{fontSize:12,fontWeight:600,textAlign:"left",backgroundColor:"#ffffff"}}):t==="reportFooter"?_(H({},a),{type:t,x:10,y:260,w:190,h:18,region:"footer",text:"",bookmarkText:"",keepTogether:!0,centerWithDetail:!0,refreshPage:"none",visible:!0,stretch:!1,shrink:!1,printRepeated:!1,printAtPageBottom:!1,removeBlankWhenNoData:!1,style:{fontSize:12,fontWeight:600,textAlign:"left",backgroundColor:"#ffffff"}}):t==="image"?_(H({},a),{type:t,w:36,h:24,src:"",fit:"contain"}):t==="qrcode"?_(H({},a),{type:t,w:24,h:24,value:"https://www.jeecg.com"}):t==="barcode"?_(H({},a),{type:t,w:48,h:18,value:"1234567890"}):t==="freeTable"?_(H({},a),{type:t,printRepeated:!1,w:120,h:50,rowCount:3,colCount:3,borderColor:"#d9d9d9",borderWidth:1,outerBorderLineStyle:"solid",innerBorderHorizontalLineStyle:"solid",innerBorderVerticalLineStyle:"solid",cells:Array.from({length:3}).flatMap((o,s)=>Array.from({length:3}).map((u,d)=>({row:s,col:d,rowspan:1,colspan:1,text:`单元格${s+1}-${d+1}`,bindField:"",align:"left",verticalAlign:"middle",fontSize:12,color:"#111111",backgroundColor:"#ffffff"})))}):_(H({},a),{type:t,w:120,h:36,source:r,mergeColumnKeys:[],strictGrouping:!0,enableMultiHeader:!1,tableHeightMode:"autoPage",fixedRows:5,showHeader:!0,rowHeight:8,headerHeight:10,headerFontSize:12,bodyFontSize:12,headerBgColor:"#f5f5f5",headerTextColor:"#111111",footerLabelColumnKey:"",footerLabelText:"合计",footerLabelCenter:!0,footerShowTotal:!0,footerTotalMode:"overall",columns:ye()})}function Ee(){const t=Dt({schema:Ht(),selectedId:"",scale:1}),e=Et(()=>t.schema.elements.find(f=>f.id===t.selectedId));function r(f){var S,g,T,C;const p=_(H({},f),{dataBinding:{fieldMap:H({},((S=f.dataBinding)==null?void 0:S.fieldMap)||{}),tableSources:Array.isArray((g=f.dataBinding)==null?void 0:g.tableSources)?[...f.dataBinding.tableSources]:["mainTable","detailList"],params:Array.isArray((T=f.dataBinding)==null?void 0:T.params)?[...f.dataBinding.params]:[],detailTables:Array.isArray((C=f.dataBinding)==null?void 0:C.detailTables)?f.dataBinding.detailTables.map(l=>_(H({},l),{fields:Array.isArray(l.fields)?[...l.fields]:[]})):[]}});t.schema=p,p.elements.some(l=>l.id===t.selectedId)||(t.selectedId="")}function a(f){var l,x,$;const p=Math.max(0,...t.schema.elements.map(P=>P.zIndex))+1,S=(x=(l=t.schema.dataBinding)==null?void 0:l.detailTables)!=null?x:[],g=S.length&&(($=S[0])!=null&&$.tableKey)?String(S[0].tableKey):"",C=me(f,p,f==="table"||f==="detailTable"?g||"List1":"");t.schema.elements.push(C),t.selectedId=C.id}function o(){t.selectedId&&(t.schema.elements=t.schema.elements.filter(f=>f.id!==t.selectedId),t.selectedId="")}function s(f,p){const S=t.schema.elements.find(g=>g.id===f);S&&Object.assign(S,p)}function u(f){t.selectedId=f}function d(f){const p=t.schema.dataBinding||{fieldMap:{},tableSources:["mainTable","detailList"],params:[],detailTables:[]};t.schema.dataBinding=H(H({},p),f)}function c(){const f=e.value;if(!f)return;const p=Math.max(0,...t.schema.elements.map(g=>g.zIndex))+1,S=JSON.parse(JSON.stringify(f));S.id=Z(f.type),S.x+=6,S.y+=6,S.zIndex=p,t.schema.elements.push(S),t.selectedId=S.id}function b(){const f=e.value;f&&(f.zIndex+=1)}function m(){const f=e.value;f&&(f.zIndex=Math.max(1,f.zIndex-1))}function i(f){t.scale=Math.min(2,Math.max(.2,f))}function h(){return JSON.stringify(t.schema)}function n(f){const p=JSON.parse(f||"{}");if((p==null?void 0:p.engine)!=="native"||!Array.isArray(p.elements)||!p.page)throw new Error("模板 JSON 不是原生设计器格式");r(p)}function y(){return{width:t.schema.page.width*dt,height:t.schema.page.height*dt}}return{MM_TO_PX:dt,state:t,selectedElement:e,setSchema:r,patchDataBinding:d,addElement:a,removeSelected:o,updateElement:s,setSelected:u,duplicateSelected:c,bringForward:b,sendBackward:m,setScale:i,serialize:h,deserialize:n,pagePxSize:y}}function Ie(t){var d,c,b,m,i,h,n,y;const e=Ht(),r=t;if(!r||r.engine!=="native")throw new Error("返回内容不是原生模板engine 需为 native");const a=H(H({},e.page),r.page||{});a.unit="mm",(!Array.isArray(a.margin)||a.margin.length<4)&&(a.margin=[...e.page.margin]);const o=Array.isArray(r.elements)?r.elements:[];let s=1;for(const f of o)f.id||(f.id=`${String(f.type||"el")}_${Math.random().toString(36).slice(2,10)}`),(f.zIndex==null||f.zIndex===void 0)&&(f.zIndex=s),s+=1;const u={fieldMap:H(H({},((d=e.dataBinding)==null?void 0:d.fieldMap)||{}),((c=r.dataBinding)==null?void 0:c.fieldMap)||{}),tableSources:Array.isArray((b=r.dataBinding)==null?void 0:b.tableSources)&&r.dataBinding.tableSources.length?[...r.dataBinding.tableSources]:[...((m=e.dataBinding)==null?void 0:m.tableSources)||["mainTable","detailList"]],params:Array.isArray((i=r.dataBinding)==null?void 0:i.params)?[...r.dataBinding.params]:[...((h=e.dataBinding)==null?void 0:h.params)||[]],detailTables:Array.isArray((n=r.dataBinding)==null?void 0:n.detailTables)?r.dataBinding.detailTables.map(f=>({tableKey:String(f.tableKey||""),label:f.label?String(f.label):void 0,fields:Array.isArray(f.fields)?f.fields.map(p=>({key:String(p.key||""),label:p.label?String(p.label):void 0})):[]})):[...((y=e.dataBinding)==null?void 0:y.detailTables)||[]]};return{engine:"native",version:String(r.version||"1.0.0"),page:a,elements:o,dataBinding:u}}function xe(t){const e=t.filter(o=>(o==null?void 0:o.type)==="freeTable"),r=t.filter(o=>(o==null?void 0:o.type)==="table"||(o==null?void 0:o.type)==="detailTable"),a=e.length?e:r;return a.length?a.reduce((o,s)=>{const u=Number(o.y)||0,d=Number(s.y)||0;if(d<u)return s;if(d>u)return o;const c=(Number(o.w)||0)*(Number(o.h)||0);return(Number(s.w)||0)*(Number(s.h)||0)>=c?s:o}):null}function Le(t){var i,h;const e=t.elements;if(!Array.isArray(e)||e.length===0)return t;const r=xe(e);if(!r)return t;const a=Number(r.y)||0,o=Number(r.x)||0,s=Number(r.w)||0,u=Number((i=t.page)==null?void 0:i.width)||210,d=((h=t.page)==null?void 0:h.margin)||[10,10,10,10],c=Number(d[0])||10,b=Number(d[1])||10,m=e.map(n=>{if((n==null?void 0:n.type)==="title"||(n==null?void 0:n.type)==="subtitle"){const y=Number(n.x)||0,f=Number(n.y)||0,p=Math.max(24,Number(n.w)||90),S=Math.max(8,Number(n.h)||14),g=f+S>a-1,T=y>o+s*.28;if(g||T){const C=o+s/2-p/2,l=Math.max(c,Math.min(u-b-p,C));return _(H({},n),{x:l,y:Math.max(2,a-S-8),style:_(H({},n.style||{}),{textAlign:"center"})})}}if((n==null?void 0:n.type)==="date"){const y=Number(n.x)||0,f=Number(n.y)||0,p=Math.max(28,Number(n.w)||55),S=Math.max(8,Number(n.h)||10),g=f+S>a+2,T=y+p<o+s*.5;if(g||T)return _(H({},n),{x:Math.max(c,u-b-p),y:Math.max(2,a-S-4),style:_(H({},n.style||{}),{textAlign:"right"})})}return n});return _(H({},t),{elements:m})}function qe(t){const e=t.elements.map(r=>{if((r==null?void 0:r.type)!=="table"&&(r==null?void 0:r.type)!=="detailTable"||r.enableMultiHeader!==!0)return r;const a=r.headerConfig,o=Array.isArray(a==null?void 0:a.cells)?a.cells:[],s=Math.max(1,Number((a==null?void 0:a.rowCount)||1)),u=o.filter(m=>{var i;return String((i=m==null?void 0:m.title)!=null?i:"").trim().length>0});if(u.length===0){const d=r,{headerConfig:m,enableMultiHeader:i}=d,h=at(d,["headerConfig","enableMultiHeader"]);return _(H({},h),{enableMultiHeader:!1})}if(s>=2&&u.length<s){const c=r,{headerConfig:m,enableMultiHeader:i}=c,h=at(c,["headerConfig","enableMultiHeader"]);return _(H({},h),{enableMultiHeader:!1})}if(o.length>=4&&u.length<Math.max(2,Math.ceil(o.length*.25))){const b=r,{headerConfig:m,enableMultiHeader:i}=b,h=at(b,["headerConfig","enableMultiHeader"]);return _(H({},h),{enableMultiHeader:!1})}return r});return _(H({},t),{elements:e})}function xt(t){return t*96/25.4}function ft(t){return t*25.4/96}function wt(t){const e=t.getBoundingClientRect();let r=0,a=0;const o=d=>{const c=d.getBoundingClientRect();r=Math.max(r,c.right-e.left),a=Math.max(a,c.bottom-e.top),Array.from(d.children).forEach(o)};o(t);const s=Math.max(1,Math.ceil(r),t.scrollWidth,t.clientWidth),u=Math.max(1,Math.ceil(a),t.scrollHeight,t.clientHeight);return{sw:s,sh:u}}function Mt(t){const e=new Uint8Array(t),r=32768;let a="";for(let o=0;o<e.length;o+=r){const s=e.subarray(o,o+r);a+=String.fromCharCode(...s)}return btoa(a)}function we(t){var e,r;try{return((r=(e=new DOMParser().parseFromString(t,"text/html").body)==null?void 0:e.innerHTML)==null?void 0:r.trim())||t}catch(a){return t}}function Me(o,s,u){return O(this,arguments,function*(t,e,r,a={}){const d=a.paginate!==!1,[{jsPDF:c},b]=yield Promise.all([yt(()=>import("./jspdf.es.min-CY_STL60.js"),__vite__mapDeps([0,1,2,3,4,5,6])),yt(()=>import("./html2canvas.esm-CviiA4BU.js"),[])]),m=b.default,i=document.createElement("div");i.style.position="fixed",i.style.left="-20000px",i.style.top="0",i.style.width="auto",i.style.maxWidth="none",i.style.overflow="visible",i.style.background="#fff",i.style.zIndex="-1",i.innerHTML=`<div class="lodop-print-root" style="width:${e}mm;min-width:${e}mm;margin:0;padding:0;background:#fff;overflow:visible;box-sizing:border-box;">${t}</div>`,document.body.appendChild(i);try{const h=i.querySelector(".lodop-print-root")||i;yield new Promise(k=>setTimeout(k,400));const n=()=>{const k=Math.max(h.scrollWidth,h.clientWidth,1),B=Math.max(h.scrollHeight,h.clientHeight,1);return{sw:k,sh:B}};let{sw:y,sh:f}=n();const p=xt(Math.max(1,e));y<p&&(h.style.width=`${p}px`),y>p&&(h.style.width=`${y}px`),{sw:y,sh:f}=n();let S=wt(h);y=Math.max(y,S.sw),f=Math.max(f,S.sh),h.style.minHeight=`${f}px`,h.style.width=`${Math.max(p,y)}px`,{sw:y,sh:f}=n(),S=wt(h),y=Math.max(y,S.sw),f=Math.max(f,S.sh);const g=12e3;let T=2;for(;Math.max(y,f)*T>g&&T>.75;)T-=.25;const C=yield m(h,{backgroundColor:"#ffffff",scale:T,useCORS:!0,allowTaint:!0,logging:!1,width:y,height:f,windowWidth:y,windowHeight:f,onclone:(k,B)=>{var A;const F=((A=B.querySelector)==null?void 0:A.call(B,".lodop-print-root"))||B;if(!F)return;F.style.minHeight=`${f}px`,F.style.width=`${y}px`,F.style.overflow="visible";const I=D=>{const N=D.style;(N.overflow==="hidden"||N.overflowX==="hidden"||N.overflowY==="hidden")&&N.setProperty("overflow","visible","important"),Array.from(D.children).forEach(z=>I(z))};I(F)}}),l=Math.max(1,C.width),x=Math.max(1,C.height),$=1;if(d){const k=Math.max(e,ft(y)+$),B=Math.max(1,r),F=Math.max(1,Math.round(xt(B)*T)),I=new c({unit:"mm",format:[k,B]});let A=0,D=!0;const N=Math.max(8,Math.floor(F*.02));for(;A<x;){const z=x-A;if(!D&&z<=N)break;const L=Math.min(F,z);if(L<1)break;const V=document.createElement("canvas");V.width=l,V.height=L;const K=V.getContext("2d");K&&(K.fillStyle="#ffffff",K.fillRect(0,0,l,L),K.drawImage(C,0,A,l,L,0,0,l,L));const Y=V.toDataURL("image/jpeg",.92),J=B*(L/F);D||I.addPage(),D=!1,I.addImage(Y,"JPEG",0,0,k,J),A+=F}return Mt(I.output("arraybuffer"))}const P=ft(y),M=ft(f),w=Math.max(e,P)+$,W=Math.max(r,M)+$,v=l/x;let E=Math.max(W,w/v),R=E*v;R<w&&(R=w,E=R/v);const q=new c({unit:"mm",format:[R,E]}),U=C.toDataURL("image/jpeg",.92);return q.addImage(U,"JPEG",0,0,R,E),Mt(q.output("arraybuffer"))}finally{i.remove()}})}const Ft="qhmes_print_dot_ws_url",At="qhmes_print_dot_key";function Bt(){return{wsUrl:localStorage.getItem(Ft)||"ws://127.0.0.1:1122/ws",key:localStorage.getItem(At)||""}}function Oe(t,e){localStorage.setItem(Ft,(t||"").trim()),localStorage.setItem(At,e!=null?e:"")}function kt(t,e){const r=(t||"").trim(),a=(e||"").trim();if(!a)return r;const o=r.includes("?")?"&":"?";return`${r}${o}key=${encodeURIComponent(a)}`}function Se(t=8e3){const{wsUrl:e,key:r}=Bt();return new Promise((a,o)=>{let s=!1;const u=new WebSocket(kt(e,r)),d=window.setTimeout(()=>{if(!s){s=!0;try{u.close()}catch(b){}o(new Error("连接 PrintDot 超时,请确认客户端已启动且 WebSocket 地址正确"))}},t),c=b=>{if(!s){s=!0,window.clearTimeout(d);try{u.close()}catch(m){}b()}};u.onmessage=b=>{try{const m=JSON.parse(b.data);if((m==null?void 0:m.type)==="printer_list"&&Array.isArray(m.data)){const i=m.data.map(h=>({name:String((h==null?void 0:h.name)||"").trim(),isDefault:(h==null?void 0:h.isDefault)===!0})).filter(h=>!!h.name);c(()=>a(i))}}catch(m){}},u.onerror=()=>{c(()=>o(new Error("无法连接 PrintDot WebSocket请检查地址与客户端是否运行")))}})}function $e(t){const e=String(t||"").trim();return/SumatraPDF\.exe not found/i.test(e)||/SUMATRAPDF_PATH/i.test(e)?`${e}。本地处理PrintDot 依赖 SumatraPDF 静默打印 PDF。请安装 Sumatra PDF 后任选其一:将 SumatraPDF.exe 放在 PrintDot 客户端 exe 同目录;或将 Sumatra 安装目录加入系统 PATH或设置用户/系统环境变量 SUMATRAPDF_PATH 指向 SumatraPDF.exe 的完整路径,然后重启 PrintDot。`:e}function Te(t){var o;const{wsUrl:e,key:r}=Bt(),a=(o=t.timeoutMs)!=null?o:18e4;return new Promise((s,u)=>{let d=!1;const c=new WebSocket(kt(e,r)),b=window.setTimeout(()=>{if(!d){d=!0;try{c.close()}catch(i){}u(new Error("PrintDot 打印等待结果超时"))}},a),m=(i,h)=>{if(!d){d=!0,window.clearTimeout(b);try{c.close()}catch(n){}s({ok:i,message:h})}};c.onopen=()=>{let i=String(t.pdfBase64||"").trim();if(i.startsWith("data:")){const n=i.indexOf(",");n!==-1&&(i=i.slice(n+1))}const h={printer:String(t.printer||"").trim(),content:i,job:{name:String(t.jobName||"QH-MES").trim()||"QH-MES",copies:Math.max(1,Number(t.copies)||1)}};c.send(JSON.stringify(h))},c.onmessage=i=>{try{const h=JSON.parse(i.data);if((h==null?void 0:h.type)==="printer_list")return;if(h!=null&&h.status){const n=h.status==="success",y=String(h.message||"");m(n,n?y:$e(y))}}catch(h){m(!1,"PrintDot 返回无法解析")}},c.onerror=()=>{if(!d){d=!0,window.clearTimeout(b);try{c.close()}catch(i){}u(new Error("PrintDot WebSocket 错误"))}}})}function ve(t,e){var o;const r=String(t||"").trim();if(r&&r!=="__system_default__")return r;const a=e.find(s=>s.isDefault);return(a==null?void 0:a.name)||((o=e[0])==null?void 0:o.name)||""}const Ce="print_template_selected_printer";function Ue(t){return O(this,null,function*(){var c,b;const e=yield ee(t.schema,t.data),r=we(e),a=yield Me(r,t.schema.page.width,t.schema.page.height,{paginate:!0}),o=yield Se(),s=(b=(c=t.printerSelection)!=null?c:localStorage.getItem(Ce))!=null?b:"__system_default__",u=ve(s,o);if(!u)throw new Error("未解析到可用打印机:请在模板列表选择打印机,或启动 PrintDot 后刷新打印机列表");const d=yield Te({printer:u,pdfBase64:a,jobName:t.jobName,timeoutMs:18e4});if(!d.ok)throw new Error(d.message||"PrintDot 打印失败")})}export{Ce as P,ee as a,Bt as b,Oe as c,Me as d,be as e,Se as f,De as g,qe as h,Le as i,Ie as n,Ue as p,he as r,We as s,Ee as u};