@oxog/printkit 1.1.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 +21 -4
- 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-B6q-4bX_.d.cts → errors-COjJm-gl.d.cts} +20 -1
- package/dist/{errors-B6q-4bX_.d.ts → errors-COjJm-gl.d.ts} +20 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +13 -7
- package/dist/index.d.ts +13 -7
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +9 -8
- package/dist/react.d.ts +9 -8
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/package.json +4 -2
- package/dist/chunk-KWR7DOLQ.cjs +0 -482
- package/dist/chunk-KWR7DOLQ.cjs.map +0 -1
- package/dist/chunk-YHD5OSS6.js +0 -482
- package/dist/chunk-YHD5OSS6.js.map +0 -1
package/dist/chunk-YHD5OSS6.js
DELETED
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
function P(){return typeof window<"u"&&typeof window.print=="function"&&typeof document<"u"}function ft(){if(typeof document>"u")return false;try{let e=document.createElement("canvas");return typeof e.getContext=="function"&&e.getContext("2d")!==null&&typeof e.toDataURL=="function"}catch{return false}}function en(){return typeof window<"u"&&typeof document<"u"}var L=class e extends Error{constructor(t,n,r){super(n),this.name="PrintError",this.code=t,this.target=r,Error.captureStackTrace&&Error.captureStackTrace(this,e);}},se={PRINT_NOT_SUPPORTED:"Printing is not supported in this environment",ELEMENT_NOT_FOUND:"Element not found",IFRAME_LOAD_FAILED:"Failed to load print iframe",PDF_EXPORT_FAILED:"Failed to export PDF",STYLE_LOAD_FAILED:"Failed to load stylesheet",CANCELLED:"Print operation was cancelled",UNKNOWN:"An unknown error occurred"};function c(e,t,n){let r=se[e];return t&&(r=`${r}: ${t}`),new L(e,r,n)}function le(e){return e instanceof L}function gt(e,t){return le(e)?e:e instanceof Error?new L("UNKNOWN",e.message,t):new L("UNKNOWN",String(e),t)}function m(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ht(e){return e.replace(/<\/(style)/gi,"<\\/$1")}var ce=new Set(["script","iframe","frame","frameset","object","embed","applet","base","meta","noscript","noembed","noframes","xmp","plaintext","portal","animate","animatemotion","animatetransform","set","handler","listener"]),de=new Set(["href","xlink:href","src","action","formaction","background","poster","lowsrc","dynsrc","ping","cite","longdesc","manifest","data","codebase"]);function pe(e){return e.replace(/[\u0000- \u007f-\u009f]+/g,"").toLowerCase()}function W(e){let t=pe(e);return t.startsWith("javascript:")||t.startsWith("vbscript:")?true:t.startsWith("data:")&&!t.startsWith("data:image/")}function O(e,t={}){let n=Array.from(e.querySelectorAll("*"));for(let r of n){let o=r.localName.toLowerCase();if(t.scriptsOnly?o==="script":ce.has(o)){r.remove();continue}for(let a of Array.from(r.attributes)){let i=a.name.toLowerCase();if(t.scriptsOnly){i.startsWith("on")&&r.removeAttribute(a.name);continue}(i.startsWith("on")||i==="srcdoc"||de.has(i)&&W(a.value)||i==="srcset"&&/(?:^|,)\s*(?:javascript|vbscript):/i.test(a.value))&&r.removeAttribute(a.name);}}}function yt(e){return typeof DOMParser>"u"?null:new DOMParser().parseFromString(e,"text/html")}function k(e){let t=yt(`<!DOCTYPE html><html><head></head><body>${e}</body></html>`);return t?(O(t.body),t.body.innerHTML):m(e)}function bt(e,t){let n=yt(e);if(!n)return {body:m(e),styles:[],styleSheets:[],title:""};O(n.documentElement);let r=[],o=[];for(let a of Array.from(n.head.querySelectorAll("style")))a.textContent&&r.push(a.textContent);for(let a of Array.from(n.head.querySelectorAll("link"))){let i=(a.getAttribute("rel")??"").toLowerCase().split(/\s+/),s=a.getAttribute("href");if(!(!i.includes("stylesheet")||!s))try{o.push(t?new URL(s,t).href:s);}catch{}}return {body:n.body.innerHTML,styles:r,styleSheets:o,title:n.title}}function Pt(e){return typeof e=="string"?document.querySelector(e):typeof e!="object"||e===null||typeof e.cloneNode!="function"||e.nodeType!==1?null:e}function me(e){if(Array.isArray(e)){let n=[];for(let r of e){let o=Pt(r);o&&n.push(o);}return n}let t=Pt(e);return t?[t]:[]}function v(e){let t=me(e);if(t.length===0){let n=typeof e=="string"?e:Array.isArray(e)?e.join(", "):"element";throw c("ELEMENT_NOT_FOUND",n,e)}return t}function Tt(e){let t=e.cloneNode(true),n=e.querySelectorAll("canvas"),r=t.querySelectorAll("canvas");n.forEach((i,s)=>{let l=r[s];if(l){let d=l.getContext("2d");d&&d.drawImage(i,0,0);}});let o=e.querySelectorAll("input, textarea, select"),a=t.querySelectorAll("input, textarea, select");return o.forEach((i,s)=>{let l=a[s];l&&(i instanceof HTMLInputElement?i.type==="checkbox"||i.type==="radio"?l.checked=i.checked:l.value=i.value:(i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)&&(l.value=i.value));}),t}function K(e,t){let n="input, textarea, select",r=e.matches(n)?[e,...Array.from(e.querySelectorAll(n))]:Array.from(e.querySelectorAll(n)),o=t.matches(n)?[t,...Array.from(t.querySelectorAll(n))]:Array.from(t.querySelectorAll(n));r.forEach((a,i)=>{let s=o[i];if(s){if(a instanceof HTMLInputElement){let l=a.type.toLowerCase();l==="checkbox"||l==="radio"?a.checked?s.setAttribute("checked",""):s.removeAttribute("checked"):l==="password"||l==="file"?s.removeAttribute("value"):s.setAttribute("value",a.value);}else if(a instanceof HTMLTextAreaElement)s.textContent=a.value;else if(a instanceof HTMLSelectElement){let l=Array.from(s.querySelectorAll("option"));Array.from(a.options).forEach((d,u)=>{let f=l[u];f&&(d.selected?f.setAttribute("selected",""):f.removeAttribute("selected"));});}}});}function J(e,t){let n=Array.from(e.querySelectorAll("canvas")),r=Array.from(t.querySelectorAll("canvas"));n.forEach((o,a)=>{let i=r[a];if(!i)return;let s;try{s=o.toDataURL("image/png");}catch{return}if(!s.startsWith("data:image/"))return;let l=document.createElement("img");l.src=s,l.width=o.width,l.height=o.height;for(let d of Array.from(i.attributes))d.name!=="width"&&d.name!=="height"&&l.setAttribute(d.name,d.value);i.replaceWith(l);});}function F(e){return e.map(t=>{let n=t.cloneNode(true);K(t,n),J(t,n),n.querySelectorAll("img[loading]").forEach(o=>o.removeAttribute("loading"));let r=document.createElement("div");return r.appendChild(n),O(r,{scriptsOnly:true}),r.innerHTML}).join(`
|
|
2
|
-
`)}function xt(){let e=document.createElement("div");return e.style.cssText="position:absolute;left:-9999px;top:-9999px;visibility:hidden;",e}function wt(e){document.body.appendChild(e);}function vt(e){document.body.contains(e)&&document.body.removeChild(e);}function R(e,t=1e4){let r=Array.from(e.querySelectorAll("img")).filter(o=>!o.complete&&o.getAttribute("loading")?.toLowerCase()!=="lazy");return r.length===0?Promise.resolve():new Promise(o=>{let a=r.length,i=[],s=()=>{clearTimeout(l),i.forEach(d=>d()),o();},l=setTimeout(s,t);for(let d of r){let u=()=>{a--,a===0&&s();};d.addEventListener("load",u,{once:true}),d.addEventListener("error",u,{once:true}),i.push(()=>{d.removeEventListener("load",u),d.removeEventListener("error",u);});}})}var Et={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 T(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 ue(e){return typeof e=="string"&&e in Et}function _(e,t="portrait"){let n;return ue(e)?n={...Et[e]}:n={width:T(e.width),height:T(e.height)},t==="landscape"?{width:n.height,height:n.width}:n}function Lt(e,t="portrait"){let n=_(e,t);return `
|
|
3
|
-
@page {
|
|
4
|
-
size: ${n.width} ${n.height};
|
|
5
|
-
}
|
|
6
|
-
`}function S(e,t="portrait",n=96){let r=_(e,t),o=a=>{let i=parseFloat(a);return a.endsWith("mm")?i/25.4*n:a.endsWith("cm")?i/2.54*n:a.endsWith("in")?i*n:a.endsWith("pt")?i/72*n:i};return {width:Math.round(o(r.width)),height:Math.round(o(r.height))}}var C=10;function z(e){if(e===void 0){let t=T(C);return {top:t,right:t,bottom:t,left:t}}if(typeof e=="number"||typeof e=="string"){let t=T(e);return {top:t,right:t,bottom:t,left:t}}return {top:T(e.top??C),right:T(e.right??C),bottom:T(e.bottom??C),left:T(e.left??C)}}function Ot(e){let t=z(e);return `
|
|
7
|
-
@page {
|
|
8
|
-
margin: ${t.top} ${t.right} ${t.bottom} ${t.left};
|
|
9
|
-
}
|
|
10
|
-
`}function I(e,t=96){let n=z(e),r=o=>{let a=parseFloat(o);return o.endsWith("mm")?a/25.4*t:o.endsWith("cm")?a/2.54*t:o.endsWith("in")?a*t:o.endsWith("pt")?a/72*t:a};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 X="print-break-before",St="print-break-after",Mt="print-avoid-break";function gn(){let e=document.createElement("div");return e.className=X,e.style.cssText="height: 0; page-break-before: always; break-before: page;",e.setAttribute("aria-hidden","true"),e}function hn(e){e.classList.add(Mt);}function yn(e){e.classList.add(X);}function bn(e){e.classList.add(St);}function At(){return `
|
|
11
|
-
@media print {
|
|
12
|
-
.${X} {
|
|
13
|
-
page-break-before: always !important;
|
|
14
|
-
break-before: page !important;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.${St} {
|
|
18
|
-
page-break-after: always !important;
|
|
19
|
-
break-after: page !important;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.${Mt} {
|
|
23
|
-
page-break-inside: avoid !important;
|
|
24
|
-
break-inside: avoid !important;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
`}function Dt(e){let t=[];return e.pageBreakBefore&&t.push(`
|
|
28
|
-
@media print {
|
|
29
|
-
${e.pageBreakBefore} {
|
|
30
|
-
page-break-before: always !important;
|
|
31
|
-
break-before: page !important;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`),e.pageBreakAfter&&t.push(`
|
|
35
|
-
@media print {
|
|
36
|
-
${e.pageBreakAfter} {
|
|
37
|
-
page-break-after: always !important;
|
|
38
|
-
break-after: page !important;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
`),e.avoidBreakInside&&t.push(`
|
|
42
|
-
@media print {
|
|
43
|
-
${e.avoidBreakInside} {
|
|
44
|
-
page-break-inside: avoid !important;
|
|
45
|
-
break-inside: avoid !important;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
`),t.join(`
|
|
49
|
-
`)}function Pn(e,t,n=0,r=0){let o=t-n-r;return o<=0?1:Math.ceil(e/o)}function kt(e,t,n,r=new Date){return {pageNumber:e,totalPages:t,title:n,date:r}}function fe(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 Z(e,t){return e?typeof e=="function"?e(t):fe(e,{...t,title:m(t.title)}):""}function Ct(e,t={}){return e?`
|
|
50
|
-
<header class="print-header" style="
|
|
51
|
-
${t.fixed?`
|
|
52
|
-
position: fixed;
|
|
53
|
-
top: 0;
|
|
54
|
-
left: 0;
|
|
55
|
-
right: 0;
|
|
56
|
-
`:""}
|
|
57
|
-
width: 100%;
|
|
58
|
-
box-sizing: border-box;
|
|
59
|
-
">
|
|
60
|
-
${e}
|
|
61
|
-
</header>
|
|
62
|
-
`:""}function It(e,t={}){return e?`
|
|
63
|
-
<footer class="print-footer" style="
|
|
64
|
-
${t.fixed?`
|
|
65
|
-
position: fixed;
|
|
66
|
-
bottom: 0;
|
|
67
|
-
left: 0;
|
|
68
|
-
right: 0;
|
|
69
|
-
`:""}
|
|
70
|
-
width: 100%;
|
|
71
|
-
box-sizing: border-box;
|
|
72
|
-
">
|
|
73
|
-
${e}
|
|
74
|
-
</footer>
|
|
75
|
-
`:""}function Ht(){return `
|
|
76
|
-
@media print {
|
|
77
|
-
.print-header {
|
|
78
|
-
page-break-after: avoid;
|
|
79
|
-
}
|
|
80
|
-
.print-footer {
|
|
81
|
-
page-break-before: avoid;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.print-header,
|
|
86
|
-
.print-footer {
|
|
87
|
-
-webkit-print-color-adjust: exact;
|
|
88
|
-
print-color-adjust: exact;
|
|
89
|
-
}
|
|
90
|
-
`}function ge(){return `printkit-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function En(e){let t=ge(),n=document.createElement("style");return n.id=t,n.setAttribute("data-printkit","true"),n.textContent=e,document.head.appendChild(n),t}function Ln(e){let t=document.getElementById(e);t&&t.remove();}function On(){document.querySelectorAll('style[data-printkit="true"]').forEach(t=>t.remove());}function U(e){let t=Array.isArray(e)?e.join(`
|
|
91
|
-
`):e;return `<style>${ht(t)}</style>`}function G(e){return `<link rel="stylesheet" href="${m(e)}">`}function $t(e){return e.map(G).join(`
|
|
92
|
-
`)}function Nt(e){let t=[];for(let n of e)n&&(Array.isArray(n)?t.push(...n):t.push(n));return t.join(`
|
|
93
|
-
`)}function he(){let e=[];return document.querySelectorAll('link[rel="stylesheet"]').forEach(n=>{let r=n.href;r&&e.push(G(r));}),e}function ye(){let e=[];return document.querySelectorAll("style").forEach(n=>{if(n.hasAttribute("data-printkit"))return;let r=n.textContent;r&&e.push(U(r));}),e}function be(){return [...he(),...ye()]}function Ft(){return be().join(`
|
|
94
|
-
`)}function An(e){let t=window.getComputedStyle(e),n=[];for(let r=0;r<t.length;r++){let o=t[r];if(o){let a=t.getPropertyValue(o);a&&n.push(`${o}: ${a}`);}}return n.join("; ")}var Pe="print-hide",Rt="print-only";function Te(){return `
|
|
95
|
-
/* Print visibility classes */
|
|
96
|
-
@media print {
|
|
97
|
-
.${Pe},
|
|
98
|
-
.no-print {
|
|
99
|
-
display: none !important;
|
|
100
|
-
visibility: hidden !important;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
.${Rt},
|
|
104
|
-
.print-only {
|
|
105
|
-
display: block !important;
|
|
106
|
-
visibility: visible !important;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@media screen {
|
|
111
|
-
.${Rt},
|
|
112
|
-
.print-only {
|
|
113
|
-
display: none !important;
|
|
114
|
-
visibility: hidden !important;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/* Default print optimizations */
|
|
119
|
-
@media print {
|
|
120
|
-
* {
|
|
121
|
-
-webkit-print-color-adjust: exact !important;
|
|
122
|
-
print-color-adjust: exact !important;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
body {
|
|
126
|
-
margin: 0;
|
|
127
|
-
padding: 0;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/* Remove backgrounds by default for better printing */
|
|
131
|
-
html {
|
|
132
|
-
background: white !important;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/* Ensure links are readable */
|
|
136
|
-
a[href]:after {
|
|
137
|
-
content: none !important;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/* Prevent orphans and widows */
|
|
141
|
-
p, h1, h2, h3, h4, h5, h6 {
|
|
142
|
-
orphans: 3;
|
|
143
|
-
widows: 3;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/* Avoid breaking inside these elements */
|
|
147
|
-
h1, h2, h3, h4, h5, h6 {
|
|
148
|
-
page-break-after: avoid;
|
|
149
|
-
break-after: avoid;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
img {
|
|
153
|
-
page-break-inside: avoid;
|
|
154
|
-
break-inside: avoid;
|
|
155
|
-
max-width: 100% !important;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
table {
|
|
159
|
-
page-break-inside: auto;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
tr {
|
|
163
|
-
page-break-inside: avoid;
|
|
164
|
-
break-inside: avoid;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
thead {
|
|
168
|
-
display: table-header-group;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
tfoot {
|
|
172
|
-
display: table-footer-group;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
`}function xe(){return `
|
|
176
|
-
*, *::before, *::after {
|
|
177
|
-
box-sizing: border-box;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
html {
|
|
181
|
-
font-size: 16px;
|
|
182
|
-
line-height: 1.5;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
body {
|
|
186
|
-
margin: 0;
|
|
187
|
-
padding: 0;
|
|
188
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
189
|
-
'Helvetica Neue', Arial, sans-serif;
|
|
190
|
-
color: #000;
|
|
191
|
-
background: #fff;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
img {
|
|
195
|
-
max-width: 100%;
|
|
196
|
-
height: auto;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
table {
|
|
200
|
-
border-collapse: collapse;
|
|
201
|
-
width: 100%;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
th, td {
|
|
205
|
-
text-align: left;
|
|
206
|
-
padding: 8px;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
pre, code {
|
|
210
|
-
font-family: 'Courier New', Courier, monospace;
|
|
211
|
-
font-size: 14px;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
pre {
|
|
215
|
-
white-space: pre-wrap;
|
|
216
|
-
word-wrap: break-word;
|
|
217
|
-
overflow-x: auto;
|
|
218
|
-
}
|
|
219
|
-
`}function we(){return `
|
|
220
|
-
@media print {
|
|
221
|
-
* {
|
|
222
|
-
-webkit-print-color-adjust: exact !important;
|
|
223
|
-
print-color-adjust: exact !important;
|
|
224
|
-
color-adjust: exact !important;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
`}function _t(){return [xe(),Te(),we()].join(`
|
|
228
|
-
`)}function ve(){let e=document.createElement("iframe");return e.style.cssText=`
|
|
229
|
-
position: fixed;
|
|
230
|
-
right: 0;
|
|
231
|
-
bottom: 0;
|
|
232
|
-
width: 0;
|
|
233
|
-
height: 0;
|
|
234
|
-
border: 0;
|
|
235
|
-
visibility: hidden;
|
|
236
|
-
opacity: 0;
|
|
237
|
-
pointer-events: none;
|
|
238
|
-
`,e.setAttribute("aria-hidden","true"),e.setAttribute("tabindex","-1"),e}function Ee(e,t=3e4){return new Promise((n,r)=>{let o=setTimeout(()=>{e.onload=null,e.onerror=null,r(c("IFRAME_LOAD_FAILED","Load timeout"));},t);e.onload=()=>{clearTimeout(o),requestAnimationFrame(()=>{requestAnimationFrame(()=>{n();});});},e.onerror=()=>{clearTimeout(o),r(c("IFRAME_LOAD_FAILED","Load error"));};})}function Le(e,t){let n=e.contentDocument??e.contentWindow?.document;if(!n)throw c("IFRAME_LOAD_FAILED","Cannot access iframe document");n.open(),n.write(t),n.close();}function V(e){e&&(e.onload=null,e.onerror=null,e.parentNode&&e.parentNode.removeChild(e));}function zt(e){return new Promise((t,n)=>{let r;try{let o=e.contentWindow;if(!o){n(c("IFRAME_LOAD_FAILED","Cannot access iframe window"));return}o.focus();let a=()=>{o.removeEventListener("afterprint",a),clearTimeout(r),t();};o.addEventListener("afterprint",a),r=setTimeout(()=>{o.removeEventListener("afterprint",a),t();},1e3),o.print();}catch(o){clearTimeout(r),n(c("IFRAME_LOAD_FAILED",o instanceof Error?o.message:"Print failed"));}})}async function Ut(e,t){let n=ve();document.body.appendChild(n);try{let r=Ee(n,t);try{Le(n,e);}catch(o){throw r.catch(()=>{}),o}await r;}catch(r){throw V(n),r}return n}var Bt=new WeakSet;function M(e,t){let n=typeof e=="object"&&e!==null?e:null;!t.onError||n&&Bt.has(n)||(n&&Bt.add(n),t.onError(gt(e)));}var jt={pageSize:"A4",orientation:"portrait"};function g(e,t={}){let n=t.pageSize??jt.pageSize,r=t.orientation??jt.orientation,o=_(n,r),a=z(t.margin),i=kt(1,1,t.title??"Print Document"),s=Z(t.header,i),l=Z(t.footer,i),d=Nt([_t(),Lt(n,r),Ot(t.margin),At(),Dt({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:d,header:s,footer:l,pageSize:o,margins:a,title:t.title??"Print Document"}}function h(e,t={}){let n=t.copyStyles!==false?Ft():"",r=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>${m(e.title)}</title>
|
|
246
|
-
${n}
|
|
247
|
-
${r}
|
|
248
|
-
${U(e.styles)}
|
|
249
|
-
</head>
|
|
250
|
-
<body>
|
|
251
|
-
${e.header?Ct(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 y(e,t={}){let n=null;try{t.onBeforePrint&&await t.onBeforePrint(),n=await Ut(e),await zt(n),t.onAfterPrint&&t.onAfterPrint();}catch(r){throw M(r,t),r}finally{t.removeAfterPrint!==false&&V(n);}}async function qt(e,t={}){let n=v(e);for(let i of n)await R(i);let r=F(n),o=g(r,t),a=h(o,t);await y(a,t);}function Oe(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 Se(e){let t=e.toLowerCase().trim();return t.includes("<!doctype")||t.includes("<html")}async function B(e,t={},n){Oe(e);let r,o=[],a=[];if(Se(e)){let D=bt(e,n);r=D.body,o=D.styles,a=D.styleSheets;}else r=k(e);let i=[...t.styleSheets??[],...a],s=Array.isArray(t.styles)?[...t.styles,...o]:t.styles?[t.styles,...o]:o,{styles:l,styleSheets:d,...u}=t,f={...u,...s.length>0?{styles:s}:{},...i.length>0?{styleSheets:i}:{}},E=g(r,f),A=h(E,f);await y(A,t);}function Me(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 Ae(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 Wt(e,t={}){Me(e);let n=new URL(e,window.location.origin).href;try{let r=await Ae(n);await B(r,{...t,title:t.title??n},n);}catch(r){throw M(r,t),r}}function Y(e,t){let n=document.createElement("canvas");return n.width=e,n.height=t,n}function Q(e){let t=e.getContext("2d");if(!t)throw c("PDF_EXPORT_FAILED","Cannot get canvas 2D context");return t}function Kt(e,t=.92){return e.toDataURL("image/jpeg",t)}function tt(e){return new Promise((t,n)=>{let r=new Image;r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>n(c("ELEMENT_NOT_FOUND",`Failed to load image: ${e}`)),r.src=e;})}function et(e){return typeof e=="string"?e:e.src}function Jt(e){let t=et(e);if(!t||t.trim().length===0)throw c("ELEMENT_NOT_FOUND","Image source is empty");if(W(t))throw c("ELEMENT_NOT_FOUND","Image source must be an image URL")}function Xt(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="${m(e)}"
|
|
269
|
-
alt="${m(t)}"
|
|
270
|
-
style="
|
|
271
|
-
max-width: 100%;
|
|
272
|
-
max-height: 100%;
|
|
273
|
-
${r}
|
|
274
|
-
"
|
|
275
|
-
/>
|
|
276
|
-
</div>
|
|
277
|
-
`}function De(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
|
-
${Xt(n,`Image ${r+1}`,t)}
|
|
286
|
-
</div>
|
|
287
|
-
`).join("")}function Zt(){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 Gt(e,t={}){Jt(e);let n=et(e);await tt(n);let r=Xt(n,t.title??"Image"),o=g(r,{...t,styles:[Zt(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),a=h(o,t);await y(a,t);}async function Vt(e,t={}){if(!e||e.length===0)throw c("ELEMENT_NOT_FOUND","No images provided");for(let i of e)Jt(i);let n=e.map(et);await Promise.all(n.map(tt));let r=De(n),o=g(r,{...t,styles:[Zt(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),a=h(o,t);await y(a,t);}var H={string:"#22863a",number:"#005cc5",boolean:"#d73a49",null:"#6f42c1",key:"#032f62"};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=H.number;if(/^"/.test(t)){if(/:$/.test(t))return n=H.key,t=t.replace(/:$/,""),`<span style="color:${n}">${m(t)}</span>:`;n=H.string;}else /true|false/.test(t)?n=H.boolean:/null/.test(t)&&(n=H.null);return `<span style="color:${n}">${m(t)}</span>`})}function Ce(e,t=2){let n;try{n=JSON.stringify(e,null,t);}catch{throw c("UNKNOWN","Failed to stringify JSON data")}if(n===void 0)throw c("UNKNOWN","Data cannot be represented as JSON");return n}function Ie(e,t={}){let{indent:n=2,syntaxHighlight:r=false}=t,o=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(o):m(o)}</code></pre>
|
|
318
|
-
`}function He(){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 Yt(e,t={}){if(e===void 0)throw c("ELEMENT_NOT_FOUND","JSON data is undefined");let n=Ie(e,t),r=g(n,{...t,styles:[He(),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),o=h(r,t);await y(o,t);}function $e(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 Ne(e,t={}){let n=t.headerStyles??"",r=t.cellStyles??"",o=e.map(a=>`<th style="${m(r)}">${m(a)}</th>`).join("");return `
|
|
336
|
-
<thead style="${m(n)}">
|
|
337
|
-
<tr>${o}</tr>
|
|
338
|
-
</thead>
|
|
339
|
-
`}function Fe(e,t,n={}){let r=n.cellStyles??"",a=n.stripedRows&&t%2===1?"background-color: #f9f9f9;":"",i=e.map(s=>`<td style="${m(r)}">${m(s??"")}</td>`).join("");return `<tr style="${a}">${i}</tr>`}function Re(e,t={}){return `<tbody>${e.map((r,o)=>Fe(r,o,t)).join("")}</tbody>`}function _e(e,t={}){let n=t.tableStyles??"",o=t.bordered!==false?"border: 1px solid #ddd; border-collapse: collapse;":"border-collapse: collapse;",a=e.caption?`<caption style="padding: 10px; font-weight: bold; text-align: left;">${m(e.caption)}</caption>`:"";return `
|
|
340
|
-
<table class="print-table" style="
|
|
341
|
-
width: 100%;
|
|
342
|
-
${o}
|
|
343
|
-
${m(n)}
|
|
344
|
-
">
|
|
345
|
-
${a}
|
|
346
|
-
${Ne(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 Qt(e,t={}){$e(e);let n=_e(e,t),r=g(n,{...t,styles:[ze(t),...Array.isArray(t.styles)?t.styles:t.styles?[t.styles]:[]]}),o=h(r,t);await y(o,t);}var j={title:"Print Document",pageSize:"A4",orientation:"portrait",copyStyles:true,removeAfterPrint:true,printBackground:true};function x(e,t){return t?{...e,...t,margin:t.margin!==void 0?t.margin:e.margin,styles:Ue(e.styles,t.styles),styleSheets:Be(e.styleSheets,t.styleSheets)}:{...e}}function Ue(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 Be(e,t){return t?e?[...e,...t]:t:e}function nt(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 ot=class{constructor(t){P()||console.warn("Printing is not supported in this environment"),this.defaultOptions={...j,...t},t&&nt(t);}async print(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await qt(t,r);}async printHTML(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await B(t,r);}async printURL(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await Wt(t,r);}async printImage(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await Gt(t,r);}async printImages(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await Vt(t,r);}async printJSON(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await Yt(t,r);}async printTable(t,n){if(!P())throw c("PRINT_NOT_SUPPORTED");let r=x(this.defaultOptions,n);await Qt(t,r);}setDefaultOptions(t){nt(t),this.defaultOptions=x(this.defaultOptions,t);}getDefaultOptions(){return {...this.defaultOptions}}destroy(){}};function je(e){return new ot(e)}var rt=null;function Or(){return rt||(rt=je()),rt}function it(e){let{pageWidth:t,pageHeight:n,margins:r}=e;return {width:Math.max(1,t-r.left-r.right),height:Math.max(1,n-r.top-r.bottom)}}function te(e,t){let n=window.getComputedStyle(e),r="";for(let i=0;i<n.length;i++){let s=n[i];s&&(r+=`${s}:${n.getPropertyValue(s)};`);}t.setAttribute("style",r);let o=e.children,a=t.children;for(let i=0;i<o.length;i++){let s=o[i],l=a[i];s&&l&&te(s,l);}}function qe(e,t){let n=Array.from(e.querySelectorAll("img")),r=Array.from(t.querySelectorAll("img"));n.forEach((o,a)=>{let i=r[a];if(!(!i||!o.complete||o.naturalWidth===0)&&!(o.currentSrc.startsWith("data:")||o.src.startsWith("data:")))try{let s=Y(o.naturalWidth,o.naturalHeight);Q(s).drawImage(o,0,0),i.setAttribute("src",s.toDataURL("image/png")),i.removeAttribute("srcset");}catch{}});}function We(e,t=3e4){return new Promise((n,r)=>{let o=new Image,a=setTimeout(()=>{o.onload=null,o.onerror=null,r(c("PDF_EXPORT_FAILED","Timed out rendering the element"));},t);o.onload=()=>{clearTimeout(a),n(o);},o.onerror=()=>{clearTimeout(a),r(c("PDF_EXPORT_FAILED","Failed to render the element"));},o.src=e;})}async function Ke(e,t){let n=it(t),r=document.createElement("div");r.setAttribute("aria-hidden","true"),r.style.cssText=["position: fixed","left: -100000px","top: 0",`width: ${n.width}px`,"margin: 0","padding: 0","border: 0","pointer-events: none","overflow: visible",`background: ${t.backgroundColor??"#ffffff"}`].join(";");let o=e.cloneNode(true);K(e,o),J(e,o),o.querySelectorAll("img[loading]").forEach(a=>a.removeAttribute("loading")),r.appendChild(o),O(r),document.body.appendChild(r);try{await R(r,1e4);let a=Math.max(1,Math.ceil(r.scrollHeight)),i=r.cloneNode(!0);return te(r,i),qe(r,i),i.style.position="static",i.style.left="0",i.style.top="0",i.style.transform="none",i.removeAttribute("aria-hidden"),{markup:new XMLSerializer().serializeToString(i),width:n.width,height:a}}finally{r.remove();}}async function Je(e,t,n){let r=it(t),{scale:o,margins:a}=t,i=Math.min(r.height,e.height-n),s=`<svg xmlns="http://www.w3.org/2000/svg" width="${Math.ceil(r.width*o)}" height="${Math.ceil(i*o)}" viewBox="0 ${n} ${r.width} ${i}"><foreignObject x="0" y="0" width="${r.width}" height="${e.height}">`+e.markup+"</foreignObject></svg>",l=await We(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`),d=Y(Math.round(t.pageWidth*o),Math.round(t.pageHeight*o)),u=Q(d);return u.fillStyle=t.backgroundColor??"#ffffff",u.fillRect(0,0,d.width,d.height),u.drawImage(l,Math.round(a.left*o),Math.round(a.top*o),Math.ceil(r.width*o),Math.ceil(i*o)),d}async function ee(e,t,n){let r=await Ke(e,t),o=it(t).height,a=Math.max(1,Math.ceil(r.height/o)),i=[];for(let s=0;s<a;s++)i.push(await Je(r,t,s*o)),n?.(s,a);return i}function $(e){if(/^[\x20-\x7e]*$/.test(e))return `(${e.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")})`;let t="FEFF";for(let n=0;n<e.length;n++)t+=e.charCodeAt(n).toString(16).padStart(4,"0").toUpperCase();return `<${t}>`}function Xe(e){let t=l=>l.toString().padStart(2,"0"),n=e.getFullYear(),r=t(e.getMonth()+1),o=t(e.getDate()),a=t(e.getHours()),i=t(e.getMinutes()),s=t(e.getSeconds());return `D:${n}${r}${o}${a}${i}${s}`}function Ze(e){let t=[];return e?.title&&t.push(`/Title ${$(e.title)}`),e?.author&&t.push(`/Author ${$(e.author)}`),e?.subject&&t.push(`/Subject ${$(e.subject)}`),e?.keywords&&e.keywords.length>0&&t.push(`/Keywords ${$(e.keywords.join(", "))}`),t.push(`/Creator ${$(e?.creator??"PrintKit")}`),t.push("/Producer (PrintKit)"),t.push(`/CreationDate (${Xe(e?.creationDate??new Date)})`),t.join(`
|
|
397
|
-
`)}function Ge(e){let t=e.slice(e.indexOf(",")+1),n=atob(t),r=new Uint8Array(n.length);for(let o=0;o<n.length;o++)r[o]=n.charCodeAt(o);return r}function Ve(e,t,n,r){let o=[],a=[],i=0,s=p=>{let b=new Uint8Array(p.length);for(let w=0;w<p.length;w++)b[w]=p.charCodeAt(w)&255;return b},l=p=>{let b=typeof p=="string"?s(p):p;o.push(b),i+=b.length;},d=p=>{a[p]=i,l(`${p} 0 obj
|
|
398
|
-
`);},u=Number(t.toFixed(2)),f=Number(n.toFixed(2)),E=p=>4+p*3,A=3+e.length*3;l(`%PDF-1.4
|
|
399
|
-
%\xFF\xFF\xFF\xFF
|
|
400
|
-
`),d(1),l(`<< /Type /Catalog /Pages 2 0 R >>
|
|
401
|
-
endobj
|
|
402
|
-
`),d(2);let D=e.map((p,b)=>`${E(b)} 0 R`).join(" ");l(`<< /Type /Pages /Kids [${D}] /Count ${e.length} >>
|
|
403
|
-
endobj
|
|
404
|
-
`),d(3),l(`<< ${Ze(r)} >>
|
|
405
|
-
endobj
|
|
406
|
-
`),e.forEach((p,b)=>{let w=E(b),pt=w+1,mt=w+2;d(w),l(`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${u} ${f}] /Contents ${pt} 0 R /Resources << /XObject << /Im${b} ${mt} 0 R >> >> >>
|
|
407
|
-
endobj
|
|
408
|
-
`);let ut=`q ${u} 0 0 ${f} 0 0 cm /Im${b} Do Q`;d(pt),l(`<< /Length ${ut.length} >>
|
|
409
|
-
stream
|
|
410
|
-
${ut}
|
|
411
|
-
endstream
|
|
412
|
-
endobj
|
|
413
|
-
`),d(mt),l(`<< /Type /XObject /Subtype /Image /Width ${p.width} /Height ${p.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${p.jpeg.length} >>
|
|
414
|
-
stream
|
|
415
|
-
`),l(p.jpeg),l(`
|
|
416
|
-
endstream
|
|
417
|
-
endobj
|
|
418
|
-
`);});let ae=i,lt=`xref
|
|
419
|
-
0 ${A+1}
|
|
420
|
-
0000000000 65535 f
|
|
421
|
-
`;for(let p=1;p<=A;p++)lt+=`${String(a[p]??0).padStart(10,"0")} 00000 n
|
|
422
|
-
`;l(lt),l(`trailer
|
|
423
|
-
<< /Size ${A+1} /Root 1 0 R /Info 3 0 R >>
|
|
424
|
-
startxref
|
|
425
|
-
${ae}
|
|
426
|
-
%%EOF`);let ct=new Uint8Array(i),dt=0;for(let p of o)ct.set(p,dt),dt+=p.length;return ct}function Ye(e,t){let n;try{n=Kt(e,t);}catch(r){throw c("PDF_EXPORT_FAILED",`This browser does not allow reading back the rendered page (${r instanceof Error?r.message:"canvas is tainted"})`)}if(!n.startsWith("data:image/jpeg"))throw c("PDF_EXPORT_FAILED","The browser could not encode the page as JPEG");return {jpeg:Ge(n),width:e.width,height:e.height}}var at=class{async toBlob(t,n){if(!ft())throw c("PDF_EXPORT_FAILED","PDF export is not supported");let o=v(t)[0];if(!o)throw c("ELEMENT_NOT_FOUND","No element found");let a=n?.onProgress;a?.(0);let i=S(n?.pageSize??"A4",n?.orientation??"portrait"),s=n?.quality??.92,l=[],d=await ee(o,{pageWidth:i.width,pageHeight:i.height,margins:I(n?.margin),scale:n?.scale??2},(f,E)=>{a?.(Math.min(99,Math.round((f+1)/E*95)));});for(let f of d)l.push(Ye(f,s));let u=Ve(l,i.width*.75,i.height*.75,n?.metadata);return a?.(100),new Blob([u.buffer],{type:"application/pdf"})}async toBase64(t,n){let r=await this.toBlob(t,n);return new Promise((o,a)=>{let i=new FileReader;i.onloadend=()=>{let s=i.result;o(s.split(",")[1]??"");},i.onerror=()=>a(c("PDF_EXPORT_FAILED","Failed to convert to base64")),i.readAsDataURL(r);})}async toDataURL(t,n){let r=await this.toBlob(t,n);return new Promise((o,a)=>{let i=new FileReader;i.onloadend=()=>o(i.result),i.onerror=()=>a(c("PDF_EXPORT_FAILED","Failed to convert to data URL")),i.readAsDataURL(r);})}async download(t,n,r){let o=await this.toBlob(t,r),a=URL.createObjectURL(o),i=document.createElement("a");i.href=a,i.download=n.endsWith(".pdf")?n:`${n}.pdf`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(a);}async downloadHTML(t,n,r){let o=xt();o.innerHTML=k(t),wt(o);try{await this.download(o,n,r);}finally{vt(o);}}};function ne(){return new at}function re(e,t){let n={...e};if(t)for(let r of Object.keys(t)){let o=t[r];o!==void 0&&(n[r]=o);}return n}var Qe={width:"90%",height:"85%",showToolbar:true,showPageNumbers:true,zoom:100,className:""},tn={print:true,download:true,zoom:true,navigation:true,close:true},N=[25,50,75,100,125,150,175,200],oe=25,ie=200,q=25,st=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={...j,...n},this.modalOptions=re(Qe,n?.modal),this.toolbarOptions=re(tn,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(){try{let t=v(this.target),n=F(t),r=g(n,this.options),o=h(r,this.options);await y(o,this.options);}catch(t){throw M(t,this.options),t}this.options.onPrint&&this.options.onPrint();}async download(t="document.pdf"){try{await ne().download(this.target,t,this.options);}catch(n){throw M(n,this.options),n}this.options.onDownload&&this.options.onDownload();}setZoom(t){this.zoomLevel=Math.max(oe,Math.min(ie,t)),this.updateZoom();}getZoom(){return this.zoomLevel}zoomIn(){let t=N.indexOf(this.zoomLevel);t<N.length-1?this.zoomLevel=N[t+1]??this.zoomLevel+q:this.zoomLevel=Math.min(ie,this.zoomLevel+q),this.updateZoom();}zoomOut(){let t=N.indexOf(this.zoomLevel);t>0?this.zoomLevel=N[t-1]??this.zoomLevel-q:this.zoomLevel=Math.max(oe,this.zoomLevel-q),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=`
|
|
427
|
-
position: fixed;
|
|
428
|
-
top: 0;
|
|
429
|
-
left: 0;
|
|
430
|
-
right: 0;
|
|
431
|
-
bottom: 0;
|
|
432
|
-
background: rgba(0, 0, 0, 0.75);
|
|
433
|
-
display: flex;
|
|
434
|
-
flex-direction: column;
|
|
435
|
-
align-items: center;
|
|
436
|
-
justify-content: center;
|
|
437
|
-
z-index: 999999;
|
|
438
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
439
|
-
`;let t=document.createElement("div");t.className="printkit-preview-container",t.style.cssText=`
|
|
440
|
-
width: ${typeof this.modalOptions.width=="number"?`${this.modalOptions.width}px`:this.modalOptions.width};
|
|
441
|
-
height: ${typeof this.modalOptions.height=="number"?`${this.modalOptions.height}px`:this.modalOptions.height};
|
|
442
|
-
display: flex;
|
|
443
|
-
flex-direction: column;
|
|
444
|
-
background: #f5f5f5;
|
|
445
|
-
border-radius: 8px;
|
|
446
|
-
overflow: hidden;
|
|
447
|
-
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
|
448
|
-
`,this.modalOptions.showToolbar&&t.appendChild(this.createToolbar()),this.contentContainer=document.createElement("div"),this.contentContainer.className="printkit-preview-content",this.contentContainer.style.cssText=`
|
|
449
|
-
flex: 1;
|
|
450
|
-
overflow: auto;
|
|
451
|
-
padding: 20px;
|
|
452
|
-
display: flex;
|
|
453
|
-
flex-direction: column;
|
|
454
|
-
align-items: center;
|
|
455
|
-
gap: 20px;
|
|
456
|
-
`,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=`
|
|
457
|
-
display: flex;
|
|
458
|
-
align-items: center;
|
|
459
|
-
justify-content: space-between;
|
|
460
|
-
padding: 12px 16px;
|
|
461
|
-
background: #fff;
|
|
462
|
-
border-bottom: 1px solid #e0e0e0;
|
|
463
|
-
`;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 o=document.createElement("div");if(o.style.cssText="display: flex; align-items: center; gap: 8px;",this.toolbarOptions.navigation){let a=this.createButton("< Prev",()=>this.prevPage()),i=this.createButton("Next >",()=>this.nextPage()),s=document.createElement("span");s.className="printkit-page-info",s.style.cssText="font-size: 14px; color: #666;",s.textContent=`Page ${this.currentPage} of ${this.totalPages}`,n.appendChild(a),n.appendChild(s),n.appendChild(i);}if(this.toolbarOptions.zoom){let a=this.createButton("-",()=>this.zoomOut()),i=document.createElement("span");i.className="printkit-zoom-level",i.style.cssText="font-size: 14px; min-width: 50px; text-align: center;",i.textContent=`${this.zoomLevel}%`;let s=this.createButton("+",()=>this.zoomIn()),l=this.createButton("Reset",()=>this.resetZoom());r.appendChild(a),r.appendChild(i),r.appendChild(s),r.appendChild(l);}if(this.toolbarOptions.print){let a=this.createButton("Print",()=>this.print().catch(()=>{}),true);o.appendChild(a);}if(this.toolbarOptions.download){let a=this.createButton("Download",()=>this.download().catch(()=>{}));o.appendChild(a);}if(this.toolbarOptions.close){let a=this.createButton("Close",()=>this.close());a.style.marginLeft="8px",o.appendChild(a);}return t.appendChild(n),t.appendChild(r),t.appendChild(o),t}createButton(t,n,r=false){let o=document.createElement("button");return o.textContent=t,o.onclick=n,o.style.cssText=`
|
|
464
|
-
padding: 6px 12px;
|
|
465
|
-
border: 1px solid ${r?"#0066cc":"#ccc"};
|
|
466
|
-
border-radius: 4px;
|
|
467
|
-
background: ${r?"#0066cc":"#fff"};
|
|
468
|
-
color: ${r?"#fff":"#333"};
|
|
469
|
-
font-size: 14px;
|
|
470
|
-
cursor: pointer;
|
|
471
|
-
transition: all 0.2s;
|
|
472
|
-
`,o.onmouseover=()=>{o.style.opacity="0.8";},o.onmouseout=()=>{o.style.opacity="1";},o}renderContent(){if(this.contentContainer)try{let t=v(this.target),n=S(this.options.pageSize??"A4",this.options.orientation??"portrait"),r=I(this.options.margin),o=document.createElement("div");o.className="printkit-page",o.style.cssText=`
|
|
473
|
-
width: ${n.width}px;
|
|
474
|
-
min-height: ${n.height}px;
|
|
475
|
-
background: white;
|
|
476
|
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
477
|
-
padding: ${r.top}px ${r.right}px ${r.bottom}px ${r.left}px;
|
|
478
|
-
box-sizing: border-box;
|
|
479
|
-
transform-origin: top center;
|
|
480
|
-
transform: scale(${this.zoomLevel/100});
|
|
481
|
-
`;for(let a of t){let i=Tt(a);o.appendChild(i);}this.contentContainer.appendChild(o);}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=S(this.options.pageSize??"A4",this.options.orientation??"portrait"),n=I(this.options.margin),r=t.height-n.top-n.bottom,o=this.contentContainer.querySelectorAll(".printkit-page"),a=0;o.forEach(i=>{a+=i.scrollHeight;}),this.totalPages=Math.max(1,Math.ceil(a/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=S(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 Xr(e,t){return new st(e,t)}export{fe as A,Z as B,En as C,Ln as D,On as E,U as F,Nt as G,be as H,An as I,Pe as J,Rt as K,Te as L,xe as M,_t as N,x as O,je as P,Or as Q,ne as R,Xr as S,P as a,ft as b,en as c,L as d,c as e,le as f,gt as g,k as h,Pt as i,me as j,Tt as k,R as l,Et as m,_ as n,S as o,z as p,I as q,X as r,St as s,Mt as t,gn as u,hn as v,yn as w,bn as x,Pn as y,kt as z};//# sourceMappingURL=chunk-YHD5OSS6.js.map
|
|
482
|
-
//# sourceMappingURL=chunk-YHD5OSS6.js.map
|