!function(){"use strict";window.dropPrint=window.dropPrint||{},window.dropPrint.dropPrintCreateOptimizedPreview=function(t,e){const i=new Image;let n=null;const r=window.dropPrint?.elements?.dropPrintImagePreview;if(!r)return console.warn("DropPrint Preview: Preview element cache missing (elements.dropPrintImagePreview)."),void e(null);r.classList.remove("visible"),r.src="";try{n=URL.createObjectURL(t),i.onload=function(){const t=document.createElement("canvas"),r=t.getContext("2d"),o=window.dropPrint?.config?.MAX_PREVIEW_DIMENSION||800,a=this.naturalWidth||this.width,l=this.naturalHeight||this.height;if(a<=0||l<=0)return console.error("DropPrint Preview Error: Invalid image dimensions detected (<= 0)."),e(null),void(n&&(URL.revokeObjectURL(n),n=null));const s=Math.min(1,o/Math.max(a,l));t.width=Math.round(a*s),t.height=Math.round(l*s),r.drawImage(i,0,0,t.width,t.height);const d=t.toDataURL("image/jpeg",.85);e(d),n&&(URL.revokeObjectURL(n),n=null)},i.onerror=function(){console.error("DropPrint Preview Error: Failed to load image object for preview generation."),e(null),n&&(URL.revokeObjectURL(n),n=null)},i.src=n}catch(t){if(console.error("DropPrint Preview Error: Exception during preview generation setup.",t),e(null),n)try{URL.revokeObjectURL(n)}catch(t){}}},window.dropPrint.dropPrintCreateDimensionPlaceholder=function(t,e){const i=window.dropPrint?.elements?.dropPrintImagePreview;if(!i)return void console.warn("DropPrint Warning: Preview element cache missing, cannot display placeholder.");if(i.classList.remove("visible"),i.src="",i.alt="Preview",!t||!e||t<=0||e<=0)return console.warn("DropPrint Warning: Invalid dimensions provided for placeholder, displaying generic message."),i.src='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300" viewBox="0 0 400 300"><rect width="100%" height="100%" fill="%23f0f0f0"/><text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-family="sans-serif" font-size="14" fill="%23999">Preview not available</text></svg>',i.style.display="block",void(i.alt="Preview not available");const n=Math.min(1,400/Math.max(t,e)),r=`data:image/svg+xml;utf8,${`\n\t\t\t<svg xmlns="http://www.w3.org/2000/svg"\n\t\t\t\t width="${Math.round(t*n)}" height="${Math.round(e*n)}"\n\t\t\t\t viewBox="0 0 ${t} ${e}"\n\t\t\t\t preserveAspectRatio="xMidYMid meet"\n\t\t\t\t style="background-color: #f0f0f0; max-width: 100%; height: auto;">\n\t\t\t\t<rect width="100%" height="100%" fill="#f0f0f0"/>\n\t\t\t\t<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle"\n\t\t\t\t\t  font-family="sans-serif" font-size="${Math.max(10,.05*Math.min(t,e))}px" fill="#999">\n\t\t\t\t\t${t} x ${e} px\n\t\t\t\t</text>\n\t\t\t</svg>`.replace(/\s\s+/g," ").replace(/#/g,"%23").replace(/</g,"%3C").replace(/>/g,"%3E")}`;i.src=r,i.alt=`Placeholder for ${t}x${e} image`,i.style.display="block"}}(jQuery);