1import{saveResultFile as Y}from"./ctResultAccessAd-Dk9whJZs.js";import{a as se,c as z}from"./fileDropzone-CA_uaFcV.js";import"./FileSaver.min-BR20wtAe.js";import"./_commonjsHelpers-BosuxZz1.js";import"./ctFullscreenAd-CL-AA_Ul.js";import"./app-gOHIPY12.js";import"./transientNotice-Ds_di7lD.js";const m={filename:"MergedImage",imageFormat:"jpeg",layout:"horizontal",bgColor:"#ffffff",gap:5,scaleImages:!1,imagesPerRow:3,remainingImagesLocation:"start",zoom:.2},O=8192,ee=3;function D(c){const e=document.getElementById("ctImgMergeToastBody"),v=document.getElementById("ctImgMergeToast");if(!e||!v||typeof bootstrap>"u"){window.alert(c);return}e.textContent=c,bootstrap.Toast.getOrCreateInstance(v).show()}function te(c,e,v,I){const h=Number(c);return Number.isFinite(h)?Math.min(Math.max(h,v),I):e}function me(c){return(c||"").trim().replace(/[\\/:*?"<>|]+/g,"-")||m.filename}function ce(c){const e=(c||"").toLowerCase();return e==="jpeg"?"image/jpeg":e==="webp"?"image/webp":"image/png"}function ne(c){const e=(c||"").toLowerCase();return e==="jpeg"?"jpg":e||"png"}function ge(c){var B;const[e,v]=c.split(","),I=((B=e.match(/data:([^;]+)/))==null?void 0:B[1])||"image/png",h=atob(v),C=h.length,p=new Uint8Array(C);for(let x=0;x<C;x+=1)p[x]=h.charCodeAt(x);return new Blob([p],{type:I})}function ue(c){return new Promise((e,v)=>{const I=new FileReader;I.onload=()=>e(String(I.result)),I.onerror=()=>v(new Error("read")),I.readAsDataURL(c)})}function ve(){var G,Z,X,q,K,V;const c=document.getElementById("ct-image-merger-root");if(!c)return;const e={uploadCard:document.getElementById("ctImgMergeUploadCard"),input:document.getElementById("ctImgMergeFiles"),drop:document.getElementById("ctImgMergeDrop"),caption:document.getElementById("ctImgMergeCaption"),layout:document.getElementById("ctImgMergeLayout"),gap:document.getElementById("ctImgMergeGap"),scale:document.getElementById("ctImgMergeScale"),perRow:document.getElementById("ctImgMergePerRow"),remainder:document.getElementById("ctImgMergeRemainder"),bg:document.getElementById("ctImgMergeBg"),previewWrap:document.getElementById("ctImgMergePreviewWrap"),busy:document.getElementById("ctImgMergeBusy"),dims:document.getElementById("ctImgMergeDims"),empty:document.getElementById("ctImgMergeEmpty"),frame:document.getElementById("ctImgMergePreviewFrame"),preview:document.getElementById("ctImgMergePreview"),zoomIn:document.getElementById("ctImgMergeZoomIn"),zoomOut:document.getElementById("ctImgMergeZoomOut"),clear:document.getElementById("ctImgMergeClear"),reset:document.getElementById("ctImgMergeReset"),format:document.getElementById("ctImgMergeFmt"),filename:document.getElementById("ctImgMergeFilename"),show:document.getElementById("ctImgMergeShow"),download:document.getElementById("ctImgMergeDownload"),canvas:document.getElementById("ctImgMergeCanvas")};if(!e.input||!e.drop||!e.canvas||!e.preview)return;const v=document.getElementById("ctImgMergeFilenameExt"),I=()=>{var t;v&&(v.textContent=`.${ne((t=e.format)==null?void 0:t.value)}`)};I();let h=[],C=[],p=m.zoom,B="",x=!1;const k=()=>C.slice(),U=()=>{var n;const t=((n=e.layout)==null?void 0:n.value)==="grid";c.querySelectorAll("[data-ct-img-grid-only]").forEach(a=>{a.classList.toggle("d-none",!t)})};function A(t){var n,a,r;x=t,(n=e.previewWrap)==null||n.setAttribute("aria-busy",t?"true":"false"),(a=e.previewWrap)==null||a.classList.toggle("ct-image-merger__preview--busy",t),(r=e.busy)==null||r.classList.toggle("d-none",!t),w()}const b=t=>{var n,a,r,i;B=t||"",B?(e.preview.src=B,e.preview.style.transform=`scale(${p})`,(n=e.empty)==null||n.classList.add("d-none"),(a=e.frame)==null||a.classList.remove("d-none")):(e.preview.removeAttribute("src"),(r=e.empty)==null||r.classList.remove("d-none"),(i=e.frame)==null||i.classList.add("d-none"))},w=()=>{const t=k().length>0,n=!!B,a=x;e.show&&(e.show.disabled=!t||a),e.download&&(e.download.disabled=!n||a),e.clear&&(e.clear.disabled=!t||a),e.reset&&(e.reset.disabled=!t&&!n||a),e.zoomOut&&(e.zoomOut.disabled=p<=m.zoom),e.zoomIn&&(e.zoomIn.disabled=p>=ee-1e-6)};function M(t,n,a){if(!e.dims)return;if(!t||!n){e.dims.classList.add("d-none"),e.dims.textContent="";return}let r=`Output size: ${Math.round(t)}Ã${Math.round(n)} px`;a<1-1e-6&&(r+=` · on-screen preview capped at ${O}px per side; download is full resolution`),e.dims.textContent=r,e.dims.classList.remove("d-none")}let j="";function ae(t){var L,R,W,E,F,P;const n=Math.max(...t.map(d=>d.width)),a=Math.max(...t.map(d=>d.height));(L=e.scale)!=null&&L.checked&&t.forEach(d=>{d.width=n,d.height=a});const r=((R=e.layout)==null?void 0:R.value)||m.layout,i=te((W=e.gap)==null?void 0:W.value,m.gap,0,1e3),l=Math.max(1,Math.floor(te((E=e.perRow)==null?void 0:E.value,m.imagesPerRow,1,50))),s=((F=e.remainder)==null?void 0:F.value)||m.remainingImagesLocation,g=((P=e.bg)==null?void 0:P.value)||m.bgColor;let u=0,y=0;if(r==="horizontal")u=t.reduce((d,f)=>d+f.width+i,-i),y=a;else if(r==="vertical")u=n,y=t.reduce((d,f)=>d+f.height+i,-i);else{const d=l,f=Math.ceil(t.length/d);u=d*(n+i)-i,y=f*(a+i)-i}return{maxWidth:n,maxHeight:a,totalWidth:u,totalHeight:y,layout:r,gap:i,imagesPerRow:l,remainingImagesLocation:s,bgColor:g}}function oe(t,n,a,r,i){const{totalWidth:l,totalHeight:s,layout:g,gap:u,imagesPerRow:y,remainingImagesLocation:L,bgColor:R,maxWidth:W}=r;t.width=Math.max(1,Math.ceil(l*i)),t.height=Math.max(1,Math.ceil(s*i)),n.setTransform(i,0,0,i,0,0),n.fillStyle=R,n.fillRect(0,0,l,s);let E=0,F=0,P=0;for(let d=0;d<a.length;d+=1){const f=a[d];if(g==="horizontal")n.drawImage(f,E,F,f.width,f.height),E+=f.width+u;else if(g==="vertical")n.drawImage(f,E,F,f.width,f.height),F+=f.height+u;else{if(P===0){const H=a.length-d,J=y-H;L==="center"&&H<y?E+=J/2*(W+u):L==="end"&&H<y&&(E+=J*(W+u))}n.drawImage(f,E,F,f.width,f.height),E+=f.width+u,P+=1,(P===y||d===a.length-1)&&(E=0,F+=f.height+u,P=0)}}n.setTransform(1,0,0,1,0,0)}function N(){var n;const t=(((n=e.format)==null?void 0:n.value)||m.imageFormat).toLowerCase();return t==="jpeg"?e.canvas.toDataURL("image/jpeg"):t==="webp"?e.canvas.toDataURL("image/webp"):e.canvas.toDataURL("image/png")}function $(t){const n=e.canvas,a=n.getContext("2d");if(!a)return Promise.reject(new Error("context"));const r=h.map(i=>{const l=new Image;return l.src=i,l});return Promise.all(r.map(i=>new Promise(l=>{i.onload=()=>l(i),i.onerror=()=>l(null)}))).then(i=>{const l=i.filter(u=>u!==null);if(l.length===0)return{ok:!1,totalWidth:0,totalHeight:0,previewScale:1};const s=ae(l),g=t??Math.min(1,O/s.totalWidth,O/s.totalHeight);if(t==null&&g<1-1e-6){const u=`${Math.round(s.totalWidth)}Ã${Math.round(s.totalHeight)}`;j!==u&&(j=u,D(`This merge is very large (${Math.round(s.totalWidth)}Ã${Math.round(s.totalHeight)} px). The preview is scaled to fit your screen; download still uses full pixel size.`))}return oe(n,a,l,s,g),{ok:!0,totalWidth:s.totalWidth,totalHeight:s.totalHeight,previewScale:g}})}function ie(){return $(null).then(t=>{t.ok&&(b(N()),M(t.totalWidth,t.totalHeight,t.previewScale))})}const S=()=>
1{if(h.length===0){b(""),M(0,0,1),w();return}A(!0),$(null).then(t=>{if(!t.ok){b(""),M(0,0,1);return}b(N()),M(t.totalWidth,t.totalHeight,t.previewScale)}).catch(()=>{b(""),M(0,0,1)}).finally(()=>{A(!1),w()})},Q=()=>{U(),h.length>0&&S(),w()},_=()=>{const t=k();if(t.length===0){h=[],b(""),M(0,0,1),w();return}Promise.all(t.map(ue)).then(n=>{h=n,S()}).catch(()=>{D("Could not read one of the files."),h=[],b(""),M(0,0,1),w()})},T=()=>{if(!e.caption)return;const t=k().length;t===0?e.caption.textContent=e.drop.getAttribute("data-ct-placeholder")||"Drop images here or click to browse":t===1?e.caption.textContent=k()[0].name:e.caption.textContent=`${t} images selected`},re=()=>{var t;C=[],(t=o==null?void 0:o.setQueue)==null||t.call(o,[]),z(e.input),h=[],b(""),e.layout&&(e.layout.value=m.layout),e.gap&&(e.gap.value=String(m.gap)),e.scale&&(e.scale.checked=m.scaleImages),e.perRow&&(e.perRow.value=String(m.imagesPerRow)),e.remainder&&(e.remainder.value=m.remainingImagesLocation),e.bg&&(e.bg.value=m.bgColor),e.format&&(e.format.value=m.imageFormat),e.filename&&(e.filename.value=m.filename),I(),p=m.zoom,e.preview.style.transform=`scale(${p})`,T(),U(),M(0,0,1),w()},le=()=>{var t;C=[],(t=o==null?void 0:o.setQueue)==null||t.call(o,[]),z(e.input),h=[],b(""),T(),M(0,0,1),w()},o=se({input:e.input,drop:e.drop,dragContainer:e.uploadCard||null,captionEl:e.caption,accumulate:!0,onInvalidFile:D,onChange:()=>{var t;C=((t=o==null?void 0:o.getQueue)==null?void 0:t.call(o))||Array.from(e.input.files||[]),T(),_(),w()}});document.addEventListener("paste",t=>{var l,s,g,u;if(!c.isConnected)return;const n=document.activeElement;if(n instanceof Element&&n!==document.body&&!c.contains(n)||n instanceof HTMLInputElement&&n.type!=="file"||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement)return;const a=(l=t.clipboardData)==null?void 0:l.items;if(!(a!=null&&a.length))return;const r=[];for(let y=0;y<a.length;y+=1){const L=a[y];if(L.kind==="file"&&L.type.startsWith("image/")){const R=L.getAsFile();R&&r.push(R)}}if(!r.length)return;t.preventDefault();const i=((s=o==null?void 0:o.getQueue)==null?void 0:s.call(o))||[];(g=o==null?void 0:o.setQueue)==null||g.call(o,[...i,...r]),C=((u=o==null?void 0:o.getQueue)==null?void 0:u.call(o))||[],T(),_(),w()}),[e.layout,e.gap,e.scale,e.perRow,e.remainder,e.bg,e.format].forEach(t=>{t==null||t.addEventListener("change",()=>{t===e.format&&I(),Q()}),t==null||t.addEventListener("input",Q)}),(G=e.show)==null||G.addEventListener("click",()=>{h.length!==0&&S()}),(Z=e.download)==null||Z.addEventListener("click",()=>{var r,i;if(h.length===0||!B)return;const t=(((r=e.format)==null?void 0:r.value)||m.imageFormat).toLowerCase(),n=ce(t),a=`${me((i=e.filename)==null?void 0:i.value)}.${ne(t)}`;A(!0),$(1).then(l=>!l.ok||!l.totalWidth?(D("Nothing to download."),Promise.resolve()):new Promise(s=>{try{e.canvas.toBlob(g=>{if(!g){D("Could not create the file."),s();return}Y(g,a),s()},n)}catch{let g;t==="jpeg"?g=e.canvas.toDataURL("image/jpeg"):t==="webp"?g=e.canvas.toDataURL("image/webp"):g=e.canvas.toDataURL("image/png"),Y(ge(g),a),s()}})).catch(()=>{D("Export failed. The merged image may be too large for this browser.")}).then(()=>ie()).finally(()=>{A(!1),w()})}),(X=e.clear)==null||X.addEventListener("click",le),(q=e.reset)==null||q.addEventListener("click",re),(K=e.zoomIn)==null||K.addEventListener("click",()=>{p=Math.min(ee,Number((p+.1).toFixed(2))),e.preview.style.transform=`scale(${p})`,w()}),(V=e.zoomOut)==null||V.addEventListener("click",()=>{p>m.zoom&&(p=Number((p-.1).toFixed(2)),e.preview.style.transform=`scale(${p})`),w()}),U(),T(),M(0,0,1),w()}export{ve as initImageMergerPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.