@oxog/printkit 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -18
- package/dist/chunk-E7TXCY3N.cjs +491 -0
- package/dist/chunk-E7TXCY3N.cjs.map +1 -0
- package/dist/chunk-N44HS34F.js +491 -0
- package/dist/chunk-N44HS34F.js.map +1 -0
- package/dist/errors-COjJm-gl.d.cts +291 -0
- package/dist/errors-COjJm-gl.d.ts +291 -0
- package/dist/index.cjs +1 -486
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -273
- package/dist/index.d.ts +32 -273
- package/dist/index.js +1 -486
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +1 -486
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +10 -125
- package/dist/react.d.ts +10 -125
- package/dist/react.js +1 -486
- package/dist/react.js.map +1 -1
- package/package.json +19 -11
package/dist/index.js
CHANGED
|
@@ -1,487 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
`)}function j(){let e=document.createElement("div");return e.style.cssText="position:absolute;left:-9999px;top:-9999px;visibility:hidden;",e}function J(e){document.body.appendChild(e);}function q(e){document.body.contains(e)&&document.body.removeChild(e);}function K(e){let t=e.querySelectorAll("img"),n=[];return t.forEach(r=>{r.complete||n.push(new Promise(i=>{r.onload=()=>i(),r.onerror=()=>i();}));}),Promise.all(n).then(()=>{})}function W(e){return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/on\w+="[^"]*"/gi,"").replace(/on\w+='[^']*'/gi,"").replace(/javascript:/gi,"")}function se(){let e=document.createElement("iframe");return e.style.cssText=`
|
|
3
|
-
position: fixed;
|
|
4
|
-
right: 0;
|
|
5
|
-
bottom: 0;
|
|
6
|
-
width: 0;
|
|
7
|
-
height: 0;
|
|
8
|
-
border: 0;
|
|
9
|
-
visibility: hidden;
|
|
10
|
-
opacity: 0;
|
|
11
|
-
pointer-events: none;
|
|
12
|
-
`,e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1"),e}function ae(e,t=3e4){return new Promise((n,r)=>{let i=setTimeout(()=>{r(l("IFRAME_LOAD_FAILED","Load timeout"));},t);e.onload=()=>{clearTimeout(i),requestAnimationFrame(()=>{requestAnimationFrame(()=>{n();});});},e.onerror=()=>{clearTimeout(i),r(l("IFRAME_LOAD_FAILED","Load error"));};})}function le(e,t){let n=e.contentDocument??e.contentWindow?.document;if(!n)throw l("IFRAME_LOAD_FAILED","Cannot access iframe document");n.open(),n.write(t),n.close();}function wt(e){e&&(e.onload=null,e.onerror=null,e.parentNode&&e.parentNode.removeChild(e));}function Tt(e){return new Promise((t,n)=>{try{let r=e.contentWindow;if(!r){n(l("IFRAME_LOAD_FAILED","Cannot access iframe window"));return}r.focus();let i=()=>{r.removeEventListener("afterprint",i),t();};r.addEventListener("afterprint",i),r.print(),setTimeout(()=>{r.removeEventListener("afterprint",i),t();},1e3);}catch(r){n(l("IFRAME_LOAD_FAILED",r instanceof Error?r.message:"Print failed"));}})}async function Et(e){let t=se();return document.body.appendChild(t),le(t,e),await ae(t),t}var Q={A3:{width:"297mm",height:"420mm"},A4:{width:"210mm",height:"297mm"},A5:{width:"148mm",height:"210mm"},Letter:{width:"8.5in",height:"11in"},Legal:{width:"8.5in",height:"14in"},Tabloid:{width:"11in",height:"17in"}};function f(e){return e===void 0?"0mm":typeof e=="number"?`${e}mm`:/\d+\s*(mm|cm|in|pt|px|%|em|rem)$/i.test(e)?e:`${e}mm`}function ce(e){return typeof e=="string"&&e in Q}function T(e,t="portrait"){let n;return ce(e)?n={...Q[e]}:n={width:f(e.width),height:f(e.height)},t==="landscape"?{width:n.height,height:n.width}:n}function Ot(e,t="portrait"){let n=T(e,t);return `
|
|
13
|
-
@page {
|
|
14
|
-
size: ${n.width} ${n.height};
|
|
15
|
-
}
|
|
16
|
-
`}function y(e,t="portrait",n=96){let r=T(e,t),i=o=>{let s=parseFloat(o);return o.endsWith("mm")?s/25.4*n:o.endsWith("cm")?s/2.54*n:o.endsWith("in")?s*n:o.endsWith("pt")?s/72*n:s};return {width:Math.round(i(r.width)),height:Math.round(i(r.height))}}var E=10;function O(e){if(e===void 0){let t=f(E);return {top:t,right:t,bottom:t,left:t}}if(typeof e=="number"){let t=f(e);return {top:t,right:t,bottom:t,left:t}}return {top:f(e.top??E),right:f(e.right??E),bottom:f(e.bottom??E),left:f(e.left??E)}}function St(e){let t=O(e);return `
|
|
17
|
-
@page {
|
|
18
|
-
margin: ${t.top} ${t.right} ${t.bottom} ${t.left};
|
|
19
|
-
}
|
|
20
|
-
`}function w(e,t=96){let n=O(e),r=i=>{let o=parseFloat(i);return i.endsWith("mm")?o/25.4*t:i.endsWith("cm")?o/2.54*t:i.endsWith("in")?o*t:i.endsWith("pt")?o/72*t:o};return {top:Math.round(r(n.top)),right:Math.round(r(n.right)),bottom:Math.round(r(n.bottom)),left:Math.round(r(n.left))}}var k="print-break-before",Z="print-break-after",G="print-avoid-break";function de(){let e=document.createElement("div");return e.className=k,e.style.cssText="height: 0; page-break-before: always; break-before: page;",e.setAttribute("aria-hidden","true"),e}function pe(e){e.classList.add(G);}function ue(e){e.classList.add(k);}function me(e){e.classList.add(Z);}function Lt(){return `
|
|
21
|
-
@media print {
|
|
22
|
-
.${k} {
|
|
23
|
-
page-break-before: always !important;
|
|
24
|
-
break-before: page !important;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.${Z} {
|
|
28
|
-
page-break-after: always !important;
|
|
29
|
-
break-after: page !important;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.${G} {
|
|
33
|
-
page-break-inside: avoid !important;
|
|
34
|
-
break-inside: avoid !important;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`}function Mt(e){let t=[];return e.pageBreakBefore&&t.push(`
|
|
38
|
-
@media print {
|
|
39
|
-
${e.pageBreakBefore} {
|
|
40
|
-
page-break-before: always !important;
|
|
41
|
-
break-before: page !important;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`),e.pageBreakAfter&&t.push(`
|
|
45
|
-
@media print {
|
|
46
|
-
${e.pageBreakAfter} {
|
|
47
|
-
page-break-after: always !important;
|
|
48
|
-
break-after: page !important;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
`),e.avoidBreakInside&&t.push(`
|
|
52
|
-
@media print {
|
|
53
|
-
${e.avoidBreakInside} {
|
|
54
|
-
page-break-inside: avoid !important;
|
|
55
|
-
break-inside: avoid !important;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
`),t.join(`
|
|
59
|
-
`)}function ge(e,t,n=0,r=0){let i=t-n-r;return i<=0?1:Math.ceil(e/i)}function X(e,t,n,r=new Date){return {pageNumber:e,totalPages:t,title:n,date:r}}function Dt(e,t){return e.replace(/\{page\}/gi,String(t.pageNumber)).replace(/\{pages\}/gi,String(t.totalPages)).replace(/\{title\}/gi,t.title).replace(/\{date\}/gi,t.date.toLocaleDateString()).replace(/\{time\}/gi,t.date.toLocaleTimeString())}function C(e,t){return e?typeof e=="function"?e(t):Dt(e,t):""}function At(e,t={}){return e?`
|
|
60
|
-
<header class="print-header" style="
|
|
61
|
-
${t.fixed?`
|
|
62
|
-
position: fixed;
|
|
63
|
-
top: 0;
|
|
64
|
-
left: 0;
|
|
65
|
-
right: 0;
|
|
66
|
-
`:""}
|
|
67
|
-
width: 100%;
|
|
68
|
-
box-sizing: border-box;
|
|
69
|
-
">
|
|
70
|
-
${e}
|
|
71
|
-
</header>
|
|
72
|
-
`:""}function kt(e,t={}){return e?`
|
|
73
|
-
<footer class="print-footer" style="
|
|
74
|
-
${t.fixed?`
|
|
75
|
-
position: fixed;
|
|
76
|
-
bottom: 0;
|
|
77
|
-
left: 0;
|
|
78
|
-
right: 0;
|
|
79
|
-
`:""}
|
|
80
|
-
width: 100%;
|
|
81
|
-
box-sizing: border-box;
|
|
82
|
-
">
|
|
83
|
-
${e}
|
|
84
|
-
</footer>
|
|
85
|
-
`:""}function Ct(){return `
|
|
86
|
-
@media print {
|
|
87
|
-
.print-header {
|
|
88
|
-
page-break-after: avoid;
|
|
89
|
-
}
|
|
90
|
-
.print-footer {
|
|
91
|
-
page-break-before: avoid;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.print-header,
|
|
96
|
-
.print-footer {
|
|
97
|
-
-webkit-print-color-adjust: exact;
|
|
98
|
-
print-color-adjust: exact;
|
|
99
|
-
}
|
|
100
|
-
`}function fe(){return `printkit-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function he(e){let t=fe(),n=document.createElement("style");return n.id=t,n.setAttribute("data-printkit","true"),n.textContent=e,document.head.appendChild(n),t}function ye(e){let t=document.getElementById(e);t&&t.remove();}function be(){document.querySelectorAll('style[data-printkit="true"]').forEach(t=>t.remove());}function Y(e){return `<style>${Array.isArray(e)?e.join(`
|
|
101
|
-
`):e}</style>`}function Pe(e){return `<link rel="stylesheet" href="${e}">`}function It(e){return e.map(Pe).join(`
|
|
102
|
-
`)}function V(e){let t=[];for(let n of e)n&&(Array.isArray(n)?t.push(...n):t.push(n));return t.join(`
|
|
103
|
-
`)}function xe(){let e=[];return document.querySelectorAll('link[rel="stylesheet"]').forEach(n=>{let r=n.href;r&&e.push(`<link rel="stylesheet" href="${r}">`);}),e}function ve(){let e=[];return document.querySelectorAll("style").forEach(n=>{if(n.hasAttribute("data-printkit"))return;let r=n.textContent;r&&e.push(`<style>${r}</style>`);}),e}function Nt(){return [...xe(),...ve()]}function $t(){return Nt().join(`
|
|
104
|
-
`)}function we(e){let t=window.getComputedStyle(e),n=[];for(let r=0;r<t.length;r++){let i=t[r];if(i){let o=t.getPropertyValue(i);o&&n.push(`${i}: ${o}`);}}return n.join("; ")}var Ft="print-hide",tt="print-only";function Ht(){return `
|
|
105
|
-
/* Print visibility classes */
|
|
106
|
-
@media print {
|
|
107
|
-
.${Ft},
|
|
108
|
-
.no-print {
|
|
109
|
-
display: none !important;
|
|
110
|
-
visibility: hidden !important;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.${tt},
|
|
114
|
-
.print-only {
|
|
115
|
-
display: block !important;
|
|
116
|
-
visibility: visible !important;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@media screen {
|
|
121
|
-
.${tt},
|
|
122
|
-
.print-only {
|
|
123
|
-
display: none !important;
|
|
124
|
-
visibility: hidden !important;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/* Default print optimizations */
|
|
129
|
-
@media print {
|
|
130
|
-
* {
|
|
131
|
-
-webkit-print-color-adjust: exact !important;
|
|
132
|
-
print-color-adjust: exact !important;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
body {
|
|
136
|
-
margin: 0;
|
|
137
|
-
padding: 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/* Remove backgrounds by default for better printing */
|
|
141
|
-
html {
|
|
142
|
-
background: white !important;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/* Ensure links are readable */
|
|
146
|
-
a[href]:after {
|
|
147
|
-
content: none !important;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* Prevent orphans and widows */
|
|
151
|
-
p, h1, h2, h3, h4, h5, h6 {
|
|
152
|
-
orphans: 3;
|
|
153
|
-
widows: 3;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/* Avoid breaking inside these elements */
|
|
157
|
-
h1, h2, h3, h4, h5, h6 {
|
|
158
|
-
page-break-after: avoid;
|
|
159
|
-
break-after: avoid;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
img {
|
|
163
|
-
page-break-inside: avoid;
|
|
164
|
-
break-inside: avoid;
|
|
165
|
-
max-width: 100% !important;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
table {
|
|
169
|
-
page-break-inside: auto;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
tr {
|
|
173
|
-
page-break-inside: avoid;
|
|
174
|
-
break-inside: avoid;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
thead {
|
|
178
|
-
display: table-header-group;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
tfoot {
|
|
182
|
-
display: table-footer-group;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
`}function Rt(){return `
|
|
186
|
-
*, *::before, *::after {
|
|
187
|
-
box-sizing: border-box;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
html {
|
|
191
|
-
font-size: 16px;
|
|
192
|
-
line-height: 1.5;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
body {
|
|
196
|
-
margin: 0;
|
|
197
|
-
padding: 0;
|
|
198
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
199
|
-
'Helvetica Neue', Arial, sans-serif;
|
|
200
|
-
color: #000;
|
|
201
|
-
background: #fff;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
img {
|
|
205
|
-
max-width: 100%;
|
|
206
|
-
height: auto;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
table {
|
|
210
|
-
border-collapse: collapse;
|
|
211
|
-
width: 100%;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
th, td {
|
|
215
|
-
text-align: left;
|
|
216
|
-
padding: 8px;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
pre, code {
|
|
220
|
-
font-family: 'Courier New', Courier, monospace;
|
|
221
|
-
font-size: 14px;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
pre {
|
|
225
|
-
white-space: pre-wrap;
|
|
226
|
-
word-wrap: break-word;
|
|
227
|
-
overflow-x: auto;
|
|
228
|
-
}
|
|
229
|
-
`}function Te(){return `
|
|
230
|
-
@media print {
|
|
231
|
-
* {
|
|
232
|
-
-webkit-print-color-adjust: exact !important;
|
|
233
|
-
print-color-adjust: exact !important;
|
|
234
|
-
color-adjust: exact !important;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
`}function et(){return [Rt(),Ht(),Te()].join(`
|
|
238
|
-
`)}var _t={pageSize:"A4",orientation:"portrait"};function d(e,t={}){let n=t.pageSize??_t.pageSize,r=t.orientation??_t.orientation,i=T(n,r),o=O(t.margin),s=X(1,1,t.title??"Print Document"),a=C(t.header,s),c=C(t.footer,s),b=V([et(),Ot(n,r),St(t.margin),Lt(),Mt({pageBreakBefore:t.pageBreakBefore,pageBreakAfter:t.pageBreakAfter,avoidBreakInside:t.avoidBreakInside}),Ct(),t.printBackground?"":"body { background: white !important; }",Array.isArray(t.styles)?t.styles.join(`
|
|
239
|
-
`):t.styles]);return {content:e,styles:b,header:a,footer:c,pageSize:i,margins:o,title:t.title??"Print Document"}}function p(e,t={}){let n=t.copyStyles!==false?$t():"",r=t.styleSheets?It(t.styleSheets):"";return `
|
|
240
|
-
<!DOCTYPE html>
|
|
241
|
-
<html>
|
|
242
|
-
<head>
|
|
243
|
-
<meta charset="utf-8">
|
|
244
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
245
|
-
<title>${e.title}</title>
|
|
246
|
-
${n}
|
|
247
|
-
${r}
|
|
248
|
-
${Y(e.styles)}
|
|
249
|
-
</head>
|
|
250
|
-
<body>
|
|
251
|
-
${e.header?At(e.header):""}
|
|
252
|
-
<main class="print-content">
|
|
253
|
-
${e.content}
|
|
254
|
-
</main>
|
|
255
|
-
${e.footer?kt(e.footer):""}
|
|
256
|
-
</body>
|
|
257
|
-
</html>
|
|
258
|
-
`}async function u(e,t={}){t.onBeforePrint&&await t.onBeforePrint();let n=null;try{n=await Et(e),await Tt(n),t.onAfterPrint&&t.onAfterPrint();}catch(r){throw t.onError&&t.onError(r),r}finally{t.removeAfterPrint!==false&&wt(n);}}async function zt(e,t={}){let n=x(e);for(let s of n)await K(s);let r=A(n),i=d(r,t),o=p(i,t);await u(o,t);}function Ee(e){if(!e||typeof e!="string")throw l("ELEMENT_NOT_FOUND","HTML content is empty or invalid");if(e.trim().length===0)throw l("ELEMENT_NOT_FOUND","HTML content is empty")}function Oe(e){let t=e.toLowerCase().trim();return t.includes("<!doctype")||t.includes("<html")}function Se(e){let t=e.match(/<body[^>]*>([\s\S]*?)<\/body>/i);return t?.[1]?t[1]:e}function Le(e){let t=[],n=e.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gi);for(let i of n)i[1]&&t.push(i[1]);let r=e.matchAll(/<link[^>]*rel=["']stylesheet["'][^>]*>/gi);for(let i of r)t.push(i[0]);return t}async function I(e,t={}){Ee(e);let n=W(e),r,i=[];Oe(n)?(r=Se(n),i=Le(n)):r=n;let o=Array.isArray(t.styles)?[...t.styles,...i]:t.styles?[t.styles,...i]:i,s=d(r,{...t,styles:o.length>0?o:void 0}),a=p(s,t);await u(a,t);}function Me(e){if(!e||typeof e!="string")throw l("ELEMENT_NOT_FOUND","URL is empty or invalid");try{new URL(e,window.location.origin);}catch{throw l("ELEMENT_NOT_FOUND",`Invalid URL: ${e}`)}}async function De(e){try{let t=await fetch(e,{method:"GET",headers:{Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}});if(!t.ok)throw l("IFRAME_LOAD_FAILED",`Failed to fetch URL: ${t.status} ${t.statusText}`);return await t.text()}catch(t){throw t instanceof Error&&t.name==="PrintError"?t:l("IFRAME_LOAD_FAILED",`Failed to fetch URL: ${t instanceof Error?t.message:"Unknown error"}`)}}async function Bt(e,t={}){Me(e);let n=new URL(e,window.location.origin).href;try{let r=await De(n);await I(r,{...t,title:t.title??n});}catch(r){throw t.onError&&t.onError(r),r}}function Ut(e,t){let n=document.createElement("canvas");return n.width=e,n.height=t,n}function jt(e){let t=e.getContext("2d");if(!t)throw l("PDF_EXPORT_FAILED","Cannot get canvas 2D context");return t}function Jt(e,t=.92){return e.toDataURL("image/jpeg",t)}function nt(e){return new Promise((t,n)=>{let r=new Image;r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>n(l("ELEMENT_NOT_FOUND",`Failed to load image: ${e}`)),r.src=e;})}function rt(e){return typeof e=="string"?e:e.src}function qt(e){let t=rt(e);if(!t||t.trim().length===0)throw l("ELEMENT_NOT_FOUND","Image source is empty")}function Kt(e,t="",n={}){let r=n.fit==="cover"?"object-fit: cover;":n.fit==="fill"?"object-fit: fill;":"object-fit: contain;";return `
|
|
259
|
-
<div class="print-image-container" style="
|
|
260
|
-
display: flex;
|
|
261
|
-
justify-content: center;
|
|
262
|
-
align-items: center;
|
|
263
|
-
width: 100%;
|
|
264
|
-
height: 100%;
|
|
265
|
-
page-break-inside: avoid;
|
|
266
|
-
">
|
|
267
|
-
<img
|
|
268
|
-
src="${e}"
|
|
269
|
-
alt="${t}"
|
|
270
|
-
style="
|
|
271
|
-
max-width: 100%;
|
|
272
|
-
max-height: 100%;
|
|
273
|
-
${r}
|
|
274
|
-
"
|
|
275
|
-
/>
|
|
276
|
-
</div>
|
|
277
|
-
`}function Ae(e,t={}){return e.map((n,r)=>`
|
|
278
|
-
<div class="print-image-page" style="
|
|
279
|
-
page-break-after: ${r<e.length-1?"always":"auto"};
|
|
280
|
-
min-height: 100vh;
|
|
281
|
-
display: flex;
|
|
282
|
-
justify-content: center;
|
|
283
|
-
align-items: center;
|
|
284
|
-
">
|
|
285
|
-
${Kt(n,`Image ${r+1}`,t)}
|
|
286
|
-
</div>
|
|
287
|
-
`).join("")}function Wt(){return `
|
|
288
|
-
.print-image-container {
|
|
289
|
-
page-break-inside: avoid;
|
|
290
|
-
break-inside: avoid;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
.print-image-page {
|
|
294
|
-
page-break-inside: avoid;
|
|
295
|
-
break-inside: avoid;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
@media print {
|
|
299
|
-
.print-image-container img {
|
|
300
|
-
max-width: 100% !important;
|
|
301
|
-
max-height: 100% !important;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
`}async function Qt(e,t={}){qt(e);let n=rt(e);await nt(n);let r=Kt(n,t.title??"Image"),i=d(r,{...t,styles:[Wt(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),o=p(i,t);await u(o,t);}async function Zt(e,t={}){if(!e||e.length===0)throw l("ELEMENT_NOT_FOUND","No images provided");for(let s of e)qt(s);let n=e.map(rt);await Promise.all(n.map(nt));let r=Ae(n),i=d(r,{...t,styles:[Wt(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),o=p(i,t);await u(o,t);}var S={string:"#22863a",number:"#005cc5",boolean:"#d73a49",null:"#6f42c1",key:"#032f62"};function it(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ke(e){return e.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,t=>{let n=S.number;if(/^"/.test(t)){if(/:$/.test(t))return n=S.key,t=t.replace(/:$/,""),`<span style="color:${n}">${it(t)}</span>:`;n=S.string;}else /true|false/.test(t)?n=S.boolean:/null/.test(t)&&(n=S.null);return `<span style="color:${n}">${it(t)}</span>`})}function Ce(e,t=2){try{return JSON.stringify(e,null,t)}catch{throw l("UNKNOWN","Failed to stringify JSON data")}}function Ie(e,t={}){let{indent:n=2,syntaxHighlight:r=false}=t,i=Ce(e,n);return `
|
|
305
|
-
<pre class="print-json" style="
|
|
306
|
-
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
|
307
|
-
font-size: 12px;
|
|
308
|
-
line-height: 1.5;
|
|
309
|
-
white-space: pre-wrap;
|
|
310
|
-
word-wrap: break-word;
|
|
311
|
-
overflow-wrap: break-word;
|
|
312
|
-
padding: 16px;
|
|
313
|
-
margin: 0;
|
|
314
|
-
background: #f6f8fa;
|
|
315
|
-
border-radius: 6px;
|
|
316
|
-
border: 1px solid #e1e4e8;
|
|
317
|
-
"><code>${r?ke(i):it(i)}</code></pre>
|
|
318
|
-
`}function Ne(){return `
|
|
319
|
-
.print-json {
|
|
320
|
-
page-break-inside: auto;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
.print-json code {
|
|
324
|
-
display: block;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
@media print {
|
|
328
|
-
.print-json {
|
|
329
|
-
background: #f6f8fa !important;
|
|
330
|
-
border: 1px solid #e1e4e8 !important;
|
|
331
|
-
-webkit-print-color-adjust: exact;
|
|
332
|
-
print-color-adjust: exact;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
`}async function Gt(e,t={}){if(e===void 0)throw l("ELEMENT_NOT_FOUND","JSON data is undefined");let n=Ie(e,t),r=d(n,{...t,styles:[Ne(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),i=p(r,t);await u(i,t);}function ot(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function $e(e){if(!e)throw l("ELEMENT_NOT_FOUND","Table data is empty");if(!Array.isArray(e.headers)||e.headers.length===0)throw l("ELEMENT_NOT_FOUND","Table headers are required");if(!Array.isArray(e.rows))throw l("ELEMENT_NOT_FOUND","Table rows must be an array")}function Fe(e,t={}){let n=t.headerStyles??"",r=t.cellStyles??"",i=e.map(o=>`<th style="${r}">${ot(o)}</th>`).join("");return `
|
|
336
|
-
<thead style="${n}">
|
|
337
|
-
<tr>${i}</tr>
|
|
338
|
-
</thead>
|
|
339
|
-
`}function He(e,t,n={}){let r=n.cellStyles??"",o=n.stripedRows&&t%2===1?"background-color: #f9f9f9;":"",s=e.map(a=>`<td style="${r}">${ot(a)}</td>`).join("");return `<tr style="${o}">${s}</tr>`}function Re(e,t={}){return `<tbody>${e.map((r,i)=>He(r,i,t)).join("")}</tbody>`}function _e(e,t={}){let n=t.tableStyles??"",i=t.bordered!==false?"border: 1px solid #ddd; border-collapse: collapse;":"border-collapse: collapse;",o=e.caption?`<caption style="padding: 10px; font-weight: bold; text-align: left;">${ot(e.caption)}</caption>`:"";return `
|
|
340
|
-
<table class="print-table" style="
|
|
341
|
-
width: 100%;
|
|
342
|
-
${i}
|
|
343
|
-
${n}
|
|
344
|
-
">
|
|
345
|
-
${o}
|
|
346
|
-
${Fe(e.headers,t)}
|
|
347
|
-
${Re(e.rows,t)}
|
|
348
|
-
</table>
|
|
349
|
-
`}function ze(e={}){return `
|
|
350
|
-
.print-table {
|
|
351
|
-
page-break-inside: auto;
|
|
352
|
-
border-collapse: collapse;
|
|
353
|
-
width: 100%;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
.print-table thead {
|
|
357
|
-
display: table-header-group;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
.print-table tfoot {
|
|
361
|
-
display: table-footer-group;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
.print-table tbody tr {
|
|
365
|
-
page-break-inside: avoid;
|
|
366
|
-
break-inside: avoid;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
.print-table th,
|
|
370
|
-
.print-table td {
|
|
371
|
-
padding: 8px 12px;
|
|
372
|
-
text-align: left;
|
|
373
|
-
vertical-align: top;
|
|
374
|
-
${e.bordered!==false?"border: 1px solid #ddd;":""}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
.print-table th {
|
|
378
|
-
font-weight: bold;
|
|
379
|
-
background-color: #f5f5f5;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
@media print {
|
|
383
|
-
.print-table {
|
|
384
|
-
-webkit-print-color-adjust: exact;
|
|
385
|
-
print-color-adjust: exact;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
.print-table th {
|
|
389
|
-
background-color: #f5f5f5 !important;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
.print-table tbody tr:nth-child(even) {
|
|
393
|
-
background-color: #f9f9f9 !important;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
`}async function Xt(e,t={}){$e(e);let n=_e(e,t),r=d(n,{...t,styles:[ze(t),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),i=p(r,t);await u(i,t);}var N={title:"Print Document",pageSize:"A4",orientation:"portrait",copyStyles:true,removeAfterPrint:true,printBackground:true};function h(e,t){return t?{...e,...t,margin:t.margin!==void 0?t.margin:e.margin,styles:Be(e.styles,t.styles),styleSheets:Ue(e.styleSheets,t.styleSheets)}:{...e}}function Be(e,t){if(!t)return e;if(!e)return t;let n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t];return [...n,...r]}function Ue(e,t){return t?e?[...e,...t]:t:e}function st(e){e.pageSize!==void 0&&(typeof e.pageSize=="string"?["A3","A4","A5","Letter","Legal","Tabloid"].includes(e.pageSize)||console.warn(`Invalid page size: ${e.pageSize}. Using default.`):typeof e.pageSize=="object"&&(e.pageSize.width===void 0||e.pageSize.height===void 0)&&console.warn("Custom page size must have width and height.")),e.orientation!==void 0&&(["portrait","landscape"].includes(e.orientation)||console.warn(`Invalid orientation: ${e.orientation}. Using default.`)),e.margin!==void 0&&typeof e.margin=="number"&&e.margin<0&&console.warn("Margin cannot be negative.");}var lt=class{constructor(t){m()||console.warn("Printing is not supported in this environment"),this.defaultOptions={...N,...t},t&&st(t);}async print(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await zt(t,r);}async printHTML(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await I(t,r);}async printURL(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await Bt(t,r);}async printImage(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await Qt(t,r);}async printImages(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await Zt(t,r);}async printJSON(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await Gt(t,r);}async printTable(t,n){if(!m())throw l("PRINT_NOT_SUPPORTED");let r=h(this.defaultOptions,n);await Xt(t,r);}setDefaultOptions(t){st(t),this.defaultOptions=h(this.defaultOptions,t);}getDefaultOptions(){return {...this.defaultOptions}}destroy(){}};function $(e){return new lt(e)}var at=null;function je(){return at||(at=$()),at}var Je={width:"90%",height:"85%",showToolbar:true,showPageNumbers:true,zoom:100,className:""},qe={print:true,download:true,zoom:true,navigation:true,close:true},L=[25,50,75,100,125,150,175,200],Yt=25,Vt=200,F=25,ct=class{constructor(t,n){this.modal=null;this.contentContainer=null;this.currentPage=1;this.totalPages=1;this.zoomLevel=100;this.isModalOpen=false;this.target=t,this.options={...N,...n},this.modalOptions={...Je,...n?.modal},this.toolbarOptions={...qe,...n?.toolbar},this.zoomLevel=this.modalOptions.zoom,this.boundHandleKeydown=this.handleKeydown.bind(this);}open(){this.isModalOpen||(this.createModal(),this.renderContent(),this.calculatePages(),this.attachEventListeners(),this.isModalOpen=true);}close(){this.isModalOpen&&(this.removeEventListeners(),this.destroyModal(),this.isModalOpen=false,this.options.onClose&&this.options.onClose());}async print(){let t=x(this.target),n=A(t),r=d(n,this.options),i=p(r,this.options);await u(i,this.options),this.options.onPrint&&this.options.onPrint();}async download(t="document.pdf"){console.log(`Download requested: ${t}`),await this.print(),this.options.onDownload&&this.options.onDownload();}setZoom(t){this.zoomLevel=Math.max(Yt,Math.min(Vt,t)),this.updateZoom();}getZoom(){return this.zoomLevel}zoomIn(){let t=L.indexOf(this.zoomLevel);t<L.length-1?this.zoomLevel=L[t+1]??this.zoomLevel+F:this.zoomLevel=Math.min(Vt,this.zoomLevel+F),this.updateZoom();}zoomOut(){let t=L.indexOf(this.zoomLevel);t>0?this.zoomLevel=L[t-1]??this.zoomLevel-F:this.zoomLevel=Math.max(Yt,this.zoomLevel-F),this.updateZoom();}resetZoom(){this.zoomLevel=100,this.updateZoom();}nextPage(){this.currentPage<this.totalPages&&(this.currentPage++,this.scrollToPage(this.currentPage));}prevPage(){this.currentPage>1&&(this.currentPage--,this.scrollToPage(this.currentPage));}goToPage(t){t>=1&&t<=this.totalPages&&(this.currentPage=t,this.scrollToPage(this.currentPage));}getCurrentPage(){return this.currentPage}getTotalPages(){return this.totalPages}isOpen(){return this.isModalOpen}destroy(){this.close(),this.target=null;}createModal(){this.modal=document.createElement("div"),this.modal.className=`printkit-preview-modal ${this.modalOptions.className}`.trim(),this.modal.style.cssText=`
|
|
397
|
-
position: fixed;
|
|
398
|
-
top: 0;
|
|
399
|
-
left: 0;
|
|
400
|
-
right: 0;
|
|
401
|
-
bottom: 0;
|
|
402
|
-
background: rgba(0, 0, 0, 0.75);
|
|
403
|
-
display: flex;
|
|
404
|
-
flex-direction: column;
|
|
405
|
-
align-items: center;
|
|
406
|
-
justify-content: center;
|
|
407
|
-
z-index: 999999;
|
|
408
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
409
|
-
`;let t=document.createElement("div");t.className="printkit-preview-container",t.style.cssText=`
|
|
410
|
-
width: ${typeof this.modalOptions.width=="number"?`${this.modalOptions.width}px`:this.modalOptions.width};
|
|
411
|
-
height: ${typeof this.modalOptions.height=="number"?`${this.modalOptions.height}px`:this.modalOptions.height};
|
|
412
|
-
display: flex;
|
|
413
|
-
flex-direction: column;
|
|
414
|
-
background: #f5f5f5;
|
|
415
|
-
border-radius: 8px;
|
|
416
|
-
overflow: hidden;
|
|
417
|
-
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
|
418
|
-
`,this.modalOptions.showToolbar&&t.appendChild(this.createToolbar()),this.contentContainer=document.createElement("div"),this.contentContainer.className="printkit-preview-content",this.contentContainer.style.cssText=`
|
|
419
|
-
flex: 1;
|
|
420
|
-
overflow: auto;
|
|
421
|
-
padding: 20px;
|
|
422
|
-
display: flex;
|
|
423
|
-
flex-direction: column;
|
|
424
|
-
align-items: center;
|
|
425
|
-
gap: 20px;
|
|
426
|
-
`,t.appendChild(this.contentContainer),this.modal.appendChild(t),document.body.appendChild(this.modal);}createToolbar(){let t=document.createElement("div");t.className="printkit-preview-toolbar",t.style.cssText=`
|
|
427
|
-
display: flex;
|
|
428
|
-
align-items: center;
|
|
429
|
-
justify-content: space-between;
|
|
430
|
-
padding: 12px 16px;
|
|
431
|
-
background: #fff;
|
|
432
|
-
border-bottom: 1px solid #e0e0e0;
|
|
433
|
-
`;let n=document.createElement("div");n.style.cssText="display: flex; align-items: center; gap: 8px;";let r=document.createElement("div");r.style.cssText="display: flex; align-items: center; gap: 8px;";let i=document.createElement("div");if(i.style.cssText="display: flex; align-items: center; gap: 8px;",this.toolbarOptions.navigation){let o=this.createButton("< Prev",()=>this.prevPage()),s=this.createButton("Next >",()=>this.nextPage()),a=document.createElement("span");a.className="printkit-page-info",a.style.cssText="font-size: 14px; color: #666;",a.textContent=`Page ${this.currentPage} of ${this.totalPages}`,n.appendChild(o),n.appendChild(a),n.appendChild(s);}if(this.toolbarOptions.zoom){let o=this.createButton("-",()=>this.zoomOut()),s=document.createElement("span");s.className="printkit-zoom-level",s.style.cssText="font-size: 14px; min-width: 50px; text-align: center;",s.textContent=`${this.zoomLevel}%`;let a=this.createButton("+",()=>this.zoomIn()),c=this.createButton("Reset",()=>this.resetZoom());r.appendChild(o),r.appendChild(s),r.appendChild(a),r.appendChild(c);}if(this.toolbarOptions.print){let o=this.createButton("Print",()=>this.print(),true);i.appendChild(o);}if(this.toolbarOptions.download){let o=this.createButton("Download",()=>this.download());i.appendChild(o);}if(this.toolbarOptions.close){let o=this.createButton("Close",()=>this.close());o.style.marginLeft="8px",i.appendChild(o);}return t.appendChild(n),t.appendChild(r),t.appendChild(i),t}createButton(t,n,r=false){let i=document.createElement("button");return i.textContent=t,i.onclick=n,i.style.cssText=`
|
|
434
|
-
padding: 6px 12px;
|
|
435
|
-
border: 1px solid ${r?"#0066cc":"#ccc"};
|
|
436
|
-
border-radius: 4px;
|
|
437
|
-
background: ${r?"#0066cc":"#fff"};
|
|
438
|
-
color: ${r?"#fff":"#333"};
|
|
439
|
-
font-size: 14px;
|
|
440
|
-
cursor: pointer;
|
|
441
|
-
transition: all 0.2s;
|
|
442
|
-
`,i.onmouseover=()=>{i.style.opacity="0.8";},i.onmouseout=()=>{i.style.opacity="1";},i}renderContent(){if(this.contentContainer)try{let t=x(this.target),n=y(this.options.pageSize??"A4",this.options.orientation??"portrait"),r=w(this.options.margin),i=document.createElement("div");i.className="printkit-page",i.style.cssText=`
|
|
443
|
-
width: ${n.width}px;
|
|
444
|
-
min-height: ${n.height}px;
|
|
445
|
-
background: white;
|
|
446
|
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
447
|
-
padding: ${r.top}px ${r.right}px ${r.bottom}px ${r.left}px;
|
|
448
|
-
box-sizing: border-box;
|
|
449
|
-
transform-origin: top center;
|
|
450
|
-
transform: scale(${this.zoomLevel/100});
|
|
451
|
-
`;for(let o of t){let s=v(o);i.appendChild(s);}this.contentContainer.appendChild(i);}catch(t){let n=document.createElement("div");n.style.cssText="color: red; padding: 20px;",n.textContent=t instanceof Error?t.message:"Failed to load content",this.contentContainer.appendChild(n);}}calculatePages(){if(!this.contentContainer)return;let t=y(this.options.pageSize??"A4",this.options.orientation??"portrait"),n=w(this.options.margin),r=t.height-n.top-n.bottom,i=this.contentContainer.querySelectorAll(".printkit-page"),o=0;i.forEach(s=>{o+=s.scrollHeight;}),this.totalPages=Math.max(1,Math.ceil(o/r)),this.updatePageInfo();}updateZoom(){if(!this.contentContainer)return;this.contentContainer.querySelectorAll(".printkit-page").forEach(r=>{r.style.transform=`scale(${this.zoomLevel/100})`;});let n=this.modal?.querySelector(".printkit-zoom-level");n&&(n.textContent=`${this.zoomLevel}%`);}updatePageInfo(){let t=this.modal?.querySelector(".printkit-page-info");t&&(t.textContent=`Page ${this.currentPage} of ${this.totalPages}`);}scrollToPage(t){if(!this.contentContainer)return;let n=y(this.options.pageSize??"A4",this.options.orientation??"portrait"),r=(t-1)*(n.height+20)*(this.zoomLevel/100);this.contentContainer.scrollTop=r,this.updatePageInfo();}attachEventListeners(){document.addEventListener("keydown",this.boundHandleKeydown);}removeEventListeners(){document.removeEventListener("keydown",this.boundHandleKeydown);}handleKeydown(t){if(this.isModalOpen)switch(t.key){case "Escape":this.close();break;case "ArrowLeft":this.prevPage();break;case "ArrowRight":this.nextPage();break;case "+":case "=":(t.ctrlKey||t.metaKey)&&(t.preventDefault(),this.zoomIn());break;case "-":(t.ctrlKey||t.metaKey)&&(t.preventDefault(),this.zoomOut());break}}destroyModal(){this.modal&&(this.modal.remove(),this.modal=null),this.contentContainer=null,this.currentPage=1;}};function Ke(e,t){return new ct(e,t)}function H(e){return e.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")}function We(e){let t=c=>c.toString().padStart(2,"0"),n=e.getFullYear(),r=t(e.getMonth()+1),i=t(e.getDate()),o=t(e.getHours()),s=t(e.getMinutes()),a=t(e.getSeconds());return `D:${n}${r}${i}${o}${s}${a}`}function Qe(e){let t=[];return e?.title&&t.push(`/Title (${H(e.title)})`),e?.author&&t.push(`/Author (${H(e.author)})`),e?.subject&&t.push(`/Subject (${H(e.subject)})`),e?.keywords&&t.push(`/Keywords (${H(e.keywords.join(", "))})`),t.push("/Creator (PrintKit)"),t.push("/Producer (PrintKit)"),t.push(`/CreationDate (${We(e?.creationDate??new Date)})`),t.join(`
|
|
452
|
-
`)}function Ze(e){let t=e.replace(/^data:image\/jpeg;base64,/,""),n=atob(t),r=new Uint8Array(n.length);for(let a=0;a<n.length;a++)r[a]=n.charCodeAt(a);let i=0,o=0,s=2;for(;s<r.length&&r[s]===255;){let a=r[s+1];if(a===void 0)break;if(a===192||a===194){o=(r[s+5]??0)<<8|(r[s+6]??0),i=(r[s+7]??0)<<8|(r[s+8]??0);break}let c=(r[s+2]??0)<<8|(r[s+3]??0);s+=2+c;}return {data:r,width:i,height:o}}function Ge(e,t,n,r){let i=Ze(e),o=[],s=[],a=0,c=`%PDF-1.4
|
|
453
|
-
%\xFF\xFF\xFF\xFF
|
|
454
|
-
`;a=c.length,s.push(a);let b=`1 0 obj
|
|
455
|
-
<< /Type /Catalog /Pages 2 0 R >>
|
|
456
|
-
endobj
|
|
457
|
-
`;o.push(b),a+=b.length,s.push(a);let mt=`2 0 obj
|
|
458
|
-
<< /Type /Pages /Kids [3 0 R] /Count 1 >>
|
|
459
|
-
endobj
|
|
460
|
-
`;o.push(mt),a+=mt.length,s.push(a);let gt=`3 0 obj
|
|
461
|
-
<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${t} ${n}] /Contents 4 0 R /Resources << /XObject << /Im0 5 0 R >> >> >>
|
|
462
|
-
endobj
|
|
463
|
-
`;o.push(gt),a+=gt.length;let ft=`q ${t} 0 0 ${n} 0 0 cm /Im0 Do Q`;s.push(a);let ht=`4 0 obj
|
|
464
|
-
<< /Length ${ft.length} >>
|
|
465
|
-
stream
|
|
466
|
-
${ft}
|
|
467
|
-
endstream
|
|
468
|
-
endobj
|
|
469
|
-
`;o.push(ht),a+=ht.length,s.push(a);let R=`5 0 obj
|
|
470
|
-
<< /Type /XObject /Subtype /Image /Width ${i.width} /Height ${i.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${i.data.length} >>
|
|
471
|
-
stream
|
|
472
|
-
`,yt=`
|
|
473
|
-
endstream
|
|
474
|
-
endobj
|
|
475
|
-
`;o.push(R),a+=R.length+i.data.length+yt.length,s.push(a);let bt=`6 0 obj
|
|
476
|
-
<< ${Qe(r)} >>
|
|
477
|
-
endobj
|
|
478
|
-
`;o.push(bt),a+=bt.length;let te=a,Pt=`xref
|
|
479
|
-
0 7
|
|
480
|
-
0000000000 65535 f
|
|
481
|
-
`;for(let g of s)Pt+=`${g.toString().padStart(10,"0")} 00000 n
|
|
482
|
-
`;let ee=`trailer
|
|
483
|
-
<< /Size 7 /Root 1 0 R /Info 6 0 R >>
|
|
484
|
-
startxref
|
|
485
|
-
${te}
|
|
486
|
-
%%EOF`,_=c+o.slice(0,4).join("")+R,z=yt+o.slice(5).join("")+Pt+ee,ne=_.length+i.data.length+z.length,M=new Uint8Array(ne),D=0;for(let g=0;g<_.length;g++)M[D++]=_.charCodeAt(g);M.set(i.data,D),D+=i.data.length;for(let g=0;g<z.length;g++)M[D++]=z.charCodeAt(g);return M}async function Xe(e,t={}){let n=t.scale??2,r=y(t.pageSize??"A4",t.orientation??"portrait"),i=w(t.margin),o=j();o.style.width=`${r.width}px`,o.style.minHeight=`${r.height}px`,o.style.padding=`${i.top}px ${i.right}px ${i.bottom}px ${i.left}px`,o.style.background="white",o.style.boxSizing="border-box";let s=v(e);o.appendChild(s),J(o);let a=Ut(r.width*n,r.height*n),c=jt(a);return c.scale(n,n),c.fillStyle="white",c.fillRect(0,0,r.width,r.height),q(o),a}var dt=class{async toBlob(t,n){if(!B())throw l("PDF_EXPORT_FAILED","PDF export is not supported");let i=x(t)[0];if(!i)throw l("ELEMENT_NOT_FOUND","No element found");let o=y(n?.pageSize??"A4",n?.orientation??"portrait"),s=await Xe(i,n),a=Jt(s,n?.quality??.92),c=Ge(a,o.width*.75,o.height*.75,n?.metadata);return new Blob([c.buffer],{type:"application/pdf"})}async toBase64(t,n){let r=await this.toBlob(t,n);return new Promise((i,o)=>{let s=new FileReader;s.onloadend=()=>{let a=s.result;i(a.split(",")[1]??"");},s.onerror=()=>o(l("PDF_EXPORT_FAILED","Failed to convert to base64")),s.readAsDataURL(r);})}async toDataURL(t,n){let r=await this.toBlob(t,n);return new Promise((i,o)=>{let s=new FileReader;s.onloadend=()=>i(s.result),s.onerror=()=>o(l("PDF_EXPORT_FAILED","Failed to convert to data URL")),s.readAsDataURL(r);})}async download(t,n,r){let i=await this.toBlob(t,r),o=URL.createObjectURL(i),s=document.createElement("a");s.href=o,s.download=n.endsWith(".pdf")?n:`${n}.pdf`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o);}async downloadHTML(t,n,r){let i=j();i.innerHTML=t,J(i);try{await this.download(i,n,r);}finally{q(i);}}};function Ye(){return new dt}function Ve(){return `job-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}var pt=class{constructor(){this.listeners=new Map;}on(t,n){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t)?.add(n),()=>this.off(t,n)}off(t,n){this.listeners.get(t)?.delete(n);}emit(t,...n){this.listeners.get(t)?.forEach(r=>{try{r(...n);}catch(i){console.error(`Error in event handler for ${t}:`,i);}});}clear(){this.listeners.clear();}},ut=class{constructor(t){this.jobs=new Map;this.emitter=new pt;this.isPaused=false;this.isProcessing=false;this.defaultOptions=t??{},this.printer=$(this.defaultOptions);}add(t){let n=Ve(),r={...t,id:n,status:"pending",createdAt:new Date};return this.jobs.set(n,r),n}remove(t){return this.jobs.delete(t)}clear(){this.jobs.clear();}getJob(t){return this.jobs.get(t)}getJobs(){return Array.from(this.jobs.values())}getPendingJobs(){let t={high:0,normal:1,low:2};return Array.from(this.jobs.values()).filter(n=>n.status==="pending").sort((n,r)=>{let i=t[n.priority??"normal"],o=t[r.priority??"normal"];return i!==o?i-o:n.createdAt.getTime()-r.createdAt.getTime()})}async printNext(){if(this.isPaused||this.isProcessing)return;let n=this.getPendingJobs()[0];n&&await this.processJob(n);}async printAll(){if(!this.isPaused){for(;!this.isPaused;){let n=this.getPendingJobs()[0];if(!n)break;await this.processJob(n);}this.isPaused||this.emitter.emit("queueComplete");}}pause(){this.isPaused=true,this.emitter.emit("queuePause");}resume(){this.isPaused=false,this.emitter.emit("queueResume");}on(t,n){return this.emitter.on(t,n)}off(t,n){this.emitter.off(t,n);}destroy(){this.clear(),this.emitter.clear(),this.printer.destroy();}async processJob(t){if(!this.isPaused){this.isProcessing=true,t.status="printing",this.emitter.emit("jobStart",t);try{await this.printer.print(t.content,t.options),t.status="completed",t.completedAt=new Date,this.emitter.emit("jobComplete",t);}catch(n){t.status="failed",t.error=n instanceof Error?n:new Error(String(n)),t.completedAt=new Date,this.emitter.emit("jobError",t,t.error);}finally{this.isProcessing=false;}}}};function tn(e){return new ut(e)}export{G as AVOID_BREAK_CLASS,Z as BREAK_AFTER_CLASS,k as BREAK_BEFORE_CLASS,Q as PAGE_SIZES,Ft as PRINT_HIDE_CLASS,tt as PRINT_ONLY_CLASS,P as PrintError,pe as avoidBreak,me as breakAfter,ue as breakBefore,Y as buildStyleTag,ge as calculatePages,v as cloneElement,V as combineStyles,Nt as copyPageStyles,Ye as createPDFExporter,X as createPageInfo,l as createPrintError,Ke as createPrintPreview,tn as createPrintQueue,$ as createPrinter,et as getAllDefaultStyles,Rt as getBaseDocumentStyles,we as getComputedStylesCSS,Ht as getDefaultPrintStyles,je as getDefaultPrinter,w as getMarginsInPixels,T as getPageDimensions,y as getPagePixelDimensions,he as injectPrintStyles,re as isBrowser,B as isPDFSupported,xt as isPrintError,m as isPrintSupported,O as normalizeMargins,de as pageBreak,be as removeAllPrintStyles,ye as removePrintStyles,C as renderHeaderFooter,Dt as replacePlaceholders,U as resolveElement,vt as resolveElements,W as sanitizeHTML,K as waitForImages,oe as wrapError};//# sourceMappingURL=index.js.map
|
|
1
|
+
import {P}from'./chunk-N44HS34F.js';export{t as AVOID_BREAK_CLASS,s as BREAK_AFTER_CLASS,r as BREAK_BEFORE_CLASS,m as PAGE_SIZES,J as PRINT_HIDE_CLASS,K as PRINT_ONLY_CLASS,d as PrintError,v as avoidBreak,x as breakAfter,w as breakBefore,F as buildStyleTag,y as calculatePages,k as cloneElement,G as combineStyles,H as copyPageStyles,R as createPDFExporter,z as createPageInfo,e as createPrintError,S as createPrintPreview,P as createPrinter,N as getAllDefaultStyles,M as getBaseDocumentStyles,I as getComputedStylesCSS,L as getDefaultPrintStyles,Q as getDefaultPrinter,q as getMarginsInPixels,n as getPageDimensions,o as getPagePixelDimensions,C as injectPrintStyles,c as isBrowser,b as isPDFSupported,f as isPrintError,a as isPrintSupported,p as normalizeMargins,u as pageBreak,E as removeAllPrintStyles,D as removePrintStyles,B as renderHeaderFooter,A as replacePlaceholders,i as resolveElement,j as resolveElements,h as sanitizeHTML,l as waitForImages,g as wrapError}from'./chunk-N44HS34F.js';function W(){return `job-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}var a=class{constructor(){this.listeners=new Map;}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e)?.add(t),()=>this.off(e,t)}off(e,t){this.listeners.get(e)?.delete(t);}emit(e,...t){this.listeners.get(e)?.forEach(r=>{try{r(...t);}catch(i){console.error(`Error in event handler for ${e}:`,i);}});}clear(){this.listeners.clear();}},u=class{constructor(e){this.jobs=new Map;this.emitter=new a;this.isPaused=false;this.isProcessing=false;this.running=null;this.defaultOptions=e??{},this.printer=P(this.defaultOptions);}add(e){let t=W(),r={...e,id:t,status:"pending",createdAt:new Date};return this.jobs.set(t,r),t}remove(e){return this.jobs.delete(e)}retry(e){let t=this.jobs.get(e);return !t||t.status!=="failed"?false:(t.status="pending",delete t.error,delete t.completedAt,true)}clear(){this.jobs.clear();}getJob(e){return this.jobs.get(e)}getJobs(){return Array.from(this.jobs.values())}getPendingJobs(){let e={high:0,normal:1,low:2};return Array.from(this.jobs.values()).filter(t=>t.status==="pending").sort((t,r)=>{let i=e[t.priority??"normal"],n=e[r.priority??"normal"];return i!==n?i-n:t.createdAt.getTime()-r.createdAt.getTime()})}async printNext(){if(this.isPaused||this.isProcessing)return;let t=this.getPendingJobs()[0];t&&await this.processJob(t);}printAll(){return this.isPaused?Promise.resolve():(this.running||(this.running=this.runAll().finally(()=>{this.running=null;})),this.running)}async runAll(){for(;!this.isPaused;){let t=this.getPendingJobs()[0];if(!t)break;await this.processJob(t);}this.isPaused||this.emitter.emit("queueComplete");}pause(){this.isPaused=true,this.emitter.emit("queuePause");}resume(){this.isPaused=false,this.emitter.emit("queueResume");}on(e,t){return this.emitter.on(e,t)}off(e,t){this.emitter.off(e,t);}destroy(){this.clear(),this.emitter.clear(),this.printer.destroy();}async processJob(e){if(!this.isPaused){this.isProcessing=true,e.status="printing",this.emitter.emit("jobStart",e);try{let t=1+Math.max(0,Math.floor(e.retries??0)),r;for(let i=0;i<t;i++){e.attempts=(e.attempts??0)+1;try{await this.printer.print(e.content,e.options),e.status="completed",e.completedAt=new Date,this.emitter.emit("jobComplete",e);return}catch(n){if(r=n,!this.jobs.has(e.id))break}}e.status="failed",e.error=r instanceof Error?r:new Error(String(r)),e.completedAt=new Date,this.emitter.emit("jobError",e,e.error);}finally{this.isProcessing=false;}}}};function X(s){return new u(s)}export{X as createPrintQueue};//# sourceMappingURL=index.js.map
|
|
487
2
|
//# sourceMappingURL=index.js.map
|