self.addEventListener("install",()=>{self.skipWaiting()}),self.addEventListener("activate",event=>{event.waitUntil(self.clients.claim())});var map=new Map;function createStream(port){return new ReadableStream({start(controller){port.onmessage=({data})=>{if("end"===data)return controller.close();"abort"===data?controller.error("Aborted the download"):controller.enqueue(data)}},cancel(reason){console.log("user aborted",reason),port.postMessage({abort:!0})}})}self.onmessage=event=>{var data,downloadUrl,port,metadata;"ping"!==event.data&&(downloadUrl=(data=event.data).url||self.registration.scope+Math.random()+"/"+("string"==typeof data?data:data.filename),port=event.ports[0],(metadata=new Array(3))[1]=data,metadata[2]=port,event.data.readableStream?metadata[0]=event.data.readableStream:event.data.transferringReadable?port.onmessage=evt=>{port.onmessage=null,metadata[0]=evt.data.readableStream}:metadata[0]=createStream(port),map.set(downloadUrl,metadata),port.postMessage({download:downloadUrl}))},self.onfetch=event=>{var url=event.request.url;if(url.endsWith("/ping"))return event.respondWith(new Response("pong"));var hijacke=map.get(url);if(!hijacke)return null;var[hijacke,data,port]=hijacke,url=(map.delete(url),new Headers({"Content-Type":"application/octet-stream; charset=utf-8","Content-Security-Policy":"default-src 'none'","X-Content-Security-Policy":"default-src 'none'","X-WebKit-CSP":"default-src 'none'","X-XSS-Protection":"1; mode=block"})),headers=new Headers(data.headers||{}),headers=(headers.has("Content-Length")&&url.set("Content-Length",headers.get("Content-Length")),headers.has("Content-Disposition")&&url.set("Content-Disposition",headers.get("Content-Disposition")),data.size&&(console.warn("Depricated"),url.set("Content-Length",data.size)),"string"==typeof data?data:data.filename);headers&&(console.warn("Depricated"),headers=encodeURIComponent(headers).replace(/['()]/g,escape).replace(/\*/g,"%2A"),url.set("Content-Disposition","attachment; filename*=UTF-8''"+headers)),event.respondWith(new Response(hijacke,{headers:url})),port.postMessage({debug:"Download started"})};