1import{J as K}from"./jszip.min-BDbxEQgs.js";import{saveResultFile as le}from"./ctResultAccessAd-Dk9whJZs.js";import{d as pe}from"./ctMediaProgressUi-wz6CtyvX.js";import{a as de,s as j,f as ue}from"./jszipArchiveProgress-1iM3A8_N.js";import{s as fe}from"./ctToast-C2BAo121.js";import"./_commonjsHelpers-BosuxZz1.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./FileSaver.min-BR20wtAe.js";import"./ctFullscreenAd-CL-AA_Ul.js";import"./app-gOHIPY12.js";const $="converted_file";function C(t){const n=document.getElementById("ctZipConvToast"),a=document.getElementById("ctZipConvToastBody");if(!n||!a){window.alert(t);return}fe(n,{bodyEl:a,message:t,delay:9e3})}const V=[{value:"zip",label:"ZIP (Most compatible)",type:"application/zip"},{value:"7z",label:"7Z (Best compression)",type:"application/x-7z-compressed"},{value:"rar",label:"RAR (Limited support)",type:"application/vnd.rar"},{value:"gz",label:"GZIP (Single file compression)",type:"application/gzip"},{value:"bz",label:"BZIP2 (Advanced compression)",type:"application/x-bzip"}];function me(t){let n=String(t||"").trim().replace(/[\\/:*?"<>|]+/g,"-").replace(/\s+/g,"_");return n=n.replace(/\.(zip|7z|rar|gz|bz2?)$/i,""),n||$}function Q(t){switch(String(t)){case"7z":return"7z";case"rar":return"rar";case"gz":return"gz";case"bz":return"bz";default:return"zip"}}function X(t){return!Number.isFinite(t)||t<0?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ve(t){const n=t.name.toLowerCase();return!!(n.endsWith(".zip")||t.type==="application/zip"||t.type==="application/x-zip-compressed"||n.endsWith(".gz")||n.endsWith(".gzip")||t.type==="application/gzip"||t.type==="application/x-gzip")}async function Y(t){if(ve(t))return!0;if(t.size<2)return!1;const n=new Uint8Array(await t.slice(0,4).arrayBuffer()),a=n[0]===80&&n[1]===75,u=n[0]===31&&n[1]===139;return a||u}async function ge(t){const n=new Uint8Array(t);if(n.length<2||n[0]!==31||n[1]!==139)return t;if(typeof DecompressionStream>"u")throw new Error("This browser cannot decompress gzip files.");const a=new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"));
1return await new Response(a).arrayBuffer()}function Ze(){if(!document.getElementById("ct-zip-converter-root"))return;const n=document.getElementById("ctZipConvDropWrap"),a=document.getElementById("ctZipConvFile"),u=document.getElementById("ctZipConvDrop"),z=document.getElementById("ctZipConvDropCaption"),f=document.getElementById("ctZipConvFmt"),s=document.getElementById("ctZipConvRun"),W=s==null?void 0:s.querySelector(".ct-zip-conv-btn-label"),_=s==null?void 0:s.querySelector(".ct-zip-conv-btn-spinner"),d=document.getElementById("ctZipConvReset"),D=document.getElementById("ctZipConvCount"),v=document.getElementById("ctZipConvReadyPanel"),Z=document.getElementById("ctZipConvEmpty"),h=document.getElementById("ctZipConvFileInfo"),c=document.getElementById("ctZipConvFilename"),M=document.getElementById("ctZipConvFilenameExt"),g=document.getElementById("ctZipConvProgressWrap"),i=pe({barId:"ctZipConvProgBar",labelId:"ctZipConvProgLabel",percentId:"ctZipConvProgPct",detailId:"ctZipConvProgDetail"});if(!n||!a||!u||!z||!f||!s)return;const G=55,ee=100;function te(){g&&(g.classList.add("is-active"),g.setAttribute("aria-hidden","false"))}function ne(){g&&(g.classList.remove("is-active"),g.setAttribute("aria-hidden","false")),i==null||i.hardReset("Ready")}let x=0,r=null;const J=z.textContent.trim();function U(){M&&(M.textContent=`.${Q(f.value)}`)}function I(){if(D){if(!r){D.textContent="No archive loaded";return}D.textContent=`${r.name} · ${X(r.size)}`}}function A(){const e=!!r;v==null||v.classList.toggle("d-none",!e),v==null||v.classList.toggle("d-flex",e),Z==null||Z.classList.toggle("d-none",e),e&&h&&r?h.textContent=`${r.name} (${X(r.size)})`:h&&(h.textContent="")}function F(){return!r&&(!c||c.value.trim()===$)}function w(){s.disabled=!r,d&&(d.disabled=F())}function S(){f.replaceChildren();const e=(r==null?void 0:r.type)||"",o=e?V.filter(l=>l.type!==e):V.slice();for(const l of o){const p=document.createElement("option");p.value=l.value,p.textContent=l.label,f.appendChild(p)}o.length&&(f.value=o[0].value),U()}function E(){return s.getAttribute("aria-busy")==="true"}function q(e){s.classList.toggle("is-loading",e),s.setAttribute("aria-busy",e?"true":"false"),W&&W.classList.toggle("invisible",e),_&&_.classList.toggle("d-none",!e),f.disabled=e,a.disabled=e,c&&(c.disabled=e),d&&(d.disabled=e||F()),e?s.disabled=!0:w()}function R(){r=null,a.value="",z.textContent=J,c&&(c.value=$),S(),I(),A(),w()}function H(e){r=e||null,z.textContent=r?r.name:J,S(),I(),A(),w()}a.addEventListener("change",async()=>{var o;if(E())return;const e=((o=a.files)==null?void 0:o[0])??null;if(!e){R();return}if(!await Y(e)){C("Choose a .zip file or a .gz file that wraps a ZIP archive (from Compress, etc.)."),a.value="";return}H(e)}),d==null||d.addEventListener("click",()=>{E()||R()}),f.addEventListener("change",()=>{U()}),c==null||c.addEventListener("input",()=>{d&&(d.disabled=F())}),n.addEventListener("click",e=>{if(E()){e.preventDefault(),e.stopPropagation();return}if(e.target!==a){if(Date.now()-x<600){e.preventDefault(),e.stopPropagation();return}a.click()}},!0),u.addEventListener("keydown",e=>{if(!(e.key!=="Enter"&&e.key!==" ")){if(E()){e.preventDefault();return}if(Date.now()-x<600){e.preventDefault();return}e.preventDefault(),a.click()}});async function ie(e){var p;if(e.preventDefault(),E())return;u.classList.remove("ct-zip-drop--active");const o=e.dataTransfer;if(!((p=o==null?void 0:o.files)!=null&&p.length))return;const l=o.files[0];if(!await Y(l)){C("Drop a .zip file or a .gz file that wraps a ZIP archive.");return}H(l)}let b=0;n.addEventListener("dragenter",e=>{e.preventDefault(),e.stopPropagation(),b+=1,u.classList.add("ct-zip-drop--active")}),n.addEventListener("dragover",e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy"),u.classList.add("ct-zip-drop--active")}),n.addEventListener("dragleave",e=>{e.preventDefault(),e.stopPropagation(),b=Math.max(0,b-1),b===0&&u.classList.remove("ct-zip-drop--active")}),n.addEventListener("drop",e=>{e.preventDefault(),e.stopPropagation(),b=0,x=Date.now(),ie(e)}),S(),I(),A(),w(),s.addEventListener("click",async()=>{const e=r;if(!e){C("Choose an archive first.");return}q(!0),te(),i==null||i.beginEncoding("Reading archiveâ¦");try{i==null||i.setEncoding(5,"Reading archiveâ¦");let o=await e.arrayBuffer();i==null||i.setEncoding(12,"Parsing archiveâ¦"),o=await ge(o);
1const l=await K.loadAsync(o),p=Object.keys(l.files);if(p.length===0){C("No files found in this archive.");return}const T=p.filter(m=>!l.files[m].dir),k=new K;let P=0;for(const m of p){const L=l.files[m];if(L.dir){k.folder(m);continue}const N=await L.async("arraybuffer",y=>{const B=typeof(y==null?void 0:y.percent)=="number"?y.percent:0,{label:O,detail:se,detailTitle:ce}=de(P,T.length,B,m,"Reading");i==null||i.setEncoding(j(12,G,(P+B/100)/Math.max(1,T.length)*100),O,void 0,se,ce)});k.file(m,N),P+=1}const oe=await k.generateAsync({type:"blob",compression:"DEFLATE",compressionOptions:{level:6}},m=>{const{pct:L,label:N,detail:y,detailTitle:B}=ue(m,{verb:"Packing",pathOrder:T.map(O=>String(O).replace(/\\/g,"/"))});i==null||i.setEncoding(j(G,ee,L),N,void 0,y,B)});i==null||i.setDone("Done â download started");const re=Q(f.value),ae=`${me(c==null?void 0:c.value)}.${re}`;le(oe,ae),R()}catch(o){i==null||i.setState({pct:0,labelText:"Conversion failed",phase:"error"}),C(o instanceof Error?o.message:"Conversion failed.")}finally{q(!1),ne()}})}export{Ze as initZipConverterPage};
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.