const ZipUtils=function(){"use strict";const e=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)n=1&n?3988292384^n>>>1:n>>>1;e[t]=n}return e})();function t(e,t){const n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=e>>8*r&255;return n}function n(...e){const t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}class r{constructor(){this.files=[],this.offset=0}async addFile(r,o){let s;if(o instanceof Blob){const e=await o.arrayBuffer();s=new Uint8Array(e)}else s=o instanceof ArrayBuffer?new Uint8Array(o):o;const i=(c=r,(new TextEncoder).encode(c));var c;const a=function(t){let n=4294967295;for(let r=0;r<t.length;r++)n=e[255&(n^t[r])]^n>>>8;return(4294967295^n)>>>0}(s),l=s.length,f=n(new Uint8Array([80,75,3,4]),t(20,2),t(0,2),t(0,2),t(0,2),t(0,2),t(a,4),t(l,4),t(l,4),t(i.length,2),t(0,2),i);this.files.push({filename:i,crc:a,size:l,offset:this.offset,localHeader:f,data:s}),this.offset+=f.length+s.length}generate(){const e=[];for(const t of this.files)e.push(t.localHeader),e.push(t.data);const r=this.offset;let o=0;for(const r of this.files){const s=n(new Uint8Array([80,75,1,2]),t(20,2),t(20,2),t(0,2),t(0,2),t(0,2),t(0,2),t(r.crc,4),t(r.size,4),t(r.size,4),t(r.filename.length,2),t(0,2),t(0,2),t(0,2),t(0,2),t(0,4),t(r.offset,4),r.filename);e.push(s),o+=s.length}const s=n(new Uint8Array([80,75,5,6]),t(0,2),t(0,2),t(this.files.length,2),t(this.files.length,2),t(o,4),t(r,4),t(0,2));return e.push(s),new Blob(e,{type:"application/zip"})}}async function o(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch: ${t.status}`);const n=await t.arrayBuffer();return new Uint8Array(n)}return{ZipWriter:r,fetchFile:o,createAndDownloadZip:async function(e,t,n){const s=new r;for(let t=0;t<e.length;t++){const r=e[t];n&&n(t+1,e.length,r.name);try{const e=await o(r.url);await s.addFile(r.name,e)}catch(e){}}const i=s.generate(),c=URL.createObjectURL(i),a=document.createElement("a");a.href=c,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(c)}}}();"undefined"!=typeof module&&module.exports&&(module.exports=ZipUtils);