1import{f as S}from"./ctMediaConvertDownload-n0-64pPl.js";import{w as k,c as A}from"./ctPendingDownload-B21SXRKd.js";import{o as N,t as W,p as H,f as q,i as K,q as M,l as _}from"./mediaInputFromFilename-AaKRjYpC.js";import{c as G,e as J}from"./ctMediaProgressUi-wz6CtyvX.js";import{w as Q,c as V}from"./fileDropzone-CA_uaFcV.js";import{s as x}from"./mediaMetadataDisplay-rUX1VKD5.js";import{a as X}from"./mediaPreviewSource-BZTPxCO_.js";import"./ctFullscreenAd-CL-AA_Ul.js";import"./app-gOHIPY12.js";import"./transientNotice-Ds_di7lD.js";function E(t){const h=document.getElementById("ctImgToolsToastBody"),d=document.getElementById("ctImgToolsToast");if(!h||!d||typeof bootstrap>"u"){window.alert(t);return}h.textContent=t,bootstrap.Toast.getOrCreateInstance(d).show()}function Y(t){return!Number.isFinite(t)||t<0?"â":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(2)} MB`}function ce(){const t=document.getElementById("ct-image-tools-root");if(!t)return;const h=(t.dataset.ctFrom||"png").toLowerCase(),d=(t.dataset.ctTo||"jpeg").toLowerCase(),C=d==="jpg"?"jpeg":d,a=document.getElementById("ctImgToolsFile"),F=document.getElementById("ctImgToolsDrop"),U=document.getElementById("ctImgToolsDropCaption"),r=document.getElementById("ctImgToolsPreview"),m=document.getElementById("ctImgToolsPreviewPh"),B=document.getElementById("ctImgToolsName"),I=document.getElementById("ctImgToolsBtn"),b=document.getElementById("ctImgToolsDownload"),v=A();k(b,v);const w=document.getElementById("ctImgToolsClr"),T=document.getElementById("ctImgToolsMeta"),n=G({barId:"ctImgToolsProgBar",labelId:"ctImgToolsProgLabel",percentId:"ctImgToolsProgPct"});if(!a||!B||!I||!w)return;a.setAttribute("accept",N()),F&&Q({input:a,drop:F,dragContainer:F.closest(".card-body"),captionEl:U??void 0});let i=null,u=null,y=null,c=!1;const f=()=>{var e;I.disabled=!c||!((e=a.files)!=null&&e.length)},P=()=>{y&&(URL.revokeObjectURL(y),y=null),r&&(r.removeAttribute("src"),r.classList.add("d-none")),m==null||m.classList.remove("d-none"),x(T,null)};async function L(){return i&&!i.loaded&&(i=null,u=null,c=!1),i?(c=!0,i):(u||(c=!1,n(2,M(0)),f(),u=_({onProgress:e=>{const l=Math.min(98,Math.round(e*100));n(l,M(e))}}).then(e=>(i=e,c=!0,n.ui.hardReset("Ready to convert"),f(),e)).catch(e=>{throw i=null,u=null,c=!1,n.ui.hardReset("Ready to convert"),f(),e})),u)}a.addEventListener("change",()=>{var l;const e=(l=a.files)==null?void 0:l[0];if(P(),!e){n.ui.hardReset("Ready to convert"),w.disabled=!0,f();return}y=URL.createObjectURL(e),X(r,y),m==null||m.classList.add("d-none"),w.disabled=!1,L().catch(()=>{}),f()}),r==null||r.addEventListener("load",()=>{var p;const e=(p=a.files)==null?void 0:p[0];if(!e||!T||!r)return;const l=r.naturalWidth,s=r.naturalHeight,g={fileSize:Y(e.size)};l&&s&&(g.resolution=`${l}Ã${s}`),x(T,g)}),w.addEventListener("click",()=>{v.clear(),v.syncDownloadButton(b),c=!1,W(i),i=null,u=null,V(a),P(),B.value="converted",n.ui.hardReset("Ready to convert"),w.disabled=!0,f()}),I.addEventListener("click",async()=>{var R,D;const e=(R=a.files)==null?void 0:R[0];if(!e)return;if(e.size>50*1024*1024){E("File exceeds 50 MB.");return}const l=H(e.name,h);let s;try{s=await L()}catch(o){E(o instanceof Error?o.message:"Could not load the converter.");return}if(!s){E("Could not load the converter.");return}I.disabled=!0,n.beginEncoding("Convertingâ¦");const g=`input.${l}`,p=`output.${C}`;try{await s.writeFile(g,await q(e)),await J(s,["-y","-i",g,p],{phaseLo:5,phaseHi:90,labelForPercent:$=>$>0?`Converting⦠${$}%`:"Convertingâ¦",onProgress:n});const o=await s.readFile(p),j=o.buffer?o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength):o,z=new Blob([j],{type:`image/${C}`}),O=(B.value||"converted").replace(/[^\w\-]+/g,"_");await S(v,b,{blob:z,filename:`${O}.${d}`,progressUi:n.ui});try{await s.deleteFile(g),await s.deleteFile(p)}catch{}n.ui.setDone("Done â click Download")}catch(o){K(o)||E(o instanceof Error?o.message:"Conversion failed."),n.ui.hardReset("Ready to convert")}finally{I.disabled=!((D=a.files)!=null&&D.length)}})}export{ce as initImageToolsPage};
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.