@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/react.cjs
CHANGED
|
@@ -1,487 +1,2 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var
|
|
2
|
-
`)}function it(){let e=document.createElement("div");return e.style.cssText="position:absolute;left:-9999px;top:-9999px;visibility:hidden;",e}function st(e){document.body.appendChild(e);}function at(e){document.body.contains(e)&&document.body.removeChild(e);}function vt(e){let t=e.querySelectorAll("img"),r=[];return t.forEach(n=>{n.complete||r.push(new Promise(o=>{n.onload=()=>o(),n.onerror=()=>o();}));}),Promise.all(r).then(()=>{})}function Et(e){return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/on\w+="[^"]*"/gi,"").replace(/on\w+='[^']*'/gi,"").replace(/javascript:/gi,"")}function xe(){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 we(e,t=3e4){return new Promise((r,n)=>{let o=setTimeout(()=>{n(c("IFRAME_LOAD_FAILED","Load timeout"));},t);e.onload=()=>{clearTimeout(o),requestAnimationFrame(()=>{requestAnimationFrame(()=>{r();});});},e.onerror=()=>{clearTimeout(o),n(c("IFRAME_LOAD_FAILED","Load error"));};})}function ve(e,t){let r=e.contentDocument??e.contentWindow?.document;if(!r)throw c("IFRAME_LOAD_FAILED","Cannot access iframe document");r.open(),r.write(t),r.close();}function Tt(e){e&&(e.onload=null,e.onerror=null,e.parentNode&&e.parentNode.removeChild(e));}function Ot(e){return new Promise((t,r)=>{try{let n=e.contentWindow;if(!n){r(c("IFRAME_LOAD_FAILED","Cannot access iframe window"));return}n.focus();let o=()=>{n.removeEventListener("afterprint",o),t();};n.addEventListener("afterprint",o),n.print(),setTimeout(()=>{n.removeEventListener("afterprint",o),t();},1e3);}catch(n){r(c("IFRAME_LOAD_FAILED",n instanceof Error?n.message:"Print failed"));}})}async function Lt(e){let t=xe();return document.body.appendChild(t),ve(t,e),await we(t),t}var St={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 R(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 Ee(e){return typeof e=="string"&&e in St}function Z(e,t="portrait"){let r;return Ee(e)?r={...St[e]}:r={width:R(e.width),height:R(e.height)},t==="landscape"?{width:r.height,height:r.width}:r}function Dt(e,t="portrait"){let r=Z(e,t);return `
|
|
13
|
-
@page {
|
|
14
|
-
size: ${r.width} ${r.height};
|
|
15
|
-
}
|
|
16
|
-
`}function k(e,t="portrait",r=96){let n=Z(e,t),o=i=>{let s=parseFloat(i);return i.endsWith("mm")?s/25.4*r:i.endsWith("cm")?s/2.54*r:i.endsWith("in")?s*r:i.endsWith("pt")?s/72*r:s};return {width:Math.round(o(n.width)),height:Math.round(o(n.height))}}var B=10;function W(e){if(e===void 0){let t=R(B);return {top:t,right:t,bottom:t,left:t}}if(typeof e=="number"){let t=R(e);return {top:t,right:t,bottom:t,left:t}}return {top:R(e.top??B),right:R(e.right??B),bottom:R(e.bottom??B),left:R(e.left??B)}}function Rt(e){let t=W(e);return `
|
|
17
|
-
@page {
|
|
18
|
-
margin: ${t.top} ${t.right} ${t.bottom} ${t.left};
|
|
19
|
-
}
|
|
20
|
-
`}function z(e,t=96){let r=W(e),n=o=>{let i=parseFloat(o);return o.endsWith("mm")?i/25.4*t:o.endsWith("cm")?i/2.54*t:o.endsWith("in")?i*t:o.endsWith("pt")?i/72*t:i};return {top:Math.round(n(r.top)),right:Math.round(n(r.right)),bottom:Math.round(n(r.bottom)),left:Math.round(n(r.left))}}var V="print-break-before",Mt="print-break-after",Ct="print-avoid-break";function kt(){return `
|
|
21
|
-
@media print {
|
|
22
|
-
.${V} {
|
|
23
|
-
page-break-before: always !important;
|
|
24
|
-
break-before: page !important;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.${Mt} {
|
|
28
|
-
page-break-after: always !important;
|
|
29
|
-
break-after: page !important;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.${Ct} {
|
|
33
|
-
page-break-inside: avoid !important;
|
|
34
|
-
break-inside: avoid !important;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`}function At(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 Nt(e,t,r,n=new Date){return {pageNumber:e,totalPages:t,title:r,date:n}}function Te(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 lt(e,t){return e?typeof e=="function"?e(t):Te(e,t):""}function Ft(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 It(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 Ht(){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 $t(e){return `<style>${Array.isArray(e)?e.join(`
|
|
101
|
-
`):e}</style>`}function Oe(e){return `<link rel="stylesheet" href="${e}">`}function _t(e){return e.map(Oe).join(`
|
|
102
|
-
`)}function Bt(e){let t=[];for(let r of e)r&&(Array.isArray(r)?t.push(...r):t.push(r));return t.join(`
|
|
103
|
-
`)}function Le(){let e=[];return document.querySelectorAll('link[rel="stylesheet"]').forEach(r=>{let n=r.href;n&&e.push(`<link rel="stylesheet" href="${n}">`);}),e}function Se(){let e=[];return document.querySelectorAll("style").forEach(r=>{if(r.hasAttribute("data-printkit"))return;let n=r.textContent;n&&e.push(`<style>${n}</style>`);}),e}function De(){return [...Le(),...Se()]}function zt(){return De().join(`
|
|
104
|
-
`)}var G="print-hide",U="print-only";function Re(){return `
|
|
105
|
-
/* Print visibility classes */
|
|
106
|
-
@media print {
|
|
107
|
-
.${G},
|
|
108
|
-
.no-print {
|
|
109
|
-
display: none !important;
|
|
110
|
-
visibility: hidden !important;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.${U},
|
|
114
|
-
.print-only {
|
|
115
|
-
display: block !important;
|
|
116
|
-
visibility: visible !important;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@media screen {
|
|
121
|
-
.${U},
|
|
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 Me(){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 Ce(){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 Ut(){return [Me(),Re(),Ce()].join(`
|
|
238
|
-
`)}var jt={pageSize:"A4",orientation:"portrait"};function E(e,t={}){let r=t.pageSize??jt.pageSize,n=t.orientation??jt.orientation,o=Z(r,n),i=W(t.margin),s=Nt(1,1,t.title??"Print Document"),a=lt(t.header,s),l=lt(t.footer,s),u=Bt([Ut(),Dt(r,n),Rt(t.margin),kt(),At({pageBreakBefore:t.pageBreakBefore,pageBreakAfter:t.pageBreakAfter,avoidBreakInside:t.avoidBreakInside}),Ht(),t.printBackground?"":"body { background: white !important; }",Array.isArray(t.styles)?t.styles.join(`
|
|
239
|
-
`):t.styles]);return {content:e,styles:u,header:a,footer:l,pageSize:o,margins:i,title:t.title??"Print Document"}}function T(e,t={}){let r=t.copyStyles!==false?zt():"",n=t.styleSheets?_t(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
|
-
${r}
|
|
247
|
-
${n}
|
|
248
|
-
${$t(e.styles)}
|
|
249
|
-
</head>
|
|
250
|
-
<body>
|
|
251
|
-
${e.header?Ft(e.header):""}
|
|
252
|
-
<main class="print-content">
|
|
253
|
-
${e.content}
|
|
254
|
-
</main>
|
|
255
|
-
${e.footer?It(e.footer):""}
|
|
256
|
-
</body>
|
|
257
|
-
</html>
|
|
258
|
-
`}async function O(e,t={}){t.onBeforePrint&&await t.onBeforePrint();let r=null;try{r=await Lt(e),await Ot(r),t.onAfterPrint&&t.onAfterPrint();}catch(n){throw t.onError&&t.onError(n),n}finally{t.removeAfterPrint!==false&&Tt(r);}}async function Kt(e,t={}){let r=C(e);for(let s of r)await vt(s);let n=X(r),o=E(n,t),i=T(o,t);await O(i,t);}function ke(e){if(!e||typeof e!="string")throw c("ELEMENT_NOT_FOUND","HTML content is empty or invalid");if(e.trim().length===0)throw c("ELEMENT_NOT_FOUND","HTML content is empty")}function Ae(e){let t=e.toLowerCase().trim();return t.includes("<!doctype")||t.includes("<html")}function Ne(e){let t=e.match(/<body[^>]*>([\s\S]*?)<\/body>/i);return t?.[1]?t[1]:e}function Fe(e){let t=[],r=e.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gi);for(let o of r)o[1]&&t.push(o[1]);let n=e.matchAll(/<link[^>]*rel=["']stylesheet["'][^>]*>/gi);for(let o of n)t.push(o[0]);return t}async function Y(e,t={}){ke(e);let r=Et(e),n,o=[];Ae(r)?(n=Ne(r),o=Fe(r)):n=r;let i=Array.isArray(t.styles)?[...t.styles,...o]:t.styles?[t.styles,...o]:o,s=E(n,{...t,styles:i.length>0?i:void 0}),a=T(s,t);await O(a,t);}function Ie(e){if(!e||typeof e!="string")throw c("ELEMENT_NOT_FOUND","URL is empty or invalid");try{new URL(e,window.location.origin);}catch{throw c("ELEMENT_NOT_FOUND",`Invalid URL: ${e}`)}}async function He(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 c("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:c("IFRAME_LOAD_FAILED",`Failed to fetch URL: ${t instanceof Error?t.message:"Unknown error"}`)}}async function qt(e,t={}){Ie(e);let r=new URL(e,window.location.origin).href;try{let n=await He(r);await Y(n,{...t,title:t.title??r});}catch(n){throw t.onError&&t.onError(n),n}}function Jt(e,t){let r=document.createElement("canvas");return r.width=e,r.height=t,r}function Xt(e){let t=e.getContext("2d");if(!t)throw c("PDF_EXPORT_FAILED","Cannot get canvas 2D context");return t}function Zt(e,t=.92){return e.toDataURL("image/jpeg",t)}function ct(e){return new Promise((t,r)=>{let n=new Image;n.crossOrigin="anonymous",n.onload=()=>t(n),n.onerror=()=>r(c("ELEMENT_NOT_FOUND",`Failed to load image: ${e}`)),n.src=e;})}function pt(e){return typeof e=="string"?e:e.src}function Wt(e){let t=pt(e);if(!t||t.trim().length===0)throw c("ELEMENT_NOT_FOUND","Image source is empty")}function Vt(e,t="",r={}){let n=r.fit==="cover"?"object-fit: cover;":r.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
|
-
${n}
|
|
274
|
-
"
|
|
275
|
-
/>
|
|
276
|
-
</div>
|
|
277
|
-
`}function $e(e,t={}){return e.map((r,n)=>`
|
|
278
|
-
<div class="print-image-page" style="
|
|
279
|
-
page-break-after: ${n<e.length-1?"always":"auto"};
|
|
280
|
-
min-height: 100vh;
|
|
281
|
-
display: flex;
|
|
282
|
-
justify-content: center;
|
|
283
|
-
align-items: center;
|
|
284
|
-
">
|
|
285
|
-
${Vt(r,`Image ${n+1}`,t)}
|
|
286
|
-
</div>
|
|
287
|
-
`).join("")}function Gt(){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 Yt(e,t={}){Wt(e);let r=pt(e);await ct(r);let n=Vt(r,t.title??"Image"),o=E(n,{...t,styles:[Gt(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),i=T(o,t);await O(i,t);}async function Qt(e,t={}){if(!e||e.length===0)throw c("ELEMENT_NOT_FOUND","No images provided");for(let s of e)Wt(s);let r=e.map(pt);await Promise.all(r.map(ct));let n=$e(r),o=E(n,{...t,styles:[Gt(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),i=T(o,t);await O(i,t);}var j={string:"#22863a",number:"#005cc5",boolean:"#d73a49",null:"#6f42c1",key:"#032f62"};function dt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function _e(e){return e.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,t=>{let r=j.number;if(/^"/.test(t)){if(/:$/.test(t))return r=j.key,t=t.replace(/:$/,""),`<span style="color:${r}">${dt(t)}</span>:`;r=j.string;}else /true|false/.test(t)?r=j.boolean:/null/.test(t)&&(r=j.null);return `<span style="color:${r}">${dt(t)}</span>`})}function Be(e,t=2){try{return JSON.stringify(e,null,t)}catch{throw c("UNKNOWN","Failed to stringify JSON data")}}function ze(e,t={}){let{indent:r=2,syntaxHighlight:n=false}=t,o=Be(e,r);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>${n?_e(o):dt(o)}</code></pre>
|
|
318
|
-
`}function Ue(){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 te(e,t={}){if(e===void 0)throw c("ELEMENT_NOT_FOUND","JSON data is undefined");let r=ze(e,t),n=E(r,{...t,styles:[Ue(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),o=T(n,t);await O(o,t);}function ut(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function je(e){if(!e)throw c("ELEMENT_NOT_FOUND","Table data is empty");if(!Array.isArray(e.headers)||e.headers.length===0)throw c("ELEMENT_NOT_FOUND","Table headers are required");if(!Array.isArray(e.rows))throw c("ELEMENT_NOT_FOUND","Table rows must be an array")}function Ke(e,t={}){let r=t.headerStyles??"",n=t.cellStyles??"",o=e.map(i=>`<th style="${n}">${ut(i)}</th>`).join("");return `
|
|
336
|
-
<thead style="${r}">
|
|
337
|
-
<tr>${o}</tr>
|
|
338
|
-
</thead>
|
|
339
|
-
`}function qe(e,t,r={}){let n=r.cellStyles??"",i=r.stripedRows&&t%2===1?"background-color: #f9f9f9;":"",s=e.map(a=>`<td style="${n}">${ut(a)}</td>`).join("");return `<tr style="${i}">${s}</tr>`}function Je(e,t={}){return `<tbody>${e.map((n,o)=>qe(n,o,t)).join("")}</tbody>`}function Xe(e,t={}){let r=t.tableStyles??"",o=t.bordered!==false?"border: 1px solid #ddd; border-collapse: collapse;":"border-collapse: collapse;",i=e.caption?`<caption style="padding: 10px; font-weight: bold; text-align: left;">${ut(e.caption)}</caption>`:"";return `
|
|
340
|
-
<table class="print-table" style="
|
|
341
|
-
width: 100%;
|
|
342
|
-
${o}
|
|
343
|
-
${r}
|
|
344
|
-
">
|
|
345
|
-
${i}
|
|
346
|
-
${Ke(e.headers,t)}
|
|
347
|
-
${Je(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 ee(e,t={}){je(e);let r=Xe(e,t),n=E(r,{...t,styles:[Ze(t),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),o=T(n,t);await O(o,t);}var Q={title:"Print Document",pageSize:"A4",orientation:"portrait",copyStyles:true,removeAfterPrint:true,printBackground:true};function M(e,t){return t?{...e,...t,margin:t.margin!==void 0?t.margin:e.margin,styles:We(e.styles,t.styles),styleSheets:Ve(e.styleSheets,t.styleSheets)}:{...e}}function We(e,t){if(!t)return e;if(!e)return t;let r=Array.isArray(e)?e:[e],n=Array.isArray(t)?t:[t];return [...r,...n]}function Ve(e,t){return t?e?[...e,...t]:t:e}function mt(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 ft=class{constructor(t){D()||console.warn("Printing is not supported in this environment"),this.defaultOptions={...Q,...t},t&&mt(t);}async print(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await Kt(t,n);}async printHTML(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await Y(t,n);}async printURL(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await qt(t,n);}async printImage(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await Yt(t,n);}async printImages(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await Qt(t,n);}async printJSON(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await te(t,n);}async printTable(t,r){if(!D())throw c("PRINT_NOT_SUPPORTED");let n=M(this.defaultOptions,r);await ee(t,n);}setDefaultOptions(t){mt(t),this.defaultOptions=M(this.defaultOptions,t);}getDefaultOptions(){return {...this.defaultOptions}}destroy(){}};function re(e){return new ft(e)}function K(e){let t=F(),[r,n]=react.useState(false),[o,i]=react.useState(null),s=react.useRef(null),a={...t?.defaultOptions,...e};react.useEffect(()=>(s.current=re(a),()=>{s.current?.destroy(),s.current=null;}),[]),react.useEffect(()=>{s.current&&s.current.setDefaultOptions(a);},[a]);let l=react.useCallback(async(P,b)=>{if(!s.current){i(new f("PRINT_NOT_SUPPORTED","Printer not initialized"));return}n(true),i(null);try{await s.current.print(P,b);}catch(g){let m=g instanceof f?g:new f("UNKNOWN",g instanceof Error?g.message:"Unknown error");throw i(m),m}finally{n(false);}},[]),u=react.useCallback(async(P,b)=>{if(!s.current){i(new f("PRINT_NOT_SUPPORTED","Printer not initialized"));return}n(true),i(null);try{await s.current.printHTML(P,b);}catch(g){let m=g instanceof f?g:new f("UNKNOWN",g instanceof Error?g.message:"Unknown error");throw i(m),m}finally{n(false);}},[]),w=react.useCallback(async(P,b)=>{if(!s.current){i(new f("PRINT_NOT_SUPPORTED","Printer not initialized"));return}n(true),i(null);try{await s.current.printURL(P,b);}catch(g){let m=g instanceof f?g:new f("UNKNOWN",g instanceof Error?g.message:"Unknown error");throw i(m),m}finally{n(false);}},[]),p=react.useCallback(()=>{i(null);},[]);return {print:l,printHTML:u,printURL:w,isPrinting:r,error:o,clearError:p}}var Ye={width:"90%",height:"85%",showToolbar:true,showPageNumbers:true,zoom:100,className:""},Qe={print:true,download:true,zoom:true,navigation:true,close:true},q=[25,50,75,100,125,150,175,200],ie=25,se=200,et=25,gt=class{constructor(t,r){this.modal=null;this.contentContainer=null;this.currentPage=1;this.totalPages=1;this.zoomLevel=100;this.isModalOpen=false;this.target=t,this.options={...Q,...r},this.modalOptions={...Ye,...r?.modal},this.toolbarOptions={...Qe,...r?.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=C(this.target),r=X(t),n=E(r,this.options),o=T(n,this.options);await O(o,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(ie,Math.min(se,t)),this.updateZoom();}getZoom(){return this.zoomLevel}zoomIn(){let t=q.indexOf(this.zoomLevel);t<q.length-1?this.zoomLevel=q[t+1]??this.zoomLevel+et:this.zoomLevel=Math.min(se,this.zoomLevel+et),this.updateZoom();}zoomOut(){let t=q.indexOf(this.zoomLevel);t>0?this.zoomLevel=q[t-1]??this.zoomLevel-et:this.zoomLevel=Math.max(ie,this.zoomLevel-et),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 r=document.createElement("div");r.style.cssText="display: flex; align-items: center; gap: 8px;";let n=document.createElement("div");n.style.cssText="display: flex; align-items: center; gap: 8px;";let o=document.createElement("div");if(o.style.cssText="display: flex; align-items: center; gap: 8px;",this.toolbarOptions.navigation){let i=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}`,r.appendChild(i),r.appendChild(a),r.appendChild(s);}if(this.toolbarOptions.zoom){let i=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()),l=this.createButton("Reset",()=>this.resetZoom());n.appendChild(i),n.appendChild(s),n.appendChild(a),n.appendChild(l);}if(this.toolbarOptions.print){let i=this.createButton("Print",()=>this.print(),true);o.appendChild(i);}if(this.toolbarOptions.download){let i=this.createButton("Download",()=>this.download());o.appendChild(i);}if(this.toolbarOptions.close){let i=this.createButton("Close",()=>this.close());i.style.marginLeft="8px",o.appendChild(i);}return t.appendChild(r),t.appendChild(n),t.appendChild(o),t}createButton(t,r,n=false){let o=document.createElement("button");return o.textContent=t,o.onclick=r,o.style.cssText=`
|
|
434
|
-
padding: 6px 12px;
|
|
435
|
-
border: 1px solid ${n?"#0066cc":"#ccc"};
|
|
436
|
-
border-radius: 4px;
|
|
437
|
-
background: ${n?"#0066cc":"#fff"};
|
|
438
|
-
color: ${n?"#fff":"#333"};
|
|
439
|
-
font-size: 14px;
|
|
440
|
-
cursor: pointer;
|
|
441
|
-
transition: all 0.2s;
|
|
442
|
-
`,o.onmouseover=()=>{o.style.opacity="0.8";},o.onmouseout=()=>{o.style.opacity="1";},o}renderContent(){if(this.contentContainer)try{let t=C(this.target),r=k(this.options.pageSize??"A4",this.options.orientation??"portrait"),n=z(this.options.margin),o=document.createElement("div");o.className="printkit-page",o.style.cssText=`
|
|
443
|
-
width: ${r.width}px;
|
|
444
|
-
min-height: ${r.height}px;
|
|
445
|
-
background: white;
|
|
446
|
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
447
|
-
padding: ${n.top}px ${n.right}px ${n.bottom}px ${n.left}px;
|
|
448
|
-
box-sizing: border-box;
|
|
449
|
-
transform-origin: top center;
|
|
450
|
-
transform: scale(${this.zoomLevel/100});
|
|
451
|
-
`;for(let i of t){let s=_(i);o.appendChild(s);}this.contentContainer.appendChild(o);}catch(t){let r=document.createElement("div");r.style.cssText="color: red; padding: 20px;",r.textContent=t instanceof Error?t.message:"Failed to load content",this.contentContainer.appendChild(r);}}calculatePages(){if(!this.contentContainer)return;let t=k(this.options.pageSize??"A4",this.options.orientation??"portrait"),r=z(this.options.margin),n=t.height-r.top-r.bottom,o=this.contentContainer.querySelectorAll(".printkit-page"),i=0;o.forEach(s=>{i+=s.scrollHeight;}),this.totalPages=Math.max(1,Math.ceil(i/n)),this.updatePageInfo();}updateZoom(){if(!this.contentContainer)return;this.contentContainer.querySelectorAll(".printkit-page").forEach(n=>{n.style.transform=`scale(${this.zoomLevel/100})`;});let r=this.modal?.querySelector(".printkit-zoom-level");r&&(r.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 r=k(this.options.pageSize??"A4",this.options.orientation??"portrait"),n=(t-1)*(r.height+20)*(this.zoomLevel/100);this.contentContainer.scrollTop=n,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 ae(e,t){return new gt(e,t)}function ht(e,t){let r=F(),[n,o]=react.useState(false),[i,s]=react.useState(1),[a,l]=react.useState(1),[u,w]=react.useState(100),p=react.useRef(null),P={...r?.defaultOptions,...t},b=react.useCallback(()=>{if(!e.current)return null;p.current&&p.current.destroy();let y=ae(e.current,{...P,onClose:()=>{o(false),P.onClose?.();}});return p.current=y,y},[e,P]);react.useEffect(()=>()=>{p.current?.destroy(),p.current=null;},[]);let g=react.useCallback(()=>{let y=b();y&&(y.open(),o(true),s(y.getCurrentPage()),l(y.getTotalPages()),w(y.getZoom()));},[b]),m=react.useCallback(()=>{p.current?.close(),o(false);},[]),x=react.useCallback(async()=>{await p.current?.print();},[]),v=react.useCallback(async y=>{await p.current?.download(y);},[]),d=react.useCallback(y=>{p.current?.setZoom(y),w(y);},[]),h=react.useCallback(()=>{p.current?.zoomIn(),p.current&&w(p.current.getZoom());},[]),A=react.useCallback(()=>{p.current?.zoomOut(),p.current&&w(p.current.getZoom());},[]),I=react.useCallback(()=>{p.current?.resetZoom(),w(100);},[]),H=react.useCallback(()=>{p.current?.nextPage(),p.current&&s(p.current.getCurrentPage());},[]),ot=react.useCallback(()=>{p.current?.prevPage(),p.current&&s(p.current.getCurrentPage());},[]),N=react.useCallback(y=>{p.current?.goToPage(y),p.current&&s(p.current.getCurrentPage());},[]);return {open:g,close:m,isOpen:n,print:x,download:v,currentPage:i,totalPages:a,zoom:u,setZoom:d,zoomIn:h,zoomOut:A,resetZoom:I,nextPage:H,prevPage:ot,goToPage:N}}function nt(e){return e.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")}function rr(e){let t=l=>l.toString().padStart(2,"0"),r=e.getFullYear(),n=t(e.getMonth()+1),o=t(e.getDate()),i=t(e.getHours()),s=t(e.getMinutes()),a=t(e.getSeconds());return `D:${r}${n}${o}${i}${s}${a}`}function nr(e){let t=[];return e?.title&&t.push(`/Title (${nt(e.title)})`),e?.author&&t.push(`/Author (${nt(e.author)})`),e?.subject&&t.push(`/Subject (${nt(e.subject)})`),e?.keywords&&t.push(`/Keywords (${nt(e.keywords.join(", "))})`),t.push("/Creator (PrintKit)"),t.push("/Producer (PrintKit)"),t.push(`/CreationDate (${rr(e?.creationDate??new Date)})`),t.join(`
|
|
452
|
-
`)}function or(e){let t=e.replace(/^data:image\/jpeg;base64,/,""),r=atob(t),n=new Uint8Array(r.length);for(let a=0;a<r.length;a++)n[a]=r.charCodeAt(a);let o=0,i=0,s=2;for(;s<n.length&&n[s]===255;){let a=n[s+1];if(a===void 0)break;if(a===192||a===194){i=(n[s+5]??0)<<8|(n[s+6]??0),o=(n[s+7]??0)<<8|(n[s+8]??0);break}let l=(n[s+2]??0)<<8|(n[s+3]??0);s+=2+l;}return {data:n,width:o,height:i}}function ir(e,t,r,n){let o=or(e),i=[],s=[],a=0,l=`%PDF-1.4
|
|
453
|
-
%\xFF\xFF\xFF\xFF
|
|
454
|
-
`;a=l.length,s.push(a);let u=`1 0 obj
|
|
455
|
-
<< /Type /Catalog /Pages 2 0 R >>
|
|
456
|
-
endobj
|
|
457
|
-
`;i.push(u),a+=u.length,s.push(a);let w=`2 0 obj
|
|
458
|
-
<< /Type /Pages /Kids [3 0 R] /Count 1 >>
|
|
459
|
-
endobj
|
|
460
|
-
`;i.push(w),a+=w.length,s.push(a);let p=`3 0 obj
|
|
461
|
-
<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${t} ${r}] /Contents 4 0 R /Resources << /XObject << /Im0 5 0 R >> >> >>
|
|
462
|
-
endobj
|
|
463
|
-
`;i.push(p),a+=p.length;let P=`q ${t} 0 0 ${r} 0 0 cm /Im0 Do Q`;s.push(a);let b=`4 0 obj
|
|
464
|
-
<< /Length ${P.length} >>
|
|
465
|
-
stream
|
|
466
|
-
${P}
|
|
467
|
-
endstream
|
|
468
|
-
endobj
|
|
469
|
-
`;i.push(b),a+=b.length,s.push(a);let g=`5 0 obj
|
|
470
|
-
<< /Type /XObject /Subtype /Image /Width ${o.width} /Height ${o.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${o.data.length} >>
|
|
471
|
-
stream
|
|
472
|
-
`,m=`
|
|
473
|
-
endstream
|
|
474
|
-
endobj
|
|
475
|
-
`;i.push(g),a+=g.length+o.data.length+m.length,s.push(a);let v=`6 0 obj
|
|
476
|
-
<< ${nr(n)} >>
|
|
477
|
-
endobj
|
|
478
|
-
`;i.push(v),a+=v.length;let d=a,h=`xref
|
|
479
|
-
0 7
|
|
480
|
-
0000000000 65535 f
|
|
481
|
-
`;for(let S of s)h+=`${S.toString().padStart(10,"0")} 00000 n
|
|
482
|
-
`;let A=`trailer
|
|
483
|
-
<< /Size 7 /Root 1 0 R /Info 6 0 R >>
|
|
484
|
-
startxref
|
|
485
|
-
${d}
|
|
486
|
-
%%EOF`,I=l+i.slice(0,4).join("")+g,H=m+i.slice(5).join("")+h+A,ot=I.length+o.data.length+H.length,N=new Uint8Array(ot),y=0;for(let S=0;S<I.length;S++)N[y++]=I.charCodeAt(S);N.set(o.data,y),y+=o.data.length;for(let S=0;S<H.length;S++)N[y++]=H.charCodeAt(S);return N}async function sr(e,t={}){let r=t.scale??2,n=k(t.pageSize??"A4",t.orientation??"portrait"),o=z(t.margin),i=it();i.style.width=`${n.width}px`,i.style.minHeight=`${n.height}px`,i.style.padding=`${o.top}px ${o.right}px ${o.bottom}px ${o.left}px`,i.style.background="white",i.style.boxSizing="border-box";let s=_(e);i.appendChild(s),st(i);let a=Jt(n.width*r,n.height*r),l=Xt(a);return l.scale(r,r),l.fillStyle="white",l.fillRect(0,0,n.width,n.height),at(i),a}var Pt=class{async toBlob(t,r){if(!xt())throw c("PDF_EXPORT_FAILED","PDF export is not supported");let o=C(t)[0];if(!o)throw c("ELEMENT_NOT_FOUND","No element found");let i=k(r?.pageSize??"A4",r?.orientation??"portrait"),s=await sr(o,r),a=Zt(s,r?.quality??.92),l=ir(a,i.width*.75,i.height*.75,r?.metadata);return new Blob([l.buffer],{type:"application/pdf"})}async toBase64(t,r){let n=await this.toBlob(t,r);return new Promise((o,i)=>{let s=new FileReader;s.onloadend=()=>{let a=s.result;o(a.split(",")[1]??"");},s.onerror=()=>i(c("PDF_EXPORT_FAILED","Failed to convert to base64")),s.readAsDataURL(n);})}async toDataURL(t,r){let n=await this.toBlob(t,r);return new Promise((o,i)=>{let s=new FileReader;s.onloadend=()=>o(s.result),s.onerror=()=>i(c("PDF_EXPORT_FAILED","Failed to convert to data URL")),s.readAsDataURL(n);})}async download(t,r,n){let o=await this.toBlob(t,n),i=URL.createObjectURL(o),s=document.createElement("a");s.href=i,s.download=r.endsWith(".pdf")?r:`${r}.pdf`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i);}async downloadHTML(t,r,n){let o=it();o.innerHTML=t,st(o);try{await this.download(o,r,n);}finally{at(o);}}};function le(){return new Pt}function cr(e){let t=F(),[r,n]=react.useState(false),[o,i]=react.useState(0),[s,a]=react.useState(null),l=react.useRef(null),u={...t?.defaultOptions,...e};react.useEffect(()=>(l.current=le(),()=>{l.current=null;}),[]);let w=react.useCallback(async(m,x,v)=>{if(!l.current){a(new f("PDF_EXPORT_FAILED","PDF exporter not initialized"));return}n(true),i(0),a(null);let d={...u,...v,onProgress:h=>{i(h),v?.onProgress?.(h),u.onProgress?.(h);}};try{await l.current.download(m,x,d),i(100);}catch(h){let A=h instanceof f?h:new f("PDF_EXPORT_FAILED",h instanceof Error?h.message:"Unknown error");throw a(A),A}finally{n(false);}},[u]),p=react.useCallback(async(m,x)=>{if(!l.current)throw new f("PDF_EXPORT_FAILED","PDF exporter not initialized");n(true),i(0),a(null);let v={...u,...x,onProgress:d=>{i(d),x?.onProgress?.(d),u.onProgress?.(d);}};try{let d=await l.current.toBlob(m,v);return i(100),d}catch(d){let h=d instanceof f?d:new f("PDF_EXPORT_FAILED",d instanceof Error?d.message:"Unknown error");throw a(h),h}finally{n(false);}},[u]),P=react.useCallback(async(m,x)=>{if(!l.current)throw new f("PDF_EXPORT_FAILED","PDF exporter not initialized");n(true),i(0),a(null);let v={...u,...x,onProgress:d=>{i(d),x?.onProgress?.(d),u.onProgress?.(d);}};try{let d=await l.current.toBase64(m,v);return i(100),d}catch(d){let h=d instanceof f?d:new f("PDF_EXPORT_FAILED",d instanceof Error?d.message:"Unknown error");throw a(h),h}finally{n(false);}},[u]),b=react.useCallback(async(m,x)=>{if(!l.current)throw new f("PDF_EXPORT_FAILED","PDF exporter not initialized");n(true),i(0),a(null);let v={...u,...x,onProgress:d=>{i(d),x?.onProgress?.(d),u.onProgress?.(d);}};try{let d=await l.current.toDataURL(m,v);return i(100),d}catch(d){let h=d instanceof f?d:new f("PDF_EXPORT_FAILED",d instanceof Error?d.message:"Unknown error");throw a(h),h}finally{n(false);}},[u]),g=react.useCallback(()=>{a(null);},[]);return {download:w,toBlob:p,toBase64:P,toDataURL:b,isExporting:r,progress:o,error:s,clearError:g}}var mr=react.forwardRef(function({children:t,className:r,style:n,id:o,...i},s){let a=react.useRef(null),{print:l}=K(i);return react.useImperativeHandle(s,()=>({print:async u=>{a.current&&await l(a.current,u);},getElement:()=>a.current}),[l]),jsxRuntime.jsx("div",{ref:a,id:o,className:r,style:n,children:t})});function gr({target:e,targetRef:t,options:r,children:n="Print",render:o,onPrintStart:i,onPrintComplete:s,onPrintError:a,disabled:l,onClick:u,...w}){let{print:p,isPrinting:P,error:b}=K(r),g=async m=>{u?.(m);let x=t?.current??e;if(!x){console.error("PrintButton: No target specified");return}try{i?.(),await p(x,r),s?.();}catch(v){v instanceof f&&a?.(v);}};return o?jsxRuntime.jsx(jsxRuntime.Fragment,{children:o({print:async()=>{let m=t?.current??e;m&&await p(m,r);},isPrinting:P,error:b})}):jsxRuntime.jsx("button",{...w,onClick:g,disabled:l??P,children:n})}function yr({target:e,targetRef:t,trigger:r,isOpen:n,onClose:o,onPrint:i,onDownload:s,...a}){let l=react.useRef(null),u=t??l,w={...a,...o?{onClose:o}:{},...i?{onPrint:i}:{},...s?{onDownload:s}:{}},{open:p,close:P,isOpen:b}=ht(u,w),g=n!==void 0;react.useEffect(()=>{g&&(n&&!b?p():!n&&b&&P());},[n,g,b,p,P]),react.useEffect(()=>{if(typeof e=="string"&&!t){let x=document.querySelector(e);x instanceof HTMLElement&&(l.current=x);}},[e,t]);let m=()=>{p();};return r?jsxRuntime.jsx("span",{onClick:m,style:{cursor:"pointer"},children:r}):null}function xr({className:e}){return jsxRuntime.jsx("div",{className:`${V} ${e??""}`.trim(),style:{height:0,pageBreakBefore:"always",breakBefore:"page"},"aria-hidden":"true"})}function vr({children:e,className:t,style:r,as:n="div"}){return jsxRuntime.jsx(n,{className:`${U} ${t??""}`.trim(),style:{display:"none",...r},children:e})}function Tr({children:e,className:t,style:r,as:n="div"}){return jsxRuntime.jsx(n,{className:`${G} ${t??""}`.trim(),style:r,children:e})}exports.AVOID_BREAK_CLASS=Ct;exports.BREAK_AFTER_CLASS=Mt;exports.BREAK_BEFORE_CLASS=V;exports.NoPrint=Tr;exports.PRINT_HIDE_CLASS=G;exports.PRINT_ONLY_CLASS=U;exports.PageBreak=xr;exports.PrintButton=gr;exports.PrintContext=$;exports.PrintOnly=vr;exports.PrintPreview=yr;exports.PrintProvider=he;exports.Printable=mr;exports.usePDF=cr;exports.usePrint=K;exports.usePrintContext=ue;exports.usePrintPreview=ht;//# sourceMappingURL=react.cjs.map
|
|
1
|
+
'use strict';var chunkE7TXCY3N_cjs=require('./chunk-E7TXCY3N.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime');var b=react.createContext(null);function rt(){let r=react.useContext(b);if(!r)throw new Error("usePrintContext must be used within a PrintProvider");return r}function T(){return react.useContext(b)}function it({defaultOptions:r,children:a}){let[P,e]=react.useState(r??{}),l=react.useCallback(o=>{e(s=>({...s,...o}));},[]),n=react.useMemo(()=>({defaultOptions:P,setDefaultOptions:l}),[P,l]);return jsxRuntime.jsx(b.Provider,{value:n,children:a})}function D(r){let a=T(),[P,e]=react.useState(false),[l,n]=react.useState(null),o=react.useRef(null),s=react.useRef({});s.current=chunkE7TXCY3N_cjs.O(a?.defaultOptions??{},r),react.useEffect(()=>(o.current=chunkE7TXCY3N_cjs.P(),()=>{o.current?.destroy(),o.current=null;}),[]);let m=react.useCallback(async(d,g)=>{if(!o.current){n(new chunkE7TXCY3N_cjs.d("PRINT_NOT_SUPPORTED","Printer not initialized"));return}e(true),n(null);try{await o.current.print(d,chunkE7TXCY3N_cjs.O(s.current,g));}catch(i){let c=i instanceof chunkE7TXCY3N_cjs.d?i:new chunkE7TXCY3N_cjs.d("UNKNOWN",i instanceof Error?i.message:"Unknown error");throw n(c),c}finally{e(false);}},[]),x=react.useCallback(async(d,g)=>{if(!o.current){n(new chunkE7TXCY3N_cjs.d("PRINT_NOT_SUPPORTED","Printer not initialized"));return}e(true),n(null);try{await o.current.printHTML(d,chunkE7TXCY3N_cjs.O(s.current,g));}catch(i){let c=i instanceof chunkE7TXCY3N_cjs.d?i:new chunkE7TXCY3N_cjs.d("UNKNOWN",i instanceof Error?i.message:"Unknown error");throw n(c),c}finally{e(false);}},[]),p=react.useCallback(async(d,g)=>{if(!o.current){n(new chunkE7TXCY3N_cjs.d("PRINT_NOT_SUPPORTED","Printer not initialized"));return}e(true),n(null);try{await o.current.printURL(d,chunkE7TXCY3N_cjs.O(s.current,g));}catch(i){let c=i instanceof chunkE7TXCY3N_cjs.d?i:new chunkE7TXCY3N_cjs.d("UNKNOWN",i instanceof Error?i.message:"Unknown error");throw n(c),c}finally{e(false);}},[]),t=react.useCallback(()=>{n(null);},[]);return {print:m,printHTML:x,printURL:p,isPrinting:P,error:l,clearError:t}}function k(r,a){let P=T(),[e,l]=react.useState(false),[n,o]=react.useState(1),[s,m]=react.useState(1),[x,p]=react.useState(100),t=react.useRef(null),d=react.useRef({});d.current={...P?.defaultOptions,...a};let g=react.useCallback(()=>{if(!r.current)return null;t.current&&t.current.destroy();let y=d.current,H=chunkE7TXCY3N_cjs.S(r.current,{...y,onClose:()=>{l(false),y.onClose?.();}});return t.current=H,H},[r]);react.useEffect(()=>()=>{t.current?.destroy(),t.current=null;},[]);let i=react.useCallback(()=>{let y=g();y&&(y.open(),l(true),o(y.getCurrentPage()),m(y.getTotalPages()),p(y.getZoom()));},[g]),c=react.useCallback(()=>{t.current?.close(),l(false);},[]),u=react.useCallback(async()=>{await t.current?.print();},[]),O=react.useCallback(async y=>{await t.current?.download(y);},[]),v=react.useCallback(y=>{t.current?.setZoom(y),p(y);},[]),E=react.useCallback(()=>{t.current?.zoomIn(),t.current&&p(t.current.getZoom());},[]),S=react.useCallback(()=>{t.current?.zoomOut(),t.current&&p(t.current.getZoom());},[]),R=react.useCallback(()=>{t.current?.resetZoom(),p(100);},[]),B=react.useCallback(()=>{t.current?.nextPage(),t.current&&o(t.current.getCurrentPage());},[]),Y=react.useCallback(()=>{t.current?.prevPage(),t.current&&o(t.current.getCurrentPage());},[]),q=react.useCallback(y=>{t.current?.goToPage(y),t.current&&o(t.current.getCurrentPage());},[]);return {open:i,close:c,isOpen:e,print:u,download:O,currentPage:n,totalPages:s,zoom:x,setZoom:v,zoomIn:E,zoomOut:S,resetZoom:R,nextPage:B,prevPage:Y,goToPage:q}}function ct(r){let a=T(),[P,e]=react.useState(false),[l,n]=react.useState(0),[o,s]=react.useState(null),m=react.useRef(null),x=react.useRef({});x.current={...a?.defaultOptions,...r},react.useEffect(()=>(m.current=chunkE7TXCY3N_cjs.R(),()=>{m.current=null;}),[]);let p=react.useCallback(async(u,O)=>{let v=m.current;if(!v){let R=new chunkE7TXCY3N_cjs.d("PDF_EXPORT_FAILED","PDF exporter not initialized");throw s(R),R}e(true),n(0),s(null);let E=x.current,S={...E,...O,onProgress:R=>{n(R),E.onProgress?.(R),O?.onProgress!==E.onProgress&&O?.onProgress?.(R);}};try{let R=await u(v,S);return n(100),R}catch(R){let B=R instanceof chunkE7TXCY3N_cjs.d?R:new chunkE7TXCY3N_cjs.d("PDF_EXPORT_FAILED",R instanceof Error?R.message:"Unknown error");throw s(B),B}finally{e(false);}},[]),t=react.useCallback((u,O,v)=>p((E,S)=>E.download(u,O,S),v),[p]),d=react.useCallback((u,O)=>p((v,E)=>v.toBlob(u,E),O),[p]),g=react.useCallback((u,O)=>p((v,E)=>v.toBase64(u,E),O),[p]),i=react.useCallback((u,O)=>p((v,E)=>v.toDataURL(u,E),O),[p]),c=react.useCallback(()=>{s(null);},[]);return {download:t,toBlob:d,toBase64:g,toDataURL:i,isExporting:P,progress:l,error:o,clearError:c}}var mt=react.forwardRef(function({children:a,className:P,style:e,id:l,...n},o){let s=react.useRef(null),{print:m}=D(n);return react.useImperativeHandle(o,()=>({print:async x=>{s.current&&await m(s.current,x);},getElement:()=>s.current}),[m]),jsxRuntime.jsx("div",{ref:s,id:l,className:P,style:e,children:a})});function gt({target:r,targetRef:a,options:P,children:e="Print",render:l,onPrintStart:n,onPrintComplete:o,onPrintError:s,disabled:m,onClick:x,...p}){let{print:t,isPrinting:d,error:g}=D(P),i=async c=>{x?.(c);let u=a?.current??r;if(!u){console.error("PrintButton: No target specified");return}try{n?.(),await t(u),o?.();}catch(O){O instanceof chunkE7TXCY3N_cjs.d&&s?.(O);}};return l?jsxRuntime.jsx(jsxRuntime.Fragment,{children:l({print:async()=>{let c=a?.current??r;c&&await t(c);},isPrinting:d,error:g})}):jsxRuntime.jsx("button",{...p,onClick:i,disabled:m??d,children:e})}function yt({target:r,targetRef:a,trigger:P,isOpen:e,onClose:l,onPrint:n,onDownload:o,...s}){let m=react.useRef(null),x=a??m,p={...s,...l?{onClose:l}:{},...n?{onPrint:n}:{},...o?{onDownload:o}:{}},{open:t,close:d,isOpen:g}=k(x,p);react.useEffect(()=>{if(!a)if(typeof r=="string"){let u=document.querySelector(r);m.current=u instanceof HTMLElement?u:null;}else r instanceof HTMLElement&&(m.current=r);},[r,a]);let i=e!==void 0;react.useEffect(()=>{i&&(e&&!g?t():!e&&g&&d());},[e,i,g,t,d]);let c=()=>{t();};return P?jsxRuntime.jsx("span",{onClick:c,style:{cursor:"pointer"},children:P}):null}function xt({className:r}){return jsxRuntime.jsx("div",{className:`${chunkE7TXCY3N_cjs.r} ${r??""}`.trim(),style:{height:0,pageBreakBefore:"always",breakBefore:"page"},"aria-hidden":"true"})}function wt({children:r,className:a,style:P,as:e="div"}){return jsxRuntime.jsx(e,{className:`${chunkE7TXCY3N_cjs.K} ${a??""}`.trim(),style:{display:"none",...P},children:r})}function Ct({children:r,className:a,style:P,as:e="div"}){return jsxRuntime.jsx(e,{className:`${chunkE7TXCY3N_cjs.J} ${a??""}`.trim(),style:P,children:r})}Object.defineProperty(exports,"AVOID_BREAK_CLASS",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.t}});Object.defineProperty(exports,"BREAK_AFTER_CLASS",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.s}});Object.defineProperty(exports,"BREAK_BEFORE_CLASS",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.r}});Object.defineProperty(exports,"PRINT_HIDE_CLASS",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.J}});Object.defineProperty(exports,"PRINT_ONLY_CLASS",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.K}});Object.defineProperty(exports,"PrintError",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.d}});Object.defineProperty(exports,"isPrintError",{enumerable:true,get:function(){return chunkE7TXCY3N_cjs.f}});exports.NoPrint=Ct;exports.PageBreak=xt;exports.PrintButton=gt;exports.PrintContext=b;exports.PrintOnly=wt;exports.PrintPreview=yt;exports.PrintProvider=it;exports.Printable=mt;exports.usePDF=ct;exports.usePrint=D;exports.usePrintContext=rt;exports.usePrintPreview=k;//# sourceMappingURL=react.cjs.map
|
|
487
2
|
//# sourceMappingURL=react.cjs.map
|