@helia/verified-fetch 7.0.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/url-resolver.d.ts.map +1 -1
- package/dist/src/url-resolver.js +19 -14
- package/dist/src/url-resolver.js.map +1 -1
- package/package.json +1 -1
- package/src/url-resolver.ts +18 -16
package/dist/index.min.js
CHANGED
|
@@ -107,7 +107,7 @@ a=ice-pwd:`+e+t)}catch{}return r}var W5=E("libp2p-webrtc-noise:");function KC(r,
|
|
|
107
107
|
`)),r.linkname!=null&&(e+=I7(" linkpath="+r.linkname+`
|
|
108
108
|
`));let t=r.pax;if(t!=null)for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=I7(" "+n+"="+t[n]+`
|
|
109
109
|
`));return E(e)}function t3(r){let e=new Uint8Array(512),t=r.name,n="";if(r.typeflag===5&&t[t.length-1]!=="/"&&(t+="/"),E(t).byteLength!==t.length)return null;for(;E(t).byteLength>100;){let o=t.indexOf("/");if(o===-1)return null;n+=n!==""?"/"+t.slice(0,o):t.slice(0,o),t=t.slice(o+1)}return E(t).byteLength>100||E(n).byteLength>155||r.linkname!=null&&E(r.linkname).byteLength>100?null:(e.set(E(t),0),e.set(ss(r.mode&Iz,6),100),e.set(ss(r.uid,6),108),e.set(ss(r.gid,6),116),e.set(ss(r.size,11),124),e.set(ss(r.mtime.getTime()/1e3|0,11),136),e[156]=Tz+Pz(r.type),r.linkname!=null&&e.set(E(r.linkname),157),e.set(_z,kz),e.set(Cz,Rz),r.uname!=null&&e.set(E(r.uname),265),r.gname!=null&&e.set(E(r.gname),297),e.set(ss(r.devmajor??0,6),329),e.set(ss(r.devminor??0,6),337),n!=null&&e.set(E(n),345),e.set(ss(Dz(e),6),148),e)}var{S_IFMT:Nz,S_IFBLK:Oz,S_IFCHR:Bz,S_IFDIR:Mz,S_IFIFO:Uz,S_IFLNK:Fz}=vk.default,$z=parseInt("755",8),Hz=parseInt("644",8),Sk=new Uint8Array(1024);function qz(r=0){switch(r&Nz){case Oz:return"block-device";case Bz:return"character-device";case Mz:return"directory";case Uz:return"fifo";case Fz:return"symlink";default:return"file"}}function R7(r){return r&=511,r!==0?Sk.subarray(0,512-r):new Uint8Array(0)}function k7(r){if(r.pax==null){let e=t3(r);if(e!=null)return e}return Vz(r)}function Vz(r){let e=Ek(r),t={name:"PaxHeader",mode:r.mode,uid:r.uid,gid:r.gid,size:e.length,mtime:r.mtime,type:"pax-header",linkname:r.linkname,uname:r.uname,gname:r.gname,devmajor:r.devmajor,devminor:r.devminor};return new j(t3(t)??new Uint8Array(0),e,R7(e.length),t3({...t,size:r.size,type:r.type})??new Uint8Array(0)).subarray()}function r3(){return async function*(r){for await(let{header:e,body:t}of r){let n={...e,size:e.type==="symlink"?0:e.size??0,type:e.type??qz(e.mode),mode:e.mode??(e.type==="directory"?$z:Hz),uid:e.uid??0,gid:e.gid??0,mtime:e.mtime??new Date};if(typeof t=="string"&&(t=E(t)),t instanceof Uint8Array||hn(t)){n.size=t.length,yield k7(n),yield hn(t)?t.subarray():t,yield R7(n.size);continue}if(n.type==="symlink"&&n.linkname==null){if(t==null)throw new Error("type was symlink but no linkname or body specified");n.linkname=R(await de(t)),yield k7(n);continue}if(yield k7(n),n.type!=="file"&&n.type!=="contiguous-file")continue;let o=0;for await(let i of t??[])o+=i.length,yield hn(i)?i.subarray():i;if(o!==n.size)throw new Error(`size mismatch, wrote ${o} of ${n.size} bytes`);yield R7(n.size)}yield Sk}}var Kz=["file","raw","directory"];function zz(r,e){let t,n,o=0n;return(r.type==="file"||r.type==="raw"||r.type==="identity")&&(o=r.size),(r.type==="file"||r.type==="directory")&&(t=r.unixfs.mode,n=r.unixfs.mtime!=null?new Date(Number(r.unixfs.mtime.secs*1000n)):void 0),{name:e,mode:t,mtime:n,size:Number(o),type:r.type==="directory"?"directory":"file"}}function Ak(r,e){if(!Kz.includes(r.type))throw new Aa(`${r.type} is not a UnixFS node`);let t={header:zz(r,e)};return(r.type==="file"||r.type==="raw")&&(t.body=r.content()),t}async function*Tk(r,e,t){let n=await Al(ns(r,e,t));if(n==null)throw new S(`Could not walk path "${r}"`);let o=await Cn(n.cid,e,t);if(o.type==="file"||o.type==="raw"){yield*zr([Ak(o,n.path)],r3());return}if(o.type==="directory"){yield*zr(ik(o.cid,e,t),i=>Et(i,async s=>{let a=await Cn(s.cid,e,t);return Ak(a,s.path)}),r3());return}throw new Aa("Not a UnixFS node")}var n3=class extends ur{id="tar-plugin";codes=[];canHandle({accept:e}){return e.some(t=>t.contentType.mediaType===Tl)}async handle(e){let{terminalElement:t,url:n,resource:o,options:i,blockstore:s,range:a}=e;if(t.cid.code!==Ke&&t.cid.code!==Ce)return Br(o,new Aa("Only UnixFS data can be returned in a TAR file"));if(a!=null)return Br(o,new Error("Range requests are not supported for TAR files"));let c=Sn(Tk(`/ipfs/${t.cid}${n.pathname}`,s,i));return fn(o,c,{redirected:e.redirected,headers:{"content-type":Tl,"content-disposition":`attachment; ${Nr(n.searchParams.get("filename")??`${t.cid.toString()}.tar`)}`,"accept-ranges":"none"}})}};function Gz(r,e){let t;try{t=new URL(r.toString())}catch{t=e}if(!t.pathname.endsWith("/"))return t.pathname+="/",t.toString()}var o3=class extends ur{id="unixfs-plugin";codes=[Ke,Ce];canHandle({terminalElement:e,accept:t}){let n=this.codes.includes(e.cid.code),o=t.length===0||t.some(i=>i.contentType.mediaType===$t||i.contentType.mediaType===kf);return n&&o}async handle(e){let{url:t,resource:n,terminalElement:o,ipfsRoots:i,blockstore:s}=e,a=t.searchParams.get("filename")??o.name,c=e.redirected,l;try{l=await Cn(o.cid,s,e.options)}catch(u){if(e?.options?.signal?.throwIfAborted(),u.name==="BlockNotFoundWhileOfflineError")throw u;return this.log.error("could not export %c - %e",o.cid,u),Sa(n,"Unable to stream content")}if(l.type==="directory"){let u=Gz(n,t);if(u!=null){if(this.log.trace("directory url normalization spec requires redirect"),e.options?.redirect==="error")throw this.log('could not redirect to %s as redirect option was set to "error"',u),new TypeError("Failed to fetch");if(e.options?.redirect==="manual")return this.log("returning 301 permanent redirect to %s",u),gk(e.resource,u);this.log("following redirect to %s",u),n=u,c=!0}let d=o.cid;if(e.options?.supportDirectoryIndexes!==!1){let h="index.html";try{this.log.trace("found directory at %c%s, looking for index.html",d,t.pathname);let p=await e.serverTiming.time("exporter-dir","",Al(ns(`/ipfs/${d}/${h}`,e.blockstore,e.options)));if(p==null)return Sa(n,"Unable to stream content");let g=await e.serverTiming.time("exporter-dir","",Cn(p.cid,e.blockstore,e.options));return g.type!=="file"&&g.type!=="raw"&&g.type!=="identity"?Sa(n,"Unable to stream content"):(a=h,this.log.trace("found directory index at %c%s with cid %c",d,h,l.cid),await this.streamFile(n,g,a,i,c,e.range,e.options))}catch(p){if(p.name!=="NotFoundError")throw this.log.error("error loading path %c/%s - %e",d,h,p),p}}let f=await de(e.blockstore.get(d,e.options));return fn(n,f,{headers:{"content-type":kf,"content-length":`${f.byteLength}`,"content-disposition":`${t.searchParams.get("download")==="true"?"attachment":"inline"}; ${Nr(`${d}.dir`)}`,"x-ipfs-roots":i.map(h=>h.toV1()).join(","),"accept-ranges":"bytes"},redirected:c})}else return l.type==="file"||l.type==="raw"||l.type==="identity"?(this.log("streaming file"),this.streamFile(n,l,a,i,c,e.range,e.options)):(this.log.error("cannot stream terminal element type %s",l.type),Sa(n,"Unable to stream content"))}async streamFile(e,t,n,o,i,s,a){let c=$t;return s==null&&(c=await this.detectContentType(t,n,a)),s!=null?_l(e,(l,u)=>t.content({...a??{},offset:l,length:u}),s,t.size,{headers:{"content-type":c,"content-disposition":`inline; ${Nr(n)}`,"x-ipfs-roots":o.map(l=>l.toV1()).join(","),"accept-ranges":"bytes"},redirected:i}):fn(e,Sn(t.content(a)),{headers:{"content-type":c,"content-length":`${t.size}`,"content-disposition":`inline; ${Nr(n)}`,"x-ipfs-roots":o.map(l=>l.toV1()).join(","),"accept-ranges":"bytes"},redirected:i})}async detectContentType(e,t,n){let o;if(e.type==="raw"||e.type==="identity"?o=e.node:o=await L1(e.content(n)),o==null)throw new Error("stream ended before first block was read");let i;if(this.pluginOptions.contentTypeParser!=null)try{let s=this.pluginOptions.contentTypeParser(o,t);if(uc(s)){let a=await s;a!=null&&(i=a)}else s!=null&&(i=s);this.log.trace("contentTypeParser returned %s for file with name %s",i,t)}catch(s){this.log.error("error parsing content type - %e",s)}return i??$t}};var Pf=class extends Map{#t=0;#e=new Map;#r=new Map;#o;#s;#a;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=e.maxSize,this.#s=e.maxAge||Number.POSITIVE_INFINITY,this.#a=e.onEviction}get __oldCache(){return this.#r}#l(e){if(typeof this.#a=="function")for(let[t,n]of e)this.#a(t,n.value)}#n(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#a=="function"&&this.#a(e,t.value),this.delete(e)):!1}#m(e,t){if(this.#n(e,t)===!1)return t.value}#h(e,t){return t.expiry?this.#m(e,t):t.value}#p(e,t){let n=t.get(e);return this.#h(e,n)}#u(e,t){this.#e.set(e,t),this.#t++,this.#t>=this.#o&&(this.#t=0,this.#l(this.#r),this.#r=this.#e,this.#e=new Map)}#d(e,t){this.#r.delete(e),this.#u(e,t)}*#i(){for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield e)}for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#h(e,t)}if(this.#r.has(e)){let t=this.#r.get(e);if(this.#n(e,t)===!1)return this.#d(e,t),t.value}}set(e,t,{maxAge:n=this.#s}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#u(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#n(e,this.#e.get(e)):this.#r.has(e)?!this.#n(e,this.#r.get(e)):!1}peek(e){if(this.#e.has(e))return this.#p(e,this.#e);if(this.#r.has(e))return this.#p(e,this.#r)}expiresIn(e){let t=this.#e.get(e)??this.#r.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){let t=this.#e.delete(e);return t&&this.#t--,this.#r.delete(e)||t}clear(){this.#e.clear(),this.#r.clear(),this.#t=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#i()],n=t.length-e;n<0?(this.#e=new Map(t),this.#r=new Map,this.#t=t.length):(n>0&&this.#l(t.slice(0,n)),this.#r=new Map(t.slice(n)),this.#e=new Map,this.#t=0),this.#o=e}evict(e=1){let t=Number(e);if(!t||t<=0)return;let n=[...this.#i()],o=Math.trunc(Math.min(t,Math.max(n.length-1,0)));o<=0||(this.#l(n.slice(0,o)),this.#r=new Map(n.slice(o)),this.#e=new Map,this.#t=0)}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield[t,n.value])}for(let e of this.#r){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield[t,n.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#n(o,i)===!1&&(yield[o,i.value])}e=[...this.#r];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,i]=n;this.#e.has(o)||this.#n(o,i)===!1&&(yield[o,i.value])}}*entriesAscending(){for(let[e,t]of this.#i())yield[e,t.value]}get size(){if(!this.#t)return this.#r.size;let e=0;for(let t of this.#r.keys())this.#e.has(t)||e++;return Math.min(this.#t+e,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#s}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[n,o]of this.entriesAscending())e.call(t,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var ND=qt(PD(),1);var UY=[200,301,302,303,307,308,404,410,451],DD=65536;function OD(r,e,t={}){try{if(e.length>DD)throw new Vg(`_redirects file size cannot exceed ${DD} bytes`);let n=e.split(`
|
|
110
|
-
`).filter(o=>(o=o.trim(),o!==""&&!o.startsWith("#"))).map(o=>{let[i,s,a]=o.split(/\s+/).map(f=>f.trim());if(a!=null&&a!==""&&!a.match(/^\d+$/))throw new Kg("Invalid status code in _redirects file");let c=parseInt(a);if(isNaN(c)&&(c=301),!UY.includes(c))throw new zg(`Status code ${c} is not allowed`);let l=new Set,u=i.split("/"),d=u.map((f,h)=>{if(f.startsWith(":")){let p=f.substring(1);if(l.has(p))throw new Gg("Duplicate placeholders in from path");return l.add(p),`(?<${p}>[^/]+)`}return f==="*"&&h===u.length-1?"(?<splat>.+)":(0,ND.default)(f)}).join("\\/");return{from:new RegExp(d),to:s,status:c}});for(let{from:o,to:i,status:s}of n){let a=r.pathname.match(o);if(a!=null)return FY(r,i,s,a.groups,t)}}catch(n){return new Response(JSON.stringify(va(n),null,2),{status:500})}}function FY(r,e,t,n,o={}){if(o.redirect==="error")throw new TypeError("Failed to fetch");if(n!=null)for(let[c,l]of Object.entries(n))e=e.replaceAll(`:${c}`,l);let i=$Y(r,new URL(`${r.protocol}//${r.host}${e}`)),s=new URL(`${r.protocol}//${r.host}${e}`),a=new URL(`${r.protocol}//${r.host}${s.pathname}${HY(i)}${r.hash}`);return o.redirect==="manual"?new Response("",{status:t,headers:{location:a.toString()}}):a}function $Y(r,e){let t={};for(let[n,o]of r.searchParams)e.searchParams.delete(n),LD(n,o,t);for(let[n,o]of e.searchParams)LD(n,o,t);return t}function LD(r,e,t){typeof t[r]=="string"&&(t[r]=[t[r]]),Array.isArray(t[r])?t[r].push(e):t[r]=e}function HY(r){let e=[...Object.entries(r)].map(([t,n])=>(Array.isArray(n)||(n=[n]),n.map(o=>`${encodeURIComponent(t)}=${encodeURIComponent(o)}`).join("&"))).join("&");return e===""?e:`?${e}`}var Bl=class{headers;constructor(){this.headers=[]}getHeader(){return this.headers.join(",")}async time(e,t,n){let o=performance.now();try{return await n}finally{let s=(performance.now()-o).toFixed(1);this.headers.push(`${e};dur=${s};desc="${t}"`)}}};var qY=29030400;function VY(r){return{cid:r,name:r.toString(),path:r.toString(),roots:[r],remainder:[]}}var S3=class{log;components;blockstoreSessions;constructor(e,t={}){this.components=e,this.log=e.helia.logger.forComponent("helia-verified-fetch:url-resolver"),this.blockstoreSessions=new Pf({maxSize:t.sessionCacheSize??100,maxAge:t.sessionTTLms??6e4,onEviction:(n,o)=>{o.close()}})}async resolve(e,t=new Bl,n={}){if(e.protocol==="ipfs:")return this.resolveIPFSPath(e,t,n);if(e.protocol==="ipns:")return this.resolveIPNSName(e,t,n);if(e.protocol==="dnslink:")return this.resolveDNSLink(e,t,n);throw new Tn(`Invalid resource. Unsupported protocol in URL, must be ipfs:, ipns:, or dnslink: ${e}`)}async getBlockstore(e,t={}){if(t.session===!1)return this.components.helia.blockstore;let n=`ipfs:${e}`,o=this.blockstoreSessions.get(n),i=!1;if(o==null&&(this.log("create session with %d initial providers for root %c",t.providers?.length??0,e),i=!0,o=this.components.helia.blockstore.createSession(e,t),this.blockstoreSessions.set(n,o)),!i&&t.providers!=null&&t.providers.length>0){this.log("adding %d providers to existing session for root %c",t.providers.length,e);try{let s=await Promise.all(t.providers.map(async a=>{await o.addPeer(a,t)})??[]);this.log("result was %o",s)}catch(s){this.log.error("could not add provs - %e",s)}}return o}async resolveDNSLink(e,t,n){let i=(await t.time("dnsLink.resolve",`Resolve DNSLink ${e.hostname}`,this.components.dnsLink.resolve(e.hostname,n)))?.[0];if(i==null)throw new TypeError(`Invalid resource. Cannot resolve DNSLink from domain: ${e.hostname}`);if(i.namespace==="ipns")return this.resolveIPNSName(e,t,n);if(i.namespace!=="ipfs")throw new TypeError(`Invalid resource. Unexpected DNSLink namespace ${i.namespace} from domain: ${domain}`);i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`),a=await this.resolveIPFSPath(s,t,n);return a instanceof Response?a:{...a,url:e,ttl:i.answer.TTL}}async resolveIPNSName(e,t,n){let o=xe(e.hostname),i=await t.time("ipns.resolve",`Resolve IPNS name ${o}`,this.components.ipnsResolver.resolve(o,n));i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`),a=await this.resolveIPFSPath(s,t,n);return a instanceof Response?a:{...a,url:e,ttl:Number((i.record.ttl??0n)/BigInt(1e9))}}async resolveIPFSPath(e,t,n){let o=await t.time("ipfs.resolve","",this.walkPath(e,n));return o instanceof Response?o:{...o,url:e,ttl:qY,blockstore:o.blockstore}}async walkPath(e,t={}){let n;try{n=F.parse(e.hostname)}catch(i){throw new Tn(`Could not parse CID - ${i}`)}let o=await this.getBlockstore(n,t);try{let i=[],s,a=KY(e);for await(let c of ns(a,o,{...t,yieldSubShards:!0}))i.push(c.cid),s=c;if(s==null)throw new e3("No terminal element found");return{ipfsRoots:i,terminalElement:s,blockstore:o,redirected:t.redirected===!0}}catch(i){if(i.name==="NotFoundError"&&t.redirected!==!0){let s;try{s=await Cn(`${n}/_redirects`,o,t)}catch(a){if(a.name!=="NotFoundError")throw a}if(s?.type==="file"||s?.type==="raw"){let a=R(await de(s.content(t))),c=OD(e,a,t);if(c instanceof Response)return c;if(c instanceof URL)return this.walkPath(c,{...t,redirected:!0})}}if(i.name==="NoResolverError")return{ipfsRoots:[n],terminalElement:VY(n),blockstore:o,redirected:!1};throw i}}};function KY(r){return`/ipfs/${r.hostname}${decodeURI(r.pathname)}`}var FD=qt(BD(),1);var MD={128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"},zY={};for(let[r,e]of Object.entries(MD))zY[e]=Number.parseInt(r,10);var A3;function GY(){if(!(typeof globalThis.TextDecoder>"u"))return A3??(A3=new globalThis.TextDecoder("utf-8"))}var _a=32*1024;function UD(r,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":{let t=GY();return t?t.decode(r):WY(r)}case"utf-16le":return YY(r);case"us-ascii":case"ascii":return jY(r);case"latin1":case"iso-8859-1":return XY(r);case"windows-1252":return QY(r);default:throw new RangeError(`Encoding '${e}' not supported`)}}function WY(r){let e=[],t="",n=0;for(;n<r.length;){let o=r[n++];if(o<128)t+=String.fromCharCode(o);else if(o<224){let i=r[n++]&63;t+=String.fromCharCode((o&31)<<6|i)}else if(o<240){let i=r[n++]&63,s=r[n++]&63;t+=String.fromCharCode((o&15)<<12|i<<6|s)}else{let i=r[n++]&63,s=r[n++]&63,a=r[n++]&63,c=(o&7)<<18|i<<12|s<<6|a;c-=65536,t+=String.fromCharCode(55296+(c>>10&1023),56320+(c&1023))}t.length>=_a&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function YY(r){let e=r.length&-2;if(e===0)return"";let t=[],n=_a;for(let o=0;o<e;){let i=Math.min(n,e-o>>1),s=new Array(i);for(let a=0;a<i;a++,o+=2)s[a]=r[o]|r[o+1]<<8;t.push(String.fromCharCode.apply(null,s))}return t.join("")}function jY(r){let e=[];for(let t=0;t<r.length;t+=_a){let n=Math.min(r.length,t+_a),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i]&127;e.push(String.fromCharCode.apply(null,o))}return e.join("")}function XY(r){let e=[];for(let t=0;t<r.length;t+=_a){let n=Math.min(r.length,t+_a),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i];e.push(String.fromCharCode.apply(null,o))}return e.join("")}function QY(r){let e=[],t="";for(let n=0;n<r.length;n++){let o=r[n],i=o>=128&&o<=159?MD[o]:void 0;t+=i??String.fromCharCode(o),t.length>=_a&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function Mr(r){return new DataView(r.buffer,r.byteOffset)}var $D={len:1,get(r,e){return Mr(r).getUint8(e)},put(r,e,t){return Mr(r).setUint8(e,t),e+1}},at={len:2,get(r,e){return Mr(r).getUint16(e,!0)},put(r,e,t){return Mr(r).setUint16(e,t,!0),e+2}},Ca={len:2,get(r,e){return Mr(r).getUint16(e)},put(r,e,t){return Mr(r).setUint16(e,t),e+2}};var gt={len:4,get(r,e){return Mr(r).getUint32(e,!0)},put(r,e,t){return Mr(r).setUint32(e,t,!0),e+4}},mw={len:4,get(r,e){return Mr(r).getUint32(e)},put(r,e,t){return Mr(r).setUint32(e,t),e+4}};var HD={len:4,get(r,e){return Mr(r).getInt32(e)},put(r,e,t){return Mr(r).setInt32(e,t),e+4}};var qD={len:8,get(r,e){return Mr(r).getBigUint64(e,!0)},put(r,e,t){return Mr(r).setBigUint64(e,t,!0),e+8}};var Ur=class{constructor(e,t){this.len=e,this.encoding=t}get(e,t=0){let n=e.subarray(t,t+this.len);return UD(n,this.encoding)}};var JY="End-Of-Stream",Je=class extends Error{constructor(){super(JY),this.name="EndOfStreamError"}},Ia=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ka=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,t=!1){let n=await this.read(e,t);return this.peekQueue.push(e.subarray(0,n)),n}async read(e,t=!1){if(e.length===0)return 0;let n=this.readFromPeekBuffer(e);if(this.endOfStream||(n+=await this.readRemainderFromStream(e.subarray(n),t)),n===0&&!t)throw new Je;return n}readFromPeekBuffer(e){let t=e.length,n=0;for(;this.peekQueue.length>0&&t>0;){let o=this.peekQueue.pop();if(!o)throw new Error("peekData should be defined");let i=Math.min(o.length,t);e.set(o.subarray(0,i),n),n+=i,t-=i,i<o.length&&this.peekQueue.push(o.subarray(i))}return n}async readRemainderFromStream(e,t){let n=0;for(;n<e.length&&!this.endOfStream;){if(this.interrupted)throw new Ia;let o=await this.readFromStream(e.subarray(n),t);if(o===0)break;n+=o}if(!t&&n<e.length)throw new Je;return n}};var T3=class extends ka{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}};var Ff=class extends T3{async readFromStream(e,t){if(e.length===0)return 0;let n=await this.reader.read(new Uint8Array(e.length),{min:t?void 0:e.length});return n.done&&(this.endOfStream=n.done),n.value?(e.set(n.value),n.value.length):0}};var Ml=class extends ka{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,t){let n=Math.min(t.length,e.length);return e.set(t.subarray(0,n)),n<t.length?this.buffer=t.subarray(n):this.buffer=null,n}async readFromStream(e,t){if(e.length===0)return 0;let n=0;for(this.buffer&&(n+=this.writeChunk(e,this.buffer));n<e.length&&!this.endOfStream;){let o=await this.reader.read();if(o.done){this.endOfStream=!0;break}o.value&&(n+=this.writeChunk(e.subarray(n),o.value))}if(!t&&n===0&&this.endOfStream)throw new Je;return n}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}};function gw(r){try{let e=r.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new Ml(e):new Ff(e)}catch(e){if(e instanceof TypeError)return new Ml(r.getReader());throw e}}var hi=class{constructor(e){this.numBuffer=new Uint8Array(8),this.position=0,this.onClose=e?.onClose,e?.abortSignal&&e.abortSignal.addEventListener("abort",()=>{this.abort()})}async readToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.readBuffer(n,{position:t})<e.len)throw new Je;return e.get(n,0)}async peekToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.peekBuffer(n,{position:t})<e.len)throw new Je;return e.get(n,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new Je;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new Je;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let t=this.fileInfo.size-this.position;if(e>t)return this.position+=t,t}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,t){if(!this.supportsRandomAccess()&&t&&t.position!==void 0&&t.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");return{mayBeLess:!1,offset:0,length:e.length,position:this.position,...t}}abort(){return Promise.resolve()}};var tj=256e3,_3=class extends hi{constructor(e,t){super(t),this.streamReader=e,this.fileInfo=t?.fileInfo??{}}async readBuffer(e,t){let n=this.normalizeOptions(e,t),o=n.position-this.position;if(o>0)return await this.ignore(o),this.readBuffer(e,t);if(o<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(n.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,n.length),n.mayBeLess);if(this.position+=i,(!t||!t.mayBeLess)&&i<n.length)throw new Je;return i}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=0;if(n.position){let i=n.position-this.position;if(i>0){let s=new Uint8Array(n.length+i);return o=await this.peekBuffer(s,{mayBeLess:n.mayBeLess}),e.set(s.subarray(i)),o-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(n.length>0){try{o=await this.streamReader.peek(e.subarray(0,n.length),n.mayBeLess)}catch(i){if(t?.mayBeLess&&i instanceof Je)return 0;throw i}if(!n.mayBeLess&&o<n.length)throw new Je}return o}async ignore(e){let t=Math.min(tj,e),n=new Uint8Array(t),o=0;for(;o<e;){let i=e-o,s=await this.readBuffer(n,{length:Math.min(t,i)});if(s<0)return s;o+=s}return o}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}};var C3=class extends hi{constructor(e,t){super(t),this.uint8Array=e,this.fileInfo={...t?.fileInfo??{},size:e.length}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.uint8Array.length-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new Je;return e.set(this.uint8Array.subarray(n.position,n.position+o)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};var I3=class extends hi{constructor(e,t){super(t),this.blob=e,this.fileInfo={...t?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.blob.size-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new Je;let i=await this.blob.slice(n.position,n.position+o).arrayBuffer();return e.set(new Uint8Array(i)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};function VD(r,e){let t=gw(r),n=e??{},o=n.onClose;return n.onClose=async()=>{if(await t.close(),o)return o()},new _3(t,n)}function KD(r,e){return new C3(r,e)}function zD(r,e){return new I3(r,e)}var eL=qt(XD(),1);var Pa={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},yw={get(r){return{signature:gt.get(r,0),compressedSize:gt.get(r,8),uncompressedSize:gt.get(r,12)}},len:16},QD={get(r){let e=at.get(r,6);return{signature:gt.get(r,0),minVersion:at.get(r,4),dataDescriptor:!!(e&8),compressedMethod:at.get(r,8),compressedSize:gt.get(r,18),uncompressedSize:gt.get(r,22),filenameLength:at.get(r,26),extraFieldLength:at.get(r,28),filename:null}},len:30},ZD={get(r){return{signature:gt.get(r,0),nrOfThisDisk:at.get(r,4),nrOfThisDiskWithTheStart:at.get(r,6),nrOfEntriesOnThisDisk:at.get(r,8),nrOfEntriesOfSize:at.get(r,10),sizeOfCd:gt.get(r,12),offsetOfStartOfCd:gt.get(r,16),zipFileCommentLength:at.get(r,20)}},len:22},JD={get(r){let e=at.get(r,8);return{signature:gt.get(r,0),minVersion:at.get(r,6),dataDescriptor:!!(e&8),compressedMethod:at.get(r,10),compressedSize:gt.get(r,20),uncompressedSize:gt.get(r,24),filenameLength:at.get(r,28),extraFieldLength:at.get(r,30),fileCommentLength:at.get(r,32),relativeOffsetOfLocalHeader:gt.get(r,42),filename:null}},len:46};function tL(r){let e=new Uint8Array(gt.len);return gt.put(e,0,r),e}var To=(0,eL.default)("tokenizer:inflate"),ww=256*1024,mj=tL(Pa.DataDescriptor),P3=tL(Pa.EndOfCentralDirectory),$f=class r{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(ww)}async isZip(){return await this.peekSignature()===Pa.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(gt)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,t=Math.min(16*1024,e.fileInfo.size),n=this.syncBuffer.subarray(0,t);await this.tokenizer.readBuffer(n,{position:e.fileInfo.size-t});for(let o=n.length-4;o>=0;o--)if(n[o]===P3[0]&&n[o+1]===P3[1]&&n[o+2]===P3[2]&&n[o+3]===P3[3])return e.fileInfo.size-t+o;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){To("Cannot reading central-directory without random-read support");return}To("Reading central-directory...");let e=this.tokenizer.position,t=await this.findEndOfCentralDirectoryLocator();if(t>0){To("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(ZD,t),o=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let s=await this.tokenizer.readToken(JD);if(s.signature!==Pa.CentralFileHeader)throw new Error("Expected Central-File-Header signature");s.filename=await this.tokenizer.readToken(new Ur(s.filenameLength,"utf-8")),await this.tokenizer.ignore(s.extraFieldLength),await this.tokenizer.ignore(s.fileCommentLength),o.push(s),To(`Add central-directory file-entry: n=${i+1}/${o.length}: filename=${o[i].filename}`)}return this.tokenizer.setPosition(e),o}this.tokenizer.setPosition(e)}async unzip(e){let t=await this.readCentralDirectory();if(t)return this.iterateOverCentralDirectory(t,e);let n=!1;do{let o=await this.readLocalFileHeader();if(!o)break;let i=e(o);n=!!i.stop;let s;if(await this.tokenizer.ignore(o.extraFieldLength),o.dataDescriptor&&o.compressedSize===0){let a=[],c=ww;To("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let l=-1;for(;l<0&&c===ww;){c=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),l=gj(this.syncBuffer.subarray(0,c),mj);let u=l>=0?l:c;if(i.handler){let d=new Uint8Array(u);await this.tokenizer.readBuffer(d),a.push(d)}else await this.tokenizer.ignore(u)}To(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(o,yj(a),i.handler)}else i.handler?(To(`Reading compressed-file-data: ${o.compressedSize} bytes`),s=new Uint8Array(o.compressedSize),await this.tokenizer.readBuffer(s),await this.inflate(o,s,i.handler)):(To(`Ignoring compressed-file-data: ${o.compressedSize} bytes`),await this.tokenizer.ignore(o.compressedSize));if(To(`Reading data-descriptor at pos=${this.tokenizer.position}`),o.dataDescriptor&&(await this.tokenizer.readToken(yw)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-yw.len}`)}while(!n)}async iterateOverCentralDirectory(e,t){for(let n of e){let o=t(n);if(o.handler){this.tokenizer.setPosition(n.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let s=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(s),await this.inflate(i,s,o.handler)}}if(o.stop)break}}async inflate(e,t,n){if(e.compressedMethod===0)return n(t);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);To(`Decompress filename=${e.filename}, compressed-size=${t.length}`);let o=await r.decompressDeflateRaw(t);return n(o)}static async decompressDeflateRaw(e){let t=new ReadableStream({start(i){i.enqueue(e),i.close()}}),n=new DecompressionStream("deflate-raw"),o=t.pipeThrough(n);try{let s=await new Response(o).arrayBuffer();return new Uint8Array(s)}catch(i){let s=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(s)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(gt);if(e===Pa.LocalFileHeader){let t=await this.tokenizer.readToken(QD);return t.filename=await this.tokenizer.readToken(new Ur(t.filenameLength,"utf-8")),t}if(e===Pa.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}};function gj(r,e){let t=r.length,n=e.length;if(n>t)return-1;for(let o=0;o<=t-n;o++){let i=!0;for(let s=0;s<n;s++)if(r[o+s]!==e[s]){i=!1;break}if(i)return o}return-1}function yj(r){let e=r.reduce((o,i)=>o+i.length,0),t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Hf=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(t){let n=new Uint8Array(1024),o=await e.readBuffer(n,{mayBeLess:!0});if(o===0){t.close();return}t.enqueue(n.subarray(0,o))}}).pipeThrough(new DecompressionStream("gzip"))}};var RBe={utf8:new globalThis.TextDecoder("utf8")};var PBe=new globalThis.TextEncoder;var DBe=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function bw(r){let{byteLength:e}=r;if(e===6)return r.getUint16(0)*2**32+r.getUint32(2);if(e===5)return r.getUint8(0)*2**32+r.getUint32(1);if(e===4)return r.getUint32(0);if(e===3)return r.getUint8(0)*2**16+r.getUint16(1);if(e===2)return r.getUint16(0);if(e===1)return r.getUint8(0)}function rL(r,e){if(e==="utf-16le"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o&255,o>>8&255)}return t}if(e==="utf-16be"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o>>8&255,o&255)}return t}return[...r].map(t=>t.charCodeAt(0))}function nL(r,e=0){let t=Number.parseInt(new Ur(6).get(r,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(t))return!1;let n=256;for(let o=e;o<e+148;o++)n+=r[o];for(let o=e+156;o<e+512;o++)n+=r[o];return t===n}var oL={get:(r,e)=>r[e+3]&127|r[e+2]<<7|r[e+1]<<14|r[e]<<21,len:4};var iL=["jpg","png","apng","gif","webp","flif","xcf","cr2","cr3","orf","arw","dng","nef","rw2","raf","tif","bmp","icns","jxr","psd","indd","zip","tar","rar","gz","bz2","7z","dmg","mp4","mid","mkv","webm","mov","avi","mpg","mp2","mp3","m4a","oga","ogg","ogv","opus","flac","wav","spx","amr","pdf","epub","elf","macho","exe","swf","rtf","wasm","woff","woff2","eot","ttf","otf","ttc","ico","flv","ps","xz","sqlite","nes","crx","xpi","cab","deb","ar","rpm","Z","lz","cfb","mxf","mts","blend","bpg","docx","pptx","xlsx","3gp","3g2","j2c","jp2","jpm","jpx","mj2","aif","qcp","odt","ods","odp","xml","mobi","heic","cur","ktx","ape","wv","dcm","ics","glb","pcap","dsf","lnk","alias","voc","ac3","m4v","m4p","m4b","f4v","f4p","f4b","f4a","mie","asf","ogm","ogx","mpc","arrow","shp","aac","mp1","it","s3m","xm","skp","avif","eps","lzh","pgp","asar","stl","chm","3mf","zst","jxl","vcf","jls","pst","dwg","parquet","class","arj","cpio","ace","avro","icc","fbx","vsdx","vtt","apk","drc","lz4","potx","xltx","dotx","xltm","ott","ots","otp","odg","otg","xlsm","docm","dotm","potm","pptm","jar","jmp","rm","sav","ppsm","ppsx","tar.gz","reg","dat"],sL=["image/jpeg","image/png","image/gif","image/webp","image/flif","image/x-xcf","image/x-canon-cr2","image/x-canon-cr3","image/tiff","image/bmp","image/vnd.ms-photo","image/vnd.adobe.photoshop","application/x-indesign","application/epub+zip","application/x-xpinstall","application/vnd.ms-powerpoint.slideshow.macroenabled.12","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.slideshow","application/zip","application/x-tar","application/x-rar-compressed","application/gzip","application/x-bzip2","application/x-7z-compressed","application/x-apple-diskimage","application/vnd.apache.arrow.file","video/mp4","audio/midi","video/matroska","video/webm","video/quicktime","video/vnd.avi","audio/wav","audio/qcelp","audio/x-ms-asf","video/x-ms-asf","application/vnd.ms-asf","video/mpeg","video/3gpp","audio/mpeg","audio/mp4","video/ogg","audio/ogg","audio/ogg; codecs=opus","application/ogg","audio/flac","audio/ape","audio/wavpack","audio/amr","application/pdf","application/x-elf","application/x-mach-binary","application/x-msdownload","application/x-shockwave-flash","application/rtf","application/wasm","font/woff","font/woff2","application/vnd.ms-fontobject","font/ttf","font/otf","font/collection","image/x-icon","video/x-flv","application/postscript","application/eps","application/x-xz","application/x-sqlite3","application/x-nintendo-nes-rom","application/x-google-chrome-extension","application/vnd.ms-cab-compressed","application/x-deb","application/x-unix-archive","application/x-rpm","application/x-compress","application/x-lzip","application/x-cfb","application/x-mie","application/mxf","video/mp2t","application/x-blender","image/bpg","image/j2c","image/jp2","image/jpx","image/jpm","image/mj2","audio/aiff","application/xml","application/x-mobipocket-ebook","image/heif","image/heif-sequence","image/heic","image/heic-sequence","image/icns","image/ktx","application/dicom","audio/x-musepack","text/calendar","text/vcard","text/vtt","model/gltf-binary","application/vnd.tcpdump.pcap","audio/x-dsf","application/x.ms.shortcut","application/x.apple.alias","audio/x-voc","audio/vnd.dolby.dd-raw","audio/x-m4a","image/apng","image/x-olympus-orf","image/x-sony-arw","image/x-adobe-dng","image/x-nikon-nef","image/x-panasonic-rw2","image/x-fujifilm-raf","video/x-m4v","video/3gpp2","application/x-esri-shape","audio/aac","audio/x-it","audio/x-s3m","audio/x-xm","video/MP1S","video/MP2P","application/vnd.sketchup.skp","image/avif","application/x-lzh-compressed","application/pgp-encrypted","application/x-asar","model/stl","application/vnd.ms-htmlhelp","model/3mf","image/jxl","application/zstd","image/jls","application/vnd.ms-outlook","image/vnd.dwg","application/vnd.apache.parquet","application/java-vm","application/x-arj","application/x-cpio","application/x-ace-compressed","application/avro","application/vnd.iccprofile","application/x.autodesk.fbx","application/vnd.visio","application/vnd.android.package-archive","application/vnd.google.draco","application/x-lz4","application/vnd.openxmlformats-officedocument.presentationml.template","application/vnd.openxmlformats-officedocument.spreadsheetml.template","application/vnd.openxmlformats-officedocument.wordprocessingml.template","application/vnd.ms-excel.template.macroenabled.12","application/vnd.oasis.opendocument.text-template","application/vnd.oasis.opendocument.spreadsheet-template","application/vnd.oasis.opendocument.presentation-template","application/vnd.oasis.opendocument.graphics","application/vnd.oasis.opendocument.graphics-template","application/vnd.ms-excel.sheet.macroenabled.12","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-word.template.macroenabled.12","application/vnd.ms-powerpoint.template.macroenabled.12","application/vnd.ms-powerpoint.presentation.macroenabled.12","application/java-archive","application/vnd.rn-realmedia","application/x-spss-sav","application/x-ms-regedit","application/x-ft-windows-registry-hive","application/x-jmp-data"];var xw=4100;async function aL(r,e){return new vw(e).fromBuffer(r)}function Ew(r){switch(r=r.toLowerCase(),r){case"application/epub+zip":return{ext:"epub",mime:r};case"application/vnd.oasis.opendocument.text":return{ext:"odt",mime:r};case"application/vnd.oasis.opendocument.text-template":return{ext:"ott",mime:r};case"application/vnd.oasis.opendocument.spreadsheet":return{ext:"ods",mime:r};case"application/vnd.oasis.opendocument.spreadsheet-template":return{ext:"ots",mime:r};case"application/vnd.oasis.opendocument.presentation":return{ext:"odp",mime:r};case"application/vnd.oasis.opendocument.presentation-template":return{ext:"otp",mime:r};case"application/vnd.oasis.opendocument.graphics":return{ext:"odg",mime:r};case"application/vnd.oasis.opendocument.graphics-template":return{ext:"otg",mime:r};case"application/vnd.openxmlformats-officedocument.presentationml.slideshow":return{ext:"ppsx",mime:r};case"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return{ext:"xlsx",mime:r};case"application/vnd.ms-excel.sheet.macroenabled":return{ext:"xlsm",mime:"application/vnd.ms-excel.sheet.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.spreadsheetml.template":return{ext:"xltx",mime:r};case"application/vnd.ms-excel.template.macroenabled":return{ext:"xltm",mime:"application/vnd.ms-excel.template.macroenabled.12"};case"application/vnd.ms-powerpoint.slideshow.macroenabled":return{ext:"ppsm",mime:"application/vnd.ms-powerpoint.slideshow.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return{ext:"docx",mime:r};case"application/vnd.ms-word.document.macroenabled":return{ext:"docm",mime:"application/vnd.ms-word.document.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.template":return{ext:"dotx",mime:r};case"application/vnd.ms-word.template.macroenabledtemplate":return{ext:"dotm",mime:"application/vnd.ms-word.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.template":return{ext:"potx",mime:r};case"application/vnd.ms-powerpoint.template.macroenabled":return{ext:"potm",mime:"application/vnd.ms-powerpoint.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.presentation":return{ext:"pptx",mime:r};case"application/vnd.ms-powerpoint.presentation.macroenabled":return{ext:"pptm",mime:"application/vnd.ms-powerpoint.presentation.macroenabled.12"};case"application/vnd.ms-visio.drawing":return{ext:"vsdx",mime:"application/vnd.visio"};case"application/vnd.ms-package.3dmanufacturing-3dmodel+xml":return{ext:"3mf",mime:"model/3mf"};default:}}function _o(r,e,t){t={offset:0,...t};for(let[n,o]of e.entries())if(t.mask){if(o!==(t.mask[n]&r[n+t.offset]))return!1}else if(o!==r[n+t.offset])return!1;return!0}var vw=class{constructor(e){this.options={mpegOffsetTolerance:0,...e},this.detectors=[...e?.customDetectors??[],{id:"core",detect:this.detectConfident},{id:"core.imprecise",detect:this.detectImprecise}],this.tokenizerOptions={abortSignal:e?.signal}}async fromTokenizer(e){let t=e.position;for(let n of this.detectors){let o=await n.detect(e);if(o)return o;if(t!==e.position)return}}async fromBuffer(e){if(!(e instanceof Uint8Array||e instanceof ArrayBuffer))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof e}\``);let t=e instanceof Uint8Array?e:new Uint8Array(e);if(t?.length>1)return this.fromTokenizer(KD(t,this.tokenizerOptions))}async fromBlob(e){let t=zD(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async fromStream(e){let t=VD(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async toDetectionStream(e,t){let{sampleSize:n=xw}=t,o,i,s=e.getReader({mode:"byob"});try{let{value:l,done:u}=await s.read(new Uint8Array(n));if(i=l,!u&&l)try{o=await this.fromBuffer(l.subarray(0,n))}catch(d){if(!(d instanceof Je))throw d;o=void 0}i=l}finally{s.releaseLock()}let a=new TransformStream({async start(l){l.enqueue(i)},transform(l,u){u.enqueue(l)}}),c=e.pipeThrough(a);return c.fileType=o,c}check(e,t){return _o(this.buffer,e,t)}checkString(e,t){return this.check(rL(e,t?.encoding),t)}detectConfident=async e=>{if(this.buffer=new Uint8Array(xw),e.fileInfo.size===void 0&&(e.fileInfo.size=Number.MAX_SAFE_INTEGER),this.tokenizer=e,await e.peekBuffer(this.buffer,{length:32,mayBeLess:!0}),this.check([66,77]))return{ext:"bmp",mime:"image/bmp"};if(this.check([11,119]))return{ext:"ac3",mime:"audio/vnd.dolby.dd-raw"};if(this.check([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(this.check([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if(this.check([37,33]))return await e.peekBuffer(this.buffer,{length:24,mayBeLess:!0}),this.checkString("PS-Adobe-",{offset:2})&&this.checkString(" EPSF-",{offset:14})?{ext:"eps",mime:"application/eps"}:{ext:"ps",mime:"application/postscript"};if(this.check([31,160])||this.check([31,157]))return{ext:"Z",mime:"application/x-compress"};if(this.check([199,113]))return{ext:"cpio",mime:"application/x-cpio"};if(this.check([96,234]))return{ext:"arj",mime:"application/x-arj"};if(this.check([239,187,191]))return this.tokenizer.ignore(3),this.detectConfident(e);if(this.check([71,73,70]))return{ext:"gif",mime:"image/gif"};if(this.check([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(this.check([31,139,8])){let n=new Hf(e).inflate(),o=!0;try{let i;try{i=await this.fromStream(n)}catch{o=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{o&&await n.cancel()}return{ext:"gz",mime:"application/gzip"}}if(this.check([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(this.checkString("ID3")){await e.ignore(6);let t=await e.readToken(oL);return e.position+t>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(t),this.fromTokenizer(e))}if(this.checkString("MP+"))return{ext:"mpc",mime:"audio/x-musepack"};if((this.buffer[0]===67||this.buffer[0]===70)&&this.check([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(this.check([255,216,255]))return this.check([247],{offset:3})?{ext:"jls",mime:"image/jls"}:{ext:"jpg",mime:"image/jpeg"};if(this.check([79,98,106,1]))return{ext:"avro",mime:"application/avro"};if(this.checkString("FLIF"))return{ext:"flif",mime:"image/flif"};if(this.checkString("8BPS"))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(this.checkString("MPCK"))return{ext:"mpc",mime:"audio/x-musepack"};if(this.checkString("FORM"))return{ext:"aif",mime:"audio/aiff"};if(this.checkString("icns",{offset:0}))return{ext:"icns",mime:"image/icns"};if(this.check([80,75,3,4])){let t;return await new $f(e).unzip(n=>{switch(n.filename){case"META-INF/mozilla.rsa":return t={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return t={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(o){let i=new TextDecoder("utf-8").decode(o).trim();t=Ew(i)},stop:!0};case"[Content_Types].xml":return{async handler(o){let i=new TextDecoder("utf-8").decode(o),s=i.indexOf('.main+xml"');if(s===-1){let a="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${a}"`)&&(t=Ew(a))}else{i=i.slice(0,Math.max(0,s));let a=i.lastIndexOf('"'),c=i.slice(Math.max(0,a+1));t=Ew(c)}},stop:!0};default:return/classes\d*\.dex/.test(n.filename)?(t={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(n=>{if(!(n instanceof Je))throw n}),t??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let t=new Uint8Array(8);return await e.readBuffer(t),_o(t,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:_o(t,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:_o(t,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:_o(t,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:_o(t,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:_o(t,[1,118,111,114,98,105,115])?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"}}if(this.check([80,75])&&(this.buffer[2]===3||this.buffer[2]===5||this.buffer[2]===7)&&(this.buffer[3]===4||this.buffer[3]===6||this.buffer[3]===8))return{ext:"zip",mime:"application/zip"};if(this.checkString("MThd"))return{ext:"mid",mime:"audio/midi"};if(this.checkString("wOFF")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff",mime:"font/woff"};if(this.checkString("wOF2")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(this.check([212,195,178,161])||this.check([161,178,195,212]))return{ext:"pcap",mime:"application/vnd.tcpdump.pcap"};if(this.checkString("DSD "))return{ext:"dsf",mime:"audio/x-dsf"};if(this.checkString("LZIP"))return{ext:"lz",mime:"application/x-lzip"};if(this.checkString("fLaC"))return{ext:"flac",mime:"audio/flac"};if(this.check([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(this.checkString("wvpk"))return{ext:"wv",mime:"audio/wavpack"};if(this.checkString("%PDF"))return{ext:"pdf",mime:"application/pdf"};if(this.check([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(this.check([73,73])){let t=await this.readTiffHeader(!1);if(t)return t}if(this.check([77,77])){let t=await this.readTiffHeader(!0);if(t)return t}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function t(){let a=await e.peekNumber($D),c=128,l=0;for(;(a&c)===0&&c!==0;)++l,c>>=1;let u=new Uint8Array(l+1);return await e.readBuffer(u),u}async function n(){let a=await t(),c=await t();c[0]^=128>>c.length-1;let l=Math.min(6,c.length),u=new DataView(a.buffer),d=new DataView(c.buffer,c.length-l,l);return{id:bw(u),len:bw(d)}}async function o(a){for(;a>0;){let c=await n();if(c.id===17026)return(await e.readToken(new Ur(c.len))).replaceAll(/\00.*$/g,"");await e.ignore(c.len),--a}}let i=await n();switch(await o(i.len)){case"webm":return{ext:"webm",mime:"video/webm"};case"matroska":return{ext:"mkv",mime:"video/matroska"};default:return}}if(this.checkString("SQLi"))return{ext:"sqlite",mime:"application/x-sqlite3"};if(this.check([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(this.checkString("Cr24"))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(this.checkString("MSCF")||this.checkString("ISc("))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(this.check([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(this.check([197,208,211,198]))return{ext:"eps",mime:"application/eps"};if(this.check([40,181,47,253]))return{ext:"zst",mime:"application/zstd"};if(this.check([127,69,76,70]))return{ext:"elf",mime:"application/x-elf"};if(this.check([33,66,68,78]))return{ext:"pst",mime:"application/vnd.ms-outlook"};if(this.checkString("PAR1")||this.checkString("PARE"))return{ext:"parquet",mime:"application/vnd.apache.parquet"};if(this.checkString("ttcf"))return{ext:"ttc",mime:"font/collection"};if(this.check([254,237,250,206])||this.check([254,237,250,207])||this.check([206,250,237,254])||this.check([207,250,237,254]))return{ext:"macho",mime:"application/x-mach-binary"};if(this.check([4,34,77,24]))return{ext:"lz4",mime:"application/x-lz4"};if(this.checkString("regf"))return{ext:"dat",mime:"application/x-ft-windows-registry-hive"};if(this.checkString("$FL2")||this.checkString("$FL3"))return{ext:"sav",mime:"application/x-spss-sav"};if(this.check([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(this.checkString("#!AMR"))return{ext:"amr",mime:"audio/amr"};if(this.checkString("{\\rtf"))return{ext:"rtf",mime:"application/rtf"};if(this.check([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(this.checkString("IMPM"))return{ext:"it",mime:"audio/x-it"};if(this.checkString("-lh0-",{offset:2})||this.checkString("-lh1-",{offset:2})||this.checkString("-lh2-",{offset:2})||this.checkString("-lh3-",{offset:2})||this.checkString("-lh4-",{offset:2})||this.checkString("-lh5-",{offset:2})||this.checkString("-lh6-",{offset:2})||this.checkString("-lh7-",{offset:2})||this.checkString("-lzs-",{offset:2})||this.checkString("-lz4-",{offset:2})||this.checkString("-lz5-",{offset:2})||this.checkString("-lhd-",{offset:2}))return{ext:"lzh",mime:"application/x-lzh-compressed"};if(this.check([0,0,1,186])){if(this.check([33],{offset:4,mask:[241]}))return{ext:"mpg",mime:"video/MP1S"};if(this.check([68],{offset:4,mask:[196]}))return{ext:"mpg",mime:"video/MP2P"}}if(this.checkString("ITSF"))return{ext:"chm",mime:"application/vnd.ms-htmlhelp"};if(this.check([202,254,186,190])){let t=mw.get(this.buffer,4),n=Ca.get(this.buffer,6);if(t>0&&t<=30)return{ext:"macho",mime:"application/x-mach-binary"};if(n>30)return{ext:"class",mime:"application/java-vm"}}if(this.checkString(".RMF"))return{ext:"rm",mime:"application/vnd.rn-realmedia"};if(this.checkString("DRACO"))return{ext:"drc",mime:"application/vnd.google.draco"};if(this.check([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(this.checkString("<?xml "))return{ext:"xml",mime:"application/xml"};if(this.check([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(this.check([82,97,114,33,26,7])&&(this.buffer[6]===0||this.buffer[6]===1))return{ext:"rar",mime:"application/x-rar-compressed"};if(this.checkString("solid "))return{ext:"stl",mime:"model/stl"};if(this.checkString("AC")){let t=new Ur(4,"latin1").get(this.buffer,2);if(t.match("^d*")&&t>=1e3&&t<=1050)return{ext:"dwg",mime:"image/vnd.dwg"}}if(this.checkString("070707"))return{ext:"cpio",mime:"application/x-cpio"};if(this.checkString("BLENDER"))return{ext:"blend",mime:"application/x-blender"};if(this.checkString("!<arch>"))return await e.ignore(8),await e.readToken(new Ur(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
110
|
+
`).filter(o=>(o=o.trim(),o!==""&&!o.startsWith("#"))).map(o=>{let[i,s,a]=o.split(/\s+/).map(f=>f.trim());if(a!=null&&a!==""&&!a.match(/^\d+$/))throw new Kg("Invalid status code in _redirects file");let c=parseInt(a);if(isNaN(c)&&(c=301),!UY.includes(c))throw new zg(`Status code ${c} is not allowed`);let l=new Set,u=i.split("/"),d=u.map((f,h)=>{if(f.startsWith(":")){let p=f.substring(1);if(l.has(p))throw new Gg("Duplicate placeholders in from path");return l.add(p),`(?<${p}>[^/]+)`}return f==="*"&&h===u.length-1?"(?<splat>.+)":(0,ND.default)(f)}).join("\\/");return{from:new RegExp(d),to:s,status:c}});for(let{from:o,to:i,status:s}of n){let a=r.pathname.match(o);if(a!=null)return FY(r,i,s,a.groups,t)}}catch(n){return new Response(JSON.stringify(va(n),null,2),{status:500})}}function FY(r,e,t,n,o={}){if(o.redirect==="error")throw new TypeError("Failed to fetch");if(n!=null)for(let[c,l]of Object.entries(n))e=e.replaceAll(`:${c}`,l);let i=$Y(r,new URL(`${r.protocol}//${r.host}${e}`)),s=new URL(`${r.protocol}//${r.host}${e}`),a=new URL(`${r.protocol}//${r.host}${s.pathname}${HY(i)}${r.hash}`);return o.redirect==="manual"?new Response("",{status:t,headers:{location:a.toString()}}):a}function $Y(r,e){let t={};for(let[n,o]of r.searchParams)e.searchParams.delete(n),LD(n,o,t);for(let[n,o]of e.searchParams)LD(n,o,t);return t}function LD(r,e,t){typeof t[r]=="string"&&(t[r]=[t[r]]),Array.isArray(t[r])?t[r].push(e):t[r]=e}function HY(r){let e=[...Object.entries(r)].map(([t,n])=>(Array.isArray(n)||(n=[n]),n.map(o=>`${encodeURIComponent(t)}=${encodeURIComponent(o)}`).join("&"))).join("&");return e===""?e:`?${e}`}var Bl=class{headers;constructor(){this.headers=[]}getHeader(){return this.headers.join(",")}async time(e,t,n){let o=performance.now();try{return await n}finally{let s=(performance.now()-o).toFixed(1);this.headers.push(`${e};dur=${s};desc="${t}"`)}}};var qY=29030400;function VY(r){return{cid:r,name:r.toString(),path:r.toString(),roots:[r],remainder:[]}}var S3=class{log;components;blockstoreSessions;constructor(e,t={}){this.components=e,this.log=e.helia.logger.forComponent("helia-verified-fetch:url-resolver"),this.blockstoreSessions=new Pf({maxSize:t.sessionCacheSize??100,maxAge:t.sessionTTLms??6e4,onEviction:(n,o)=>{o.close()}})}async resolve(e,t=new Bl,n={}){if(e.protocol==="ipfs:")return this.resolveIPFSPath(e,t,n);if(e.protocol==="ipns:")return this.resolveIPNSName(e,t,n);if(e.protocol==="dnslink:")return this.resolveDNSLink(e,t,n);throw new Tn(`Invalid resource. Unsupported protocol in URL, must be ipfs:, ipns:, or dnslink: ${e}`)}async getBlockstore(e,t={}){if(t.session===!1)return this.components.helia.blockstore;let n=`ipfs:${e}`,o=this.blockstoreSessions.get(n),i=!1;if(o==null&&(this.log("create session with %d initial providers for root %c",t.providers?.length??0,e),i=!0,o=this.components.helia.blockstore.createSession(e,t),this.blockstoreSessions.set(n,o)),!i&&t.providers!=null&&t.providers.length>0){this.log("adding %d providers to existing session for root %c",t.providers.length,e);try{let s=await Promise.all(t.providers.map(async a=>{await o.addPeer(a,t)})??[]);this.log("result was %o",s)}catch(s){this.log.error("could not add provs - %e",s)}}return o}async resolveDNSLink(e,t,n){let i=(await t.time("dnsLink.resolve",`Resolve DNSLink ${e.hostname}`,this.components.dnsLink.resolve(e.hostname,n)))?.[0];if(i==null)throw new TypeError(`Invalid resource. Cannot resolve DNSLink from domain: ${e.hostname}`);i.path!=null&&e.pathname!==""&&e.pathname;let s;if(i.namespace==="ipns"){let a=new URL(`ipns://${i.peerId.toCID()}${e.pathname}`);s=await this.resolveIPNSName(a,t,n)}else if(i.namespace==="ipfs"){let a=new URL(`ipfs://${i.cid}/${e.pathname}`);s=await this.resolveIPFSPath(a,t,n)}else throw new TypeError(`Invalid resource. Unexpected DNSLink namespace ${i.namespace} from domain: ${domain}`);return s instanceof Response?s:{...s,url:e,ttl:i.answer.TTL}}async resolveIPNSName(e,t,n){let o=xe(e.hostname),i=await t.time("ipns.resolve",`Resolve IPNS name ${o}`,this.components.ipnsResolver.resolve(o,n));i.path!=null&&e.pathname!==""&&e.pathname;let s=new URL(`ipfs://${i.cid}/${e.pathname}`),a=await this.resolveIPFSPath(s,t,n);return a instanceof Response?a:{...a,url:e,ttl:Number((i.record.ttl??0n)/BigInt(1e9))}}async resolveIPFSPath(e,t,n){let o=await t.time("ipfs.resolve","",this.walkPath(e,n));return o instanceof Response?o:{...o,url:e,ttl:qY,blockstore:o.blockstore}}async walkPath(e,t={}){let n;try{n=F.parse(e.hostname)}catch(i){throw new Tn(`Could not parse CID - ${i}`)}let o=await this.getBlockstore(n,t);try{let i=[],s,a=KY(e);for await(let c of ns(a,o,{...t,yieldSubShards:!0}))i.push(c.cid),s=c;if(s==null)throw new e3("No terminal element found");return{ipfsRoots:i,terminalElement:s,blockstore:o,redirected:t.redirected===!0}}catch(i){if(i.name==="NotFoundError"&&t.redirected!==!0){let s;try{s=await Cn(`${n}/_redirects`,o,t)}catch(a){if(a.name!=="NotFoundError")throw a}if(s?.type==="file"||s?.type==="raw"){let a=R(await de(s.content(t))),c=OD(e,a,t);if(c instanceof Response)return c;if(c instanceof URL)return this.walkPath(c,{...t,redirected:!0})}}if(i.name==="NoResolverError")return{ipfsRoots:[n],terminalElement:VY(n),blockstore:o,redirected:!1};throw i}}};function KY(r){return`/ipfs/${r.hostname}${decodeURI(r.pathname)}`}var FD=qt(BD(),1);var MD={128:"\u20AC",130:"\u201A",131:"\u0192",132:"\u201E",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02C6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017D",145:"\u2018",146:"\u2019",147:"\u201C",148:"\u201D",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02DC",153:"\u2122",154:"\u0161",155:"\u203A",156:"\u0153",158:"\u017E",159:"\u0178"},zY={};for(let[r,e]of Object.entries(MD))zY[e]=Number.parseInt(r,10);var A3;function GY(){if(!(typeof globalThis.TextDecoder>"u"))return A3??(A3=new globalThis.TextDecoder("utf-8"))}var _a=32*1024;function UD(r,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":{let t=GY();return t?t.decode(r):WY(r)}case"utf-16le":return YY(r);case"us-ascii":case"ascii":return jY(r);case"latin1":case"iso-8859-1":return XY(r);case"windows-1252":return QY(r);default:throw new RangeError(`Encoding '${e}' not supported`)}}function WY(r){let e=[],t="",n=0;for(;n<r.length;){let o=r[n++];if(o<128)t+=String.fromCharCode(o);else if(o<224){let i=r[n++]&63;t+=String.fromCharCode((o&31)<<6|i)}else if(o<240){let i=r[n++]&63,s=r[n++]&63;t+=String.fromCharCode((o&15)<<12|i<<6|s)}else{let i=r[n++]&63,s=r[n++]&63,a=r[n++]&63,c=(o&7)<<18|i<<12|s<<6|a;c-=65536,t+=String.fromCharCode(55296+(c>>10&1023),56320+(c&1023))}t.length>=_a&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function YY(r){let e=r.length&-2;if(e===0)return"";let t=[],n=_a;for(let o=0;o<e;){let i=Math.min(n,e-o>>1),s=new Array(i);for(let a=0;a<i;a++,o+=2)s[a]=r[o]|r[o+1]<<8;t.push(String.fromCharCode.apply(null,s))}return t.join("")}function jY(r){let e=[];for(let t=0;t<r.length;t+=_a){let n=Math.min(r.length,t+_a),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i]&127;e.push(String.fromCharCode.apply(null,o))}return e.join("")}function XY(r){let e=[];for(let t=0;t<r.length;t+=_a){let n=Math.min(r.length,t+_a),o=new Array(n-t);for(let i=t,s=0;i<n;i++,s++)o[s]=r[i];e.push(String.fromCharCode.apply(null,o))}return e.join("")}function QY(r){let e=[],t="";for(let n=0;n<r.length;n++){let o=r[n],i=o>=128&&o<=159?MD[o]:void 0;t+=i??String.fromCharCode(o),t.length>=_a&&(e.push(t),t="")}return t&&e.push(t),e.join("")}function Mr(r){return new DataView(r.buffer,r.byteOffset)}var $D={len:1,get(r,e){return Mr(r).getUint8(e)},put(r,e,t){return Mr(r).setUint8(e,t),e+1}},at={len:2,get(r,e){return Mr(r).getUint16(e,!0)},put(r,e,t){return Mr(r).setUint16(e,t,!0),e+2}},Ca={len:2,get(r,e){return Mr(r).getUint16(e)},put(r,e,t){return Mr(r).setUint16(e,t),e+2}};var gt={len:4,get(r,e){return Mr(r).getUint32(e,!0)},put(r,e,t){return Mr(r).setUint32(e,t,!0),e+4}},mw={len:4,get(r,e){return Mr(r).getUint32(e)},put(r,e,t){return Mr(r).setUint32(e,t),e+4}};var HD={len:4,get(r,e){return Mr(r).getInt32(e)},put(r,e,t){return Mr(r).setInt32(e,t),e+4}};var qD={len:8,get(r,e){return Mr(r).getBigUint64(e,!0)},put(r,e,t){return Mr(r).setBigUint64(e,t,!0),e+8}};var Ur=class{constructor(e,t){this.len=e,this.encoding=t}get(e,t=0){let n=e.subarray(t,t+this.len);return UD(n,this.encoding)}};var JY="End-Of-Stream",Je=class extends Error{constructor(){super(JY),this.name="EndOfStreamError"}},Ia=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var ka=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,t=!1){let n=await this.read(e,t);return this.peekQueue.push(e.subarray(0,n)),n}async read(e,t=!1){if(e.length===0)return 0;let n=this.readFromPeekBuffer(e);if(this.endOfStream||(n+=await this.readRemainderFromStream(e.subarray(n),t)),n===0&&!t)throw new Je;return n}readFromPeekBuffer(e){let t=e.length,n=0;for(;this.peekQueue.length>0&&t>0;){let o=this.peekQueue.pop();if(!o)throw new Error("peekData should be defined");let i=Math.min(o.length,t);e.set(o.subarray(0,i),n),n+=i,t-=i,i<o.length&&this.peekQueue.push(o.subarray(i))}return n}async readRemainderFromStream(e,t){let n=0;for(;n<e.length&&!this.endOfStream;){if(this.interrupted)throw new Ia;let o=await this.readFromStream(e.subarray(n),t);if(o===0)break;n+=o}if(!t&&n<e.length)throw new Je;return n}};var T3=class extends ka{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}};var Ff=class extends T3{async readFromStream(e,t){if(e.length===0)return 0;let n=await this.reader.read(new Uint8Array(e.length),{min:t?void 0:e.length});return n.done&&(this.endOfStream=n.done),n.value?(e.set(n.value),n.value.length):0}};var Ml=class extends ka{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,t){let n=Math.min(t.length,e.length);return e.set(t.subarray(0,n)),n<t.length?this.buffer=t.subarray(n):this.buffer=null,n}async readFromStream(e,t){if(e.length===0)return 0;let n=0;for(this.buffer&&(n+=this.writeChunk(e,this.buffer));n<e.length&&!this.endOfStream;){let o=await this.reader.read();if(o.done){this.endOfStream=!0;break}o.value&&(n+=this.writeChunk(e.subarray(n),o.value))}if(!t&&n===0&&this.endOfStream)throw new Je;return n}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}};function gw(r){try{let e=r.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new Ml(e):new Ff(e)}catch(e){if(e instanceof TypeError)return new Ml(r.getReader());throw e}}var hi=class{constructor(e){this.numBuffer=new Uint8Array(8),this.position=0,this.onClose=e?.onClose,e?.abortSignal&&e.abortSignal.addEventListener("abort",()=>{this.abort()})}async readToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.readBuffer(n,{position:t})<e.len)throw new Je;return e.get(n,0)}async peekToken(e,t=this.position){let n=new Uint8Array(e.len);if(await this.peekBuffer(n,{position:t})<e.len)throw new Je;return e.get(n,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new Je;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new Je;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let t=this.fileInfo.size-this.position;if(e>t)return this.position+=t,t}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,t){if(!this.supportsRandomAccess()&&t&&t.position!==void 0&&t.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");return{mayBeLess:!1,offset:0,length:e.length,position:this.position,...t}}abort(){return Promise.resolve()}};var tj=256e3,_3=class extends hi{constructor(e,t){super(t),this.streamReader=e,this.fileInfo=t?.fileInfo??{}}async readBuffer(e,t){let n=this.normalizeOptions(e,t),o=n.position-this.position;if(o>0)return await this.ignore(o),this.readBuffer(e,t);if(o<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(n.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,n.length),n.mayBeLess);if(this.position+=i,(!t||!t.mayBeLess)&&i<n.length)throw new Je;return i}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=0;if(n.position){let i=n.position-this.position;if(i>0){let s=new Uint8Array(n.length+i);return o=await this.peekBuffer(s,{mayBeLess:n.mayBeLess}),e.set(s.subarray(i)),o-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(n.length>0){try{o=await this.streamReader.peek(e.subarray(0,n.length),n.mayBeLess)}catch(i){if(t?.mayBeLess&&i instanceof Je)return 0;throw i}if(!n.mayBeLess&&o<n.length)throw new Je}return o}async ignore(e){let t=Math.min(tj,e),n=new Uint8Array(t),o=0;for(;o<e;){let i=e-o,s=await this.readBuffer(n,{length:Math.min(t,i)});if(s<0)return s;o+=s}return o}abort(){return this.streamReader.abort()}async close(){return this.streamReader.close()}supportsRandomAccess(){return!1}};var C3=class extends hi{constructor(e,t){super(t),this.uint8Array=e,this.fileInfo={...t?.fileInfo??{},size:e.length}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.uint8Array.length-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new Je;return e.set(this.uint8Array.subarray(n.position,n.position+o)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};var I3=class extends hi{constructor(e,t){super(t),this.blob=e,this.fileInfo={...t?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,t){t?.position&&(this.position=t.position);let n=await this.peekBuffer(e,t);return this.position+=n,n}async peekBuffer(e,t){let n=this.normalizeOptions(e,t),o=Math.min(this.blob.size-n.position,n.length);if(!n.mayBeLess&&o<n.length)throw new Je;let i=await this.blob.slice(n.position,n.position+o).arrayBuffer();return e.set(new Uint8Array(i)),o}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}};function VD(r,e){let t=gw(r),n=e??{},o=n.onClose;return n.onClose=async()=>{if(await t.close(),o)return o()},new _3(t,n)}function KD(r,e){return new C3(r,e)}function zD(r,e){return new I3(r,e)}var eL=qt(XD(),1);var Pa={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},yw={get(r){return{signature:gt.get(r,0),compressedSize:gt.get(r,8),uncompressedSize:gt.get(r,12)}},len:16},QD={get(r){let e=at.get(r,6);return{signature:gt.get(r,0),minVersion:at.get(r,4),dataDescriptor:!!(e&8),compressedMethod:at.get(r,8),compressedSize:gt.get(r,18),uncompressedSize:gt.get(r,22),filenameLength:at.get(r,26),extraFieldLength:at.get(r,28),filename:null}},len:30},ZD={get(r){return{signature:gt.get(r,0),nrOfThisDisk:at.get(r,4),nrOfThisDiskWithTheStart:at.get(r,6),nrOfEntriesOnThisDisk:at.get(r,8),nrOfEntriesOfSize:at.get(r,10),sizeOfCd:gt.get(r,12),offsetOfStartOfCd:gt.get(r,16),zipFileCommentLength:at.get(r,20)}},len:22},JD={get(r){let e=at.get(r,8);return{signature:gt.get(r,0),minVersion:at.get(r,6),dataDescriptor:!!(e&8),compressedMethod:at.get(r,10),compressedSize:gt.get(r,20),uncompressedSize:gt.get(r,24),filenameLength:at.get(r,28),extraFieldLength:at.get(r,30),fileCommentLength:at.get(r,32),relativeOffsetOfLocalHeader:gt.get(r,42),filename:null}},len:46};function tL(r){let e=new Uint8Array(gt.len);return gt.put(e,0,r),e}var To=(0,eL.default)("tokenizer:inflate"),ww=256*1024,mj=tL(Pa.DataDescriptor),P3=tL(Pa.EndOfCentralDirectory),$f=class r{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(ww)}async isZip(){return await this.peekSignature()===Pa.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(gt)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,t=Math.min(16*1024,e.fileInfo.size),n=this.syncBuffer.subarray(0,t);await this.tokenizer.readBuffer(n,{position:e.fileInfo.size-t});for(let o=n.length-4;o>=0;o--)if(n[o]===P3[0]&&n[o+1]===P3[1]&&n[o+2]===P3[2]&&n[o+3]===P3[3])return e.fileInfo.size-t+o;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){To("Cannot reading central-directory without random-read support");return}To("Reading central-directory...");let e=this.tokenizer.position,t=await this.findEndOfCentralDirectoryLocator();if(t>0){To("Central-directory 32-bit signature found");let n=await this.tokenizer.readToken(ZD,t),o=[];this.tokenizer.setPosition(n.offsetOfStartOfCd);for(let i=0;i<n.nrOfEntriesOfSize;++i){let s=await this.tokenizer.readToken(JD);if(s.signature!==Pa.CentralFileHeader)throw new Error("Expected Central-File-Header signature");s.filename=await this.tokenizer.readToken(new Ur(s.filenameLength,"utf-8")),await this.tokenizer.ignore(s.extraFieldLength),await this.tokenizer.ignore(s.fileCommentLength),o.push(s),To(`Add central-directory file-entry: n=${i+1}/${o.length}: filename=${o[i].filename}`)}return this.tokenizer.setPosition(e),o}this.tokenizer.setPosition(e)}async unzip(e){let t=await this.readCentralDirectory();if(t)return this.iterateOverCentralDirectory(t,e);let n=!1;do{let o=await this.readLocalFileHeader();if(!o)break;let i=e(o);n=!!i.stop;let s;if(await this.tokenizer.ignore(o.extraFieldLength),o.dataDescriptor&&o.compressedSize===0){let a=[],c=ww;To("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let l=-1;for(;l<0&&c===ww;){c=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),l=gj(this.syncBuffer.subarray(0,c),mj);let u=l>=0?l:c;if(i.handler){let d=new Uint8Array(u);await this.tokenizer.readBuffer(d),a.push(d)}else await this.tokenizer.ignore(u)}To(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(o,yj(a),i.handler)}else i.handler?(To(`Reading compressed-file-data: ${o.compressedSize} bytes`),s=new Uint8Array(o.compressedSize),await this.tokenizer.readBuffer(s),await this.inflate(o,s,i.handler)):(To(`Ignoring compressed-file-data: ${o.compressedSize} bytes`),await this.tokenizer.ignore(o.compressedSize));if(To(`Reading data-descriptor at pos=${this.tokenizer.position}`),o.dataDescriptor&&(await this.tokenizer.readToken(yw)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-yw.len}`)}while(!n)}async iterateOverCentralDirectory(e,t){for(let n of e){let o=t(n);if(o.handler){this.tokenizer.setPosition(n.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let s=new Uint8Array(n.compressedSize);await this.tokenizer.readBuffer(s),await this.inflate(i,s,o.handler)}}if(o.stop)break}}async inflate(e,t,n){if(e.compressedMethod===0)return n(t);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);To(`Decompress filename=${e.filename}, compressed-size=${t.length}`);let o=await r.decompressDeflateRaw(t);return n(o)}static async decompressDeflateRaw(e){let t=new ReadableStream({start(i){i.enqueue(e),i.close()}}),n=new DecompressionStream("deflate-raw"),o=t.pipeThrough(n);try{let s=await new Response(o).arrayBuffer();return new Uint8Array(s)}catch(i){let s=i instanceof Error?`Failed to deflate ZIP entry: ${i.message}`:"Unknown decompression error in ZIP entry";throw new TypeError(s)}}async readLocalFileHeader(){let e=await this.tokenizer.peekToken(gt);if(e===Pa.LocalFileHeader){let t=await this.tokenizer.readToken(QD);return t.filename=await this.tokenizer.readToken(new Ur(t.filenameLength,"utf-8")),t}if(e===Pa.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}};function gj(r,e){let t=r.length,n=e.length;if(n>t)return-1;for(let o=0;o<=t-n;o++){let i=!0;for(let s=0;s<n;s++)if(r[o+s]!==e[s]){i=!1;break}if(i)return o}return-1}function yj(r){let e=r.reduce((o,i)=>o+i.length,0),t=new Uint8Array(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var Hf=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(t){let n=new Uint8Array(1024),o=await e.readBuffer(n,{mayBeLess:!0});if(o===0){t.close();return}t.enqueue(n.subarray(0,o))}}).pipeThrough(new DecompressionStream("gzip"))}};var RBe={utf8:new globalThis.TextDecoder("utf8")};var PBe=new globalThis.TextEncoder;var DBe=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function bw(r){let{byteLength:e}=r;if(e===6)return r.getUint16(0)*2**32+r.getUint32(2);if(e===5)return r.getUint8(0)*2**32+r.getUint32(1);if(e===4)return r.getUint32(0);if(e===3)return r.getUint8(0)*2**16+r.getUint16(1);if(e===2)return r.getUint16(0);if(e===1)return r.getUint8(0)}function rL(r,e){if(e==="utf-16le"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o&255,o>>8&255)}return t}if(e==="utf-16be"){let t=[];for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);t.push(o>>8&255,o&255)}return t}return[...r].map(t=>t.charCodeAt(0))}function nL(r,e=0){let t=Number.parseInt(new Ur(6).get(r,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(t))return!1;let n=256;for(let o=e;o<e+148;o++)n+=r[o];for(let o=e+156;o<e+512;o++)n+=r[o];return t===n}var oL={get:(r,e)=>r[e+3]&127|r[e+2]<<7|r[e+1]<<14|r[e]<<21,len:4};var iL=["jpg","png","apng","gif","webp","flif","xcf","cr2","cr3","orf","arw","dng","nef","rw2","raf","tif","bmp","icns","jxr","psd","indd","zip","tar","rar","gz","bz2","7z","dmg","mp4","mid","mkv","webm","mov","avi","mpg","mp2","mp3","m4a","oga","ogg","ogv","opus","flac","wav","spx","amr","pdf","epub","elf","macho","exe","swf","rtf","wasm","woff","woff2","eot","ttf","otf","ttc","ico","flv","ps","xz","sqlite","nes","crx","xpi","cab","deb","ar","rpm","Z","lz","cfb","mxf","mts","blend","bpg","docx","pptx","xlsx","3gp","3g2","j2c","jp2","jpm","jpx","mj2","aif","qcp","odt","ods","odp","xml","mobi","heic","cur","ktx","ape","wv","dcm","ics","glb","pcap","dsf","lnk","alias","voc","ac3","m4v","m4p","m4b","f4v","f4p","f4b","f4a","mie","asf","ogm","ogx","mpc","arrow","shp","aac","mp1","it","s3m","xm","skp","avif","eps","lzh","pgp","asar","stl","chm","3mf","zst","jxl","vcf","jls","pst","dwg","parquet","class","arj","cpio","ace","avro","icc","fbx","vsdx","vtt","apk","drc","lz4","potx","xltx","dotx","xltm","ott","ots","otp","odg","otg","xlsm","docm","dotm","potm","pptm","jar","jmp","rm","sav","ppsm","ppsx","tar.gz","reg","dat"],sL=["image/jpeg","image/png","image/gif","image/webp","image/flif","image/x-xcf","image/x-canon-cr2","image/x-canon-cr3","image/tiff","image/bmp","image/vnd.ms-photo","image/vnd.adobe.photoshop","application/x-indesign","application/epub+zip","application/x-xpinstall","application/vnd.ms-powerpoint.slideshow.macroenabled.12","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.slideshow","application/zip","application/x-tar","application/x-rar-compressed","application/gzip","application/x-bzip2","application/x-7z-compressed","application/x-apple-diskimage","application/vnd.apache.arrow.file","video/mp4","audio/midi","video/matroska","video/webm","video/quicktime","video/vnd.avi","audio/wav","audio/qcelp","audio/x-ms-asf","video/x-ms-asf","application/vnd.ms-asf","video/mpeg","video/3gpp","audio/mpeg","audio/mp4","video/ogg","audio/ogg","audio/ogg; codecs=opus","application/ogg","audio/flac","audio/ape","audio/wavpack","audio/amr","application/pdf","application/x-elf","application/x-mach-binary","application/x-msdownload","application/x-shockwave-flash","application/rtf","application/wasm","font/woff","font/woff2","application/vnd.ms-fontobject","font/ttf","font/otf","font/collection","image/x-icon","video/x-flv","application/postscript","application/eps","application/x-xz","application/x-sqlite3","application/x-nintendo-nes-rom","application/x-google-chrome-extension","application/vnd.ms-cab-compressed","application/x-deb","application/x-unix-archive","application/x-rpm","application/x-compress","application/x-lzip","application/x-cfb","application/x-mie","application/mxf","video/mp2t","application/x-blender","image/bpg","image/j2c","image/jp2","image/jpx","image/jpm","image/mj2","audio/aiff","application/xml","application/x-mobipocket-ebook","image/heif","image/heif-sequence","image/heic","image/heic-sequence","image/icns","image/ktx","application/dicom","audio/x-musepack","text/calendar","text/vcard","text/vtt","model/gltf-binary","application/vnd.tcpdump.pcap","audio/x-dsf","application/x.ms.shortcut","application/x.apple.alias","audio/x-voc","audio/vnd.dolby.dd-raw","audio/x-m4a","image/apng","image/x-olympus-orf","image/x-sony-arw","image/x-adobe-dng","image/x-nikon-nef","image/x-panasonic-rw2","image/x-fujifilm-raf","video/x-m4v","video/3gpp2","application/x-esri-shape","audio/aac","audio/x-it","audio/x-s3m","audio/x-xm","video/MP1S","video/MP2P","application/vnd.sketchup.skp","image/avif","application/x-lzh-compressed","application/pgp-encrypted","application/x-asar","model/stl","application/vnd.ms-htmlhelp","model/3mf","image/jxl","application/zstd","image/jls","application/vnd.ms-outlook","image/vnd.dwg","application/vnd.apache.parquet","application/java-vm","application/x-arj","application/x-cpio","application/x-ace-compressed","application/avro","application/vnd.iccprofile","application/x.autodesk.fbx","application/vnd.visio","application/vnd.android.package-archive","application/vnd.google.draco","application/x-lz4","application/vnd.openxmlformats-officedocument.presentationml.template","application/vnd.openxmlformats-officedocument.spreadsheetml.template","application/vnd.openxmlformats-officedocument.wordprocessingml.template","application/vnd.ms-excel.template.macroenabled.12","application/vnd.oasis.opendocument.text-template","application/vnd.oasis.opendocument.spreadsheet-template","application/vnd.oasis.opendocument.presentation-template","application/vnd.oasis.opendocument.graphics","application/vnd.oasis.opendocument.graphics-template","application/vnd.ms-excel.sheet.macroenabled.12","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-word.template.macroenabled.12","application/vnd.ms-powerpoint.template.macroenabled.12","application/vnd.ms-powerpoint.presentation.macroenabled.12","application/java-archive","application/vnd.rn-realmedia","application/x-spss-sav","application/x-ms-regedit","application/x-ft-windows-registry-hive","application/x-jmp-data"];var xw=4100;async function aL(r,e){return new vw(e).fromBuffer(r)}function Ew(r){switch(r=r.toLowerCase(),r){case"application/epub+zip":return{ext:"epub",mime:r};case"application/vnd.oasis.opendocument.text":return{ext:"odt",mime:r};case"application/vnd.oasis.opendocument.text-template":return{ext:"ott",mime:r};case"application/vnd.oasis.opendocument.spreadsheet":return{ext:"ods",mime:r};case"application/vnd.oasis.opendocument.spreadsheet-template":return{ext:"ots",mime:r};case"application/vnd.oasis.opendocument.presentation":return{ext:"odp",mime:r};case"application/vnd.oasis.opendocument.presentation-template":return{ext:"otp",mime:r};case"application/vnd.oasis.opendocument.graphics":return{ext:"odg",mime:r};case"application/vnd.oasis.opendocument.graphics-template":return{ext:"otg",mime:r};case"application/vnd.openxmlformats-officedocument.presentationml.slideshow":return{ext:"ppsx",mime:r};case"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return{ext:"xlsx",mime:r};case"application/vnd.ms-excel.sheet.macroenabled":return{ext:"xlsm",mime:"application/vnd.ms-excel.sheet.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.spreadsheetml.template":return{ext:"xltx",mime:r};case"application/vnd.ms-excel.template.macroenabled":return{ext:"xltm",mime:"application/vnd.ms-excel.template.macroenabled.12"};case"application/vnd.ms-powerpoint.slideshow.macroenabled":return{ext:"ppsm",mime:"application/vnd.ms-powerpoint.slideshow.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return{ext:"docx",mime:r};case"application/vnd.ms-word.document.macroenabled":return{ext:"docm",mime:"application/vnd.ms-word.document.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.wordprocessingml.template":return{ext:"dotx",mime:r};case"application/vnd.ms-word.template.macroenabledtemplate":return{ext:"dotm",mime:"application/vnd.ms-word.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.template":return{ext:"potx",mime:r};case"application/vnd.ms-powerpoint.template.macroenabled":return{ext:"potm",mime:"application/vnd.ms-powerpoint.template.macroenabled.12"};case"application/vnd.openxmlformats-officedocument.presentationml.presentation":return{ext:"pptx",mime:r};case"application/vnd.ms-powerpoint.presentation.macroenabled":return{ext:"pptm",mime:"application/vnd.ms-powerpoint.presentation.macroenabled.12"};case"application/vnd.ms-visio.drawing":return{ext:"vsdx",mime:"application/vnd.visio"};case"application/vnd.ms-package.3dmanufacturing-3dmodel+xml":return{ext:"3mf",mime:"model/3mf"};default:}}function _o(r,e,t){t={offset:0,...t};for(let[n,o]of e.entries())if(t.mask){if(o!==(t.mask[n]&r[n+t.offset]))return!1}else if(o!==r[n+t.offset])return!1;return!0}var vw=class{constructor(e){this.options={mpegOffsetTolerance:0,...e},this.detectors=[...e?.customDetectors??[],{id:"core",detect:this.detectConfident},{id:"core.imprecise",detect:this.detectImprecise}],this.tokenizerOptions={abortSignal:e?.signal}}async fromTokenizer(e){let t=e.position;for(let n of this.detectors){let o=await n.detect(e);if(o)return o;if(t!==e.position)return}}async fromBuffer(e){if(!(e instanceof Uint8Array||e instanceof ArrayBuffer))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof e}\``);let t=e instanceof Uint8Array?e:new Uint8Array(e);if(t?.length>1)return this.fromTokenizer(KD(t,this.tokenizerOptions))}async fromBlob(e){let t=zD(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async fromStream(e){let t=VD(e,this.tokenizerOptions);try{return await this.fromTokenizer(t)}finally{await t.close()}}async toDetectionStream(e,t){let{sampleSize:n=xw}=t,o,i,s=e.getReader({mode:"byob"});try{let{value:l,done:u}=await s.read(new Uint8Array(n));if(i=l,!u&&l)try{o=await this.fromBuffer(l.subarray(0,n))}catch(d){if(!(d instanceof Je))throw d;o=void 0}i=l}finally{s.releaseLock()}let a=new TransformStream({async start(l){l.enqueue(i)},transform(l,u){u.enqueue(l)}}),c=e.pipeThrough(a);return c.fileType=o,c}check(e,t){return _o(this.buffer,e,t)}checkString(e,t){return this.check(rL(e,t?.encoding),t)}detectConfident=async e=>{if(this.buffer=new Uint8Array(xw),e.fileInfo.size===void 0&&(e.fileInfo.size=Number.MAX_SAFE_INTEGER),this.tokenizer=e,await e.peekBuffer(this.buffer,{length:32,mayBeLess:!0}),this.check([66,77]))return{ext:"bmp",mime:"image/bmp"};if(this.check([11,119]))return{ext:"ac3",mime:"audio/vnd.dolby.dd-raw"};if(this.check([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(this.check([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if(this.check([37,33]))return await e.peekBuffer(this.buffer,{length:24,mayBeLess:!0}),this.checkString("PS-Adobe-",{offset:2})&&this.checkString(" EPSF-",{offset:14})?{ext:"eps",mime:"application/eps"}:{ext:"ps",mime:"application/postscript"};if(this.check([31,160])||this.check([31,157]))return{ext:"Z",mime:"application/x-compress"};if(this.check([199,113]))return{ext:"cpio",mime:"application/x-cpio"};if(this.check([96,234]))return{ext:"arj",mime:"application/x-arj"};if(this.check([239,187,191]))return this.tokenizer.ignore(3),this.detectConfident(e);if(this.check([71,73,70]))return{ext:"gif",mime:"image/gif"};if(this.check([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(this.check([31,139,8])){let n=new Hf(e).inflate(),o=!0;try{let i;try{i=await this.fromStream(n)}catch{o=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{o&&await n.cancel()}return{ext:"gz",mime:"application/gzip"}}if(this.check([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(this.checkString("ID3")){await e.ignore(6);let t=await e.readToken(oL);return e.position+t>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(t),this.fromTokenizer(e))}if(this.checkString("MP+"))return{ext:"mpc",mime:"audio/x-musepack"};if((this.buffer[0]===67||this.buffer[0]===70)&&this.check([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(this.check([255,216,255]))return this.check([247],{offset:3})?{ext:"jls",mime:"image/jls"}:{ext:"jpg",mime:"image/jpeg"};if(this.check([79,98,106,1]))return{ext:"avro",mime:"application/avro"};if(this.checkString("FLIF"))return{ext:"flif",mime:"image/flif"};if(this.checkString("8BPS"))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(this.checkString("MPCK"))return{ext:"mpc",mime:"audio/x-musepack"};if(this.checkString("FORM"))return{ext:"aif",mime:"audio/aiff"};if(this.checkString("icns",{offset:0}))return{ext:"icns",mime:"image/icns"};if(this.check([80,75,3,4])){let t;return await new $f(e).unzip(n=>{switch(n.filename){case"META-INF/mozilla.rsa":return t={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return t={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(o){let i=new TextDecoder("utf-8").decode(o).trim();t=Ew(i)},stop:!0};case"[Content_Types].xml":return{async handler(o){let i=new TextDecoder("utf-8").decode(o),s=i.indexOf('.main+xml"');if(s===-1){let a="application/vnd.ms-package.3dmanufacturing-3dmodel+xml";i.includes(`ContentType="${a}"`)&&(t=Ew(a))}else{i=i.slice(0,Math.max(0,s));let a=i.lastIndexOf('"'),c=i.slice(Math.max(0,a+1));t=Ew(c)}},stop:!0};default:return/classes\d*\.dex/.test(n.filename)?(t={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(n=>{if(!(n instanceof Je))throw n}),t??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let t=new Uint8Array(8);return await e.readBuffer(t),_o(t,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:_o(t,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:_o(t,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:_o(t,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:_o(t,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:_o(t,[1,118,111,114,98,105,115])?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"}}if(this.check([80,75])&&(this.buffer[2]===3||this.buffer[2]===5||this.buffer[2]===7)&&(this.buffer[3]===4||this.buffer[3]===6||this.buffer[3]===8))return{ext:"zip",mime:"application/zip"};if(this.checkString("MThd"))return{ext:"mid",mime:"audio/midi"};if(this.checkString("wOFF")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff",mime:"font/woff"};if(this.checkString("wOF2")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(this.check([212,195,178,161])||this.check([161,178,195,212]))return{ext:"pcap",mime:"application/vnd.tcpdump.pcap"};if(this.checkString("DSD "))return{ext:"dsf",mime:"audio/x-dsf"};if(this.checkString("LZIP"))return{ext:"lz",mime:"application/x-lzip"};if(this.checkString("fLaC"))return{ext:"flac",mime:"audio/flac"};if(this.check([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(this.checkString("wvpk"))return{ext:"wv",mime:"audio/wavpack"};if(this.checkString("%PDF"))return{ext:"pdf",mime:"application/pdf"};if(this.check([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(this.check([73,73])){let t=await this.readTiffHeader(!1);if(t)return t}if(this.check([77,77])){let t=await this.readTiffHeader(!0);if(t)return t}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function t(){let a=await e.peekNumber($D),c=128,l=0;for(;(a&c)===0&&c!==0;)++l,c>>=1;let u=new Uint8Array(l+1);return await e.readBuffer(u),u}async function n(){let a=await t(),c=await t();c[0]^=128>>c.length-1;let l=Math.min(6,c.length),u=new DataView(a.buffer),d=new DataView(c.buffer,c.length-l,l);return{id:bw(u),len:bw(d)}}async function o(a){for(;a>0;){let c=await n();if(c.id===17026)return(await e.readToken(new Ur(c.len))).replaceAll(/\00.*$/g,"");await e.ignore(c.len),--a}}let i=await n();switch(await o(i.len)){case"webm":return{ext:"webm",mime:"video/webm"};case"matroska":return{ext:"mkv",mime:"video/matroska"};default:return}}if(this.checkString("SQLi"))return{ext:"sqlite",mime:"application/x-sqlite3"};if(this.check([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(this.checkString("Cr24"))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(this.checkString("MSCF")||this.checkString("ISc("))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(this.check([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(this.check([197,208,211,198]))return{ext:"eps",mime:"application/eps"};if(this.check([40,181,47,253]))return{ext:"zst",mime:"application/zstd"};if(this.check([127,69,76,70]))return{ext:"elf",mime:"application/x-elf"};if(this.check([33,66,68,78]))return{ext:"pst",mime:"application/vnd.ms-outlook"};if(this.checkString("PAR1")||this.checkString("PARE"))return{ext:"parquet",mime:"application/vnd.apache.parquet"};if(this.checkString("ttcf"))return{ext:"ttc",mime:"font/collection"};if(this.check([254,237,250,206])||this.check([254,237,250,207])||this.check([206,250,237,254])||this.check([207,250,237,254]))return{ext:"macho",mime:"application/x-mach-binary"};if(this.check([4,34,77,24]))return{ext:"lz4",mime:"application/x-lz4"};if(this.checkString("regf"))return{ext:"dat",mime:"application/x-ft-windows-registry-hive"};if(this.checkString("$FL2")||this.checkString("$FL3"))return{ext:"sav",mime:"application/x-spss-sav"};if(this.check([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(this.checkString("#!AMR"))return{ext:"amr",mime:"audio/amr"};if(this.checkString("{\\rtf"))return{ext:"rtf",mime:"application/rtf"};if(this.check([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(this.checkString("IMPM"))return{ext:"it",mime:"audio/x-it"};if(this.checkString("-lh0-",{offset:2})||this.checkString("-lh1-",{offset:2})||this.checkString("-lh2-",{offset:2})||this.checkString("-lh3-",{offset:2})||this.checkString("-lh4-",{offset:2})||this.checkString("-lh5-",{offset:2})||this.checkString("-lh6-",{offset:2})||this.checkString("-lh7-",{offset:2})||this.checkString("-lzs-",{offset:2})||this.checkString("-lz4-",{offset:2})||this.checkString("-lz5-",{offset:2})||this.checkString("-lhd-",{offset:2}))return{ext:"lzh",mime:"application/x-lzh-compressed"};if(this.check([0,0,1,186])){if(this.check([33],{offset:4,mask:[241]}))return{ext:"mpg",mime:"video/MP1S"};if(this.check([68],{offset:4,mask:[196]}))return{ext:"mpg",mime:"video/MP2P"}}if(this.checkString("ITSF"))return{ext:"chm",mime:"application/vnd.ms-htmlhelp"};if(this.check([202,254,186,190])){let t=mw.get(this.buffer,4),n=Ca.get(this.buffer,6);if(t>0&&t<=30)return{ext:"macho",mime:"application/x-mach-binary"};if(n>30)return{ext:"class",mime:"application/java-vm"}}if(this.checkString(".RMF"))return{ext:"rm",mime:"application/vnd.rn-realmedia"};if(this.checkString("DRACO"))return{ext:"drc",mime:"application/vnd.google.draco"};if(this.check([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(this.checkString("<?xml "))return{ext:"xml",mime:"application/xml"};if(this.check([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(this.check([82,97,114,33,26,7])&&(this.buffer[6]===0||this.buffer[6]===1))return{ext:"rar",mime:"application/x-rar-compressed"};if(this.checkString("solid "))return{ext:"stl",mime:"model/stl"};if(this.checkString("AC")){let t=new Ur(4,"latin1").get(this.buffer,2);if(t.match("^d*")&&t>=1e3&&t<=1050)return{ext:"dwg",mime:"image/vnd.dwg"}}if(this.checkString("070707"))return{ext:"cpio",mime:"application/x-cpio"};if(this.checkString("BLENDER"))return{ext:"blend",mime:"application/x-blender"};if(this.checkString("!<arch>"))return await e.ignore(8),await e.readToken(new Ur(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
111
111
|
`,"\r"," "," ","\0"].some(t=>this.checkString(t,{offset:6})))return{ext:"vtt",mime:"text/vtt"};if(this.check([137,80,78,71,13,10,26,10])){await e.ignore(8);async function t(){return{length:await e.readToken(HD),type:await e.readToken(new Ur(4,"latin1"))}}do{let n=await t();if(n.length<0)return;switch(n.type){case"IDAT":return{ext:"png",mime:"image/png"};case"acTL":return{ext:"apng",mime:"image/apng"};default:await e.ignore(n.length+4)}}while(e.position+8<e.fileInfo.size);return{ext:"png",mime:"image/png"}}if(this.check([65,82,82,79,87,49,0,0]))return{ext:"arrow",mime:"application/vnd.apache.arrow.file"};if(this.check([103,108,84,70,2,0,0,0]))return{ext:"glb",mime:"model/gltf-binary"};if(this.check([102,114,101,101],{offset:4})||this.check([109,100,97,116],{offset:4})||this.check([109,111,111,118],{offset:4})||this.check([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(this.check([73,73,82,79,8,0,0,0,24]))return{ext:"orf",mime:"image/x-olympus-orf"};if(this.checkString("gimp xcf "))return{ext:"xcf",mime:"image/x-xcf"};if(this.checkString("ftyp",{offset:4})&&(this.buffer[8]&96)!==0){let t=new Ur(4,"latin1").get(this.buffer,8).replace("\0"," ").trim();switch(t){case"avif":case"avis":return{ext:"avif",mime:"image/avif"};case"mif1":return{ext:"heic",mime:"image/heif"};case"msf1":return{ext:"heic",mime:"image/heif-sequence"};case"heic":case"heix":return{ext:"heic",mime:"image/heic"};case"hevc":case"hevx":return{ext:"heic",mime:"image/heic-sequence"};case"qt":return{ext:"mov",mime:"video/quicktime"};case"M4V":case"M4VH":case"M4VP":return{ext:"m4v",mime:"video/x-m4v"};case"M4P":return{ext:"m4p",mime:"video/mp4"};case"M4B":return{ext:"m4b",mime:"audio/mp4"};case"M4A":return{ext:"m4a",mime:"audio/x-m4a"};case"F4V":return{ext:"f4v",mime:"video/mp4"};case"F4P":return{ext:"f4p",mime:"video/mp4"};case"F4A":return{ext:"f4a",mime:"audio/mp4"};case"F4B":return{ext:"f4b",mime:"audio/mp4"};case"crx":return{ext:"cr3",mime:"image/x-canon-cr3"};default:return t.startsWith("3g")?t.startsWith("3g2")?{ext:"3g2",mime:"video/3gpp2"}:{ext:"3gp",mime:"video/3gpp"}:{ext:"mp4",mime:"video/mp4"}}}if(this.checkString(`REGEDIT4\r
|
|
112
112
|
`))return{ext:"reg",mime:"application/x-ms-regedit"};if(this.check([82,73,70,70])){if(this.checkString("WEBP",{offset:8}))return{ext:"webp",mime:"image/webp"};if(this.check([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(this.check([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/wav"};if(this.check([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(this.check([73,73,85,0,24,0,0,0,136,231,116,216]))return{ext:"rw2",mime:"image/x-panasonic-rw2"};if(this.check([48,38,178,117,142,102,207,17,166,217])){async function t(){let n=new Uint8Array(16);return await e.readBuffer(n),{id:n,size:Number(await e.readToken(qD))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let n=await t(),o=n.size-24;if(_o(n.id,[145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101])){let i=new Uint8Array(16);if(o-=await e.readBuffer(i),_o(i,[64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"audio/x-ms-asf"};if(_o(i,[192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"video/x-ms-asf"};break}await e.ignore(o)}return{ext:"asf",mime:"application/vnd.ms-asf"}}if(this.check([171,75,84,88,32,49,49,187,13,10,26,10]))return{ext:"ktx",mime:"image/ktx"};if((this.check([126,16,4])||this.check([126,24,4]))&&this.check([48,77,73,69],{offset:4}))return{ext:"mie",mime:"application/x-mie"};if(this.check([39,10,0,0,0,0,0,0,0,0,0,0],{offset:2}))return{ext:"shp",mime:"application/x-esri-shape"};if(this.check([255,79,255,81]))return{ext:"j2c",mime:"image/j2c"};if(this.check([0,0,0,12,106,80,32,32,13,10,135,10]))switch(await e.ignore(20),await e.readToken(new Ur(4,"ascii"))){case"jp2 ":return{ext:"jp2",mime:"image/jp2"};case"jpx ":return{ext:"jpx",mime:"image/jpx"};case"jpm ":return{ext:"jpm",mime:"image/jpm"};case"mjp2":return{ext:"mj2",mime:"image/mj2"};default:return}if(this.check([255,10])||this.check([0,0,0,12,74,88,76,32,13,10,135,10]))return{ext:"jxl",mime:"image/jxl"};if(this.check([254,255]))return this.checkString("<?xml ",{offset:2,encoding:"utf-16be"})?{ext:"xml",mime:"application/xml"}:void 0;if(this.check([208,207,17,224,161,177,26,225]))return{ext:"cfb",mime:"application/x-cfb"};if(await e.peekBuffer(this.buffer,{length:Math.min(256,e.fileInfo.size),mayBeLess:!0}),this.check([97,99,115,112],{offset:36}))return{ext:"icc",mime:"application/vnd.iccprofile"};if(this.checkString("**ACE",{offset:7})&&this.checkString("**",{offset:12}))return{ext:"ace",mime:"application/x-ace-compressed"};if(this.checkString("BEGIN:")){if(this.checkString("VCARD",{offset:6}))return{ext:"vcf",mime:"text/vcard"};if(this.checkString("VCALENDAR",{offset:6}))return{ext:"ics",mime:"text/calendar"}}if(this.checkString("FUJIFILMCCD-RAW"))return{ext:"raf",mime:"image/x-fujifilm-raf"};if(this.checkString("Extended Module:"))return{ext:"xm",mime:"audio/x-xm"};if(this.checkString("Creative Voice File"))return{ext:"voc",mime:"audio/x-voc"};if(this.check([4,0,0,0])&&this.buffer.length>=16){let t=new DataView(this.buffer.buffer).getUint32(12,!0);if(t>12&&this.buffer.length>=t+16)try{let n=new TextDecoder().decode(this.buffer.subarray(16,t+16));if(JSON.parse(n).files)return{ext:"asar",mime:"application/x-asar"}}catch{}}if(this.check([6,14,43,52,2,5,1,1,13,1,2,1,1,2]))return{ext:"mxf",mime:"application/mxf"};if(this.checkString("SCRM",{offset:44}))return{ext:"s3m",mime:"audio/x-s3m"};if(this.check([71])&&this.check([71],{offset:188}))return{ext:"mts",mime:"video/mp2t"};if(this.check([71],{offset:4})&&this.check([71],{offset:196}))return{ext:"mts",mime:"video/mp2t"};if(this.check([66,79,79,75,77,79,66,73],{offset:60}))return{ext:"mobi",mime:"application/x-mobipocket-ebook"};if(this.check([68,73,67,77],{offset:128}))return{ext:"dcm",mime:"application/dicom"};if(this.check([76,0,0,0,1,20,2,0,0,0,0,0,192,0,0,0,0,0,0,70]))return{ext:"lnk",mime:"application/x.ms.shortcut"};if(this.check([98,111,111,107,0,0,0,0,109,97,114,107,0,0,0,0]))return{ext:"alias",mime:"application/x.apple.alias"};if(this.checkString("Kaydara FBX Binary \0"))return{ext:"fbx",mime:"application/x.autodesk.fbx"};if(this.check([76,80],{offset:34})&&(this.check([0,0,1],{offset:8})||this.check([1,0,2],{offset:8})||this.check([2,0,2],{offset:8})))return{ext:"eot",mime:"application/vnd.ms-fontobject"};if(this.check([6,6,237,245,216,29,70,229,189,49,239,231,254,116,183,29]))return{ext:"indd",mime:"application/x-indesign"};if(this.check([255,255,0,0,7,0,0,0,4,0,0,0,1,0,1,0])||this.check([0,0,255,255,0,0,0,7,0,0,0,4,0,1,0,1]))return{ext:"jmp",mime:"application/x-jmp-data"};if(await e.peekBuffer(this.buffer,{length:Math.min(512,e.fileInfo.size),mayBeLess:!0}),this.checkString("ustar",{offset:257})&&(this.checkString("\0",{offset:262})||this.checkString(" ",{offset:262}))||this.check([0,0,0,0,0,0],{offset:257})&&nL(this.buffer))return{ext:"tar",mime:"application/x-tar"};if(this.check([255,254])){let t="utf-16le";return this.checkString("<?xml ",{offset:2,encoding:t})?{ext:"xml",mime:"application/xml"}:this.check([255,14],{offset:2})&&this.checkString("SketchUp Model",{offset:4,encoding:t})?{ext:"skp",mime:"application/vnd.sketchup.skp"}:this.checkString(`Windows Registry Editor Version 5.00\r
|
|
113
113
|
`,{offset:2,encoding:t})?{ext:"reg",mime:"application/x-ms-regedit"}:void 0}if(this.checkString("-----BEGIN PGP MESSAGE-----"))return{ext:"pgp",mime:"application/pgp-encrypted"}};detectImprecise=async e=>{if(this.buffer=new Uint8Array(xw),await e.peekBuffer(this.buffer,{length:Math.min(8,e.fileInfo.size),mayBeLess:!0}),this.check([0,0,1,186])||this.check([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(this.check([0,1,0,0,0]))return{ext:"ttf",mime:"font/ttf"};if(this.check([0,0,1,0]))return{ext:"ico",mime:"image/x-icon"};if(this.check([0,0,2,0]))return{ext:"cur",mime:"image/x-icon"};if(await e.peekBuffer(this.buffer,{length:Math.min(2+this.options.mpegOffsetTolerance,e.fileInfo.size),mayBeLess:!0}),this.buffer.length>=2+this.options.mpegOffsetTolerance)for(let t=0;t<=this.options.mpegOffsetTolerance;++t){let n=this.scanMpeg(t);if(n)return n}};async readTiffTag(e){let t=await this.tokenizer.readToken(e?Ca:at);switch(this.tokenizer.ignore(10),t){case 50341:return{ext:"arw",mime:"image/x-sony-arw"};case 50706:return{ext:"dng",mime:"image/x-adobe-dng"};default:}}async readTiffIFD(e){let t=await this.tokenizer.readToken(e?Ca:at);for(let n=0;n<t;++n){let o=await this.readTiffTag(e);if(o)return o}}async readTiffHeader(e){let t=(e?Ca:at).get(this.buffer,2),n=(e?mw:gt).get(this.buffer,4);if(t===42){if(n>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(n>=8){let i=(e?Ca:at).get(this.buffer,8),s=(e?Ca:at).get(this.buffer,10);if(i===28&&s===254||i===31&&s===11)return{ext:"nef",mime:"image/x-nikon-nef"}}}return await this.tokenizer.ignore(n),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(t===43)return{ext:"tif",mime:"image/tiff"}}scanMpeg(e){if(this.check([255,224],{offset:e,mask:[255,224]})){if(this.check([16],{offset:e+1,mask:[22]}))return this.check([8],{offset:e+1,mask:[8]})?{ext:"aac",mime:"audio/aac"}:{ext:"aac",mime:"audio/aac"};if(this.check([2],{offset:e+1,mask:[6]}))return{ext:"mp3",mime:"audio/mpeg"};if(this.check([4],{offset:e+1,mask:[6]}))return{ext:"mp2",mime:"audio/mpeg"};if(this.check([6],{offset:e+1,mask:[6]}))return{ext:"mp1",mime:"audio/mpeg"}}}},HBe=new Set(iL),qBe=new Set(sL);var cL="application/octet-stream";function wj(r){return/^(<\?xml[^>]+>)?[^<^\w]+<svg/ig.test(r)}async function bj(r){try{return JSON.parse(r),!0}catch{return!1}}function xj(r){let e=new TextDecoder("utf-8",{fatal:!0});try{return e.decode(r)}catch{return null}}async function Ej(r){return/^\s*<(?:!doctype\s+html|html|head|body)\b/i.test(r)}async function lL(r,e){let t=(await aL(r))?.mime;if(t!=null)return t==="application/xml"&&e?.toLowerCase().endsWith(".svg")?"image/svg+xml":t;if(e==null||e.includes(".")===!1){let n=xj(r);return n!=null?wj(n)?"image/svg+xml":await bj(n)?"application/json":await Ej(n)?"text/html; charset=utf-8":"text/plain; charset=utf-8":cL}switch(e.split(".").pop()){case"css":return"text/css";case"html":return"text/html; charset=utf-8";case"js":return"application/javascript";case"json":return"application/json";case"txt":return"text/plain";case"woff2":return"font/woff2";case"svg":return"image/svg+xml";case"csv":return"text/csv";case"doc":return"application/msword";case"xls":return"application/vnd.ms-excel";case"ppt":return"application/vnd.ms-powerpoint";case"msi":return"application/x-msdownload";default:return cL}}function uL(r,e,t){if(t?.signal?.throwIfAborted(),["AbortError"].includes(e.name))throw e;return["InvalidParametersError"].includes(e.name)?Br(r,e):e.code==="ECONNREFUSED"||e.code==="ECANCELLED"||e.name==="DNSQueryFailedError"?Wg(r,e):["NotUnixFSError"].includes(e.name)?Sa(r,e):e.code==="ETIMEOUT"||e.name==="TimeoutError"?Wg(r,e):["ERR_BAD_PATH","ERR_NO_TERMINAL_ELEMENT","ERR_NOT_FOUND"].includes(e.code)?_7(r):["DoesNotExistError"].includes(e.name)?_7(r):["BlockNotFoundWhileOfflineError"].includes(e.name)?yk(r):["RecordNotFoundError","LoadBlockFailedError"].includes(e.name)?Wg(r,e):A7(r,e)}function dL({cid:r,contentType:e,ranges:t,contentPrefix:n}){let o=e.immutable?"":"W/",i=e.etag;if(t?.length!=null&&t?.length>0){let s=t.filter(a=>a.start!=null||a.end!=null);s.length>0&&(i+="."+s.map(a=>`${a.start??0}-${a.end??"N"}`).join(","))}return`${o}"${n??""}${r.toString()}${i}"`}function Sw(r,e){let t=(e?.get("if-none-match")??"").split(",").map(n=>(n=n.trim(),n.startsWith("W/")&&(n=n.substring(2)),n));return r.startsWith("W/")&&(r=r.substring(2)),t.includes("*")||t.includes(r)}function Aw(r){if(r==null||r==="")return;let e=Number(r);if(isNaN(e))throw new Or(`Invalid range specification: could not parse "${e}" as number`);return e}function vj(r){if(r==null||r==="")return[];if(!r.startsWith("bytes="))throw new Or("Invalid range request");let t=r.substring(6).split(",").map(o=>o.trim()),n=[];for(let o of t){let i=o.match(/^(?<start>\d+)?-(?<end>\d+)?$/);if(i?.groups==null)throw new Or(`Invalid range specification: ${o}`);if(o.startsWith("-"))n.push({end:Aw(o)});else{let{start:s,end:a}=i.groups;n.push({start:Aw(s),end:Aw(a)})}}return n}function fL(r,e){let t=e.get("range");if(t!=null)try{let n=vj(t);return n.length===0?void 0:{multipartBoundary:`multipart_byteranges_${Math.floor(Math.random()*1e9)}`,ranges:n}}catch(n){return n.name==="InvalidRangeError"?Yg(r):Br(r,n)}}function Sj(r){if(!r.startsWith("/ipfs/")&&!r.startsWith("/ipns/"))throw new S(`Path ${r} did not start with /ipfs/ or /ipns/`);let e=new URL(`not-http://example.com${r}`),[,t,n,...o]=e.pathname.split("/");return`${t}://${n}${o.length>0?`/${o.join("/")}`:""}${e.search}${e.hash}`}function hL(r){if((r.startsWith("/ipfs/")||r.startsWith("/ipns/"))&&(r=Sj(r)),r.startsWith("ipfs://")||r.startsWith("ipns://")||r.startsWith("dnslink://")){let e=new URL(r);if(e.protocol==="ipns:")try{F.parse(e.hostname)}catch{try{xe(e.hostname)}catch{e.protocol="dnslink"}}return e}throw new S(`URL did not start with ipfs:// or ipns:// - ${r}`)}function Aj(r){if(r!=null)return{...r,signal:r?.signal==null?void 0:r?.signal}}function Tj(r){let e=r.get("accept")?.split(",")??[];return e.length!==1?!1:e[0].split(";")[0]===ba}var D3=class{helia;ipnsResolver;dnsLink;log;contentTypeParser;withServerTiming;plugins=[];urlResolver;constructor(e,t={}){this.helia=e,this.log=e.logger.forComponent("helia:verified-fetch"),this.ipnsResolver=t.ipnsResolver??dI(e),this.dnsLink=t.dnsLink??iI(e),this.contentTypeParser=t.contentTypeParser??lL,this.withServerTiming=t?.withServerTiming??!1,this.urlResolver=new S3({ipnsResolver:this.ipnsResolver,dnsLink:this.dnsLink,helia:this.helia},t);let n={...t,logger:e.logger.forComponent("verified-fetch"),helia:e,contentTypeParser:this.contentTypeParser,ipnsResolver:this.ipnsResolver},o=[new o3(n),new Xg(n),new jg(n),new n3(n),new Qg(n),new Zg(n)],i=t.plugins?.map(s=>s(n))??[];if(i.length>0){let s=new Map(o.map(c=>[c.id,c])),a=new Map(i.map(c=>[c.id,c]));this.plugins=o.map(c=>a.get(c.id)??c),this.plugins.unshift(...i.filter(c=>!s.has(c.id)))}else this.plugins=o}async fetch(e,t){this.log("fetch %s %s",t?.method??"GET",e);try{if(t?.method==="OPTIONS")return this.handleFinalResponse(new Response(null,{status:200}));let n=Aj(t),o=new Headers(n?.headers),i=new Bl;n!=null&&(n.offline??=o.get("cache-control")==="only-if-cached"),n?.onProgress?.(new M("verified-fetch:request:start",{resource:e}));let s=fL(e,o);if(s instanceof Response)return this.handleFinalResponse(s);let a=this.parseResource(e);if(a.protocol==="ipfs:"&&a.pathname===""&&Sw(`"${a.hostname}"`,o))return C7(e,new Headers({etag:`"${a.hostname}"`,"cache-control":"public, max-age=29030400, immutable"}));let c=_j(a,o.get("accept"));if(Tj(o)){if(a.protocol!=="ipns:")return is(a,c,[Ea]);let h=this.plugins.find(p=>p.id==="ipns-record-plugin");return h==null?is(e,c,[]):this.handleFinalResponse(await h.handle({range:s,url:a,resource:e,options:n,redirected:!1}))}let l=await this.urlResolver.resolve(a,i,n);if(l instanceof Response)return this.handleFinalResponse(l);n?.onProgress?.(new M("verified-fetch:request:resolve",{cid:l.terminalElement.cid,path:l.url.pathname}));let u=this.getAcceptHeader(l.url,c,l.terminalElement.cid);if(u instanceof Response)return this.log("allowed media types for requested CID did not contain anything the client can understand"),this.handleFinalResponse(u);let d={...l,resource:e,accept:u,range:s,options:n,onProgress:n?.onProgress,serverTiming:i,headers:o,requestedMimeTypes:c};this.log.trace('finding handler for cid code "0x%s" and response content types %s',l.terminalElement.cid.code.toString(16),u.map(h=>h.contentType.mediaType).join(", "));let f=await this.runPluginPipeline(d);return n?.onProgress?.(new M("verified-fetch:request:end",{cid:l.terminalElement.cid,path:l.url.pathname})),f==null&&this.log.error("no plugin could handle request for %s",e),this.handleFinalResponse(f,!!n?.withServerTiming||!!this.withServerTiming,d)}catch(n){return this.log.error("error fetching resource %s - %e",e,n),this.handleFinalResponse(uL(e,n,t))}}getAcceptHeader(e,t,n){let o=uk(e.protocol,n),i=[];for(let s of t){let[a,c]=s.mediaType.split("/");for(let l of o){let[u,d]=l.mediaType.split("/");s.mediaType.includes(l.mediaType)&&i.push({contentType:l,options:s.options}),s.mediaType==="*/*"&&i.push({contentType:l,options:s.options}),s.mediaType.startsWith("*/")&&d===c&&i.push({contentType:l,options:s.options}),s.mediaType.endsWith("/*")&&u===a&&i.push({contentType:l,options:s.options})}}return i.length===0?(this.log("requested %o",t.map(({mediaType:s})=>s)),this.log("supported %o",o.map(({mediaType:s})=>s)),is(e,t,o)):i}parseResource(e){return(yt(e)||Zf(e))&&(e=`/ipns/${e}`),(F.asCID(e)===e||e instanceof F)&&(e=`/ipfs/${e}`),new URL(hL(e.toString()))}handleFinalResponse(e,t,n){let o=lk(e.headers.get("content-type"))??qg;if(t===!0&&n?.serverTiming!=null){let i=n?.serverTiming.getHeader();i!==""&&e.headers.set("server-timing",i)}if(n?.url?.protocol!=null&&n.ttl!=null&&pk({response:e,ttl:n.ttl,protocol:n.url.protocol}),n?.terminalElement.cid!=null){let i=decodeURI(n?.url.pathname),s=R(E(i),"ascii");e.headers.set("x-ipfs-path",`/${n.url.protocol==="ipfs:"?"ipfs":"ipns"}/${n?.url.hostname}${s==="/"?"":s}`)}if(e.headers.set("access-control-allow-origin","*"),e.headers.set("access-control-allow-methods","GET, HEAD, OPTIONS"),e.headers.set("access-control-allow-headers","Content-Type, Range, User-Agent, X-Requested-With"),e.headers.set("access-control-expose-headers","Content-Range, Content-Length, X-Ipfs-Path, X-Ipfs-Roots, X-Chunked-Output, X-Stream-Output"),n?.terminalElement.cid!=null&&e.headers.get("etag")==null){let i=dL({cid:n.terminalElement.cid,contentType:o,ranges:n?.range?.ranges});if(e.headers.set("etag",i),Sw(i,n?.headers))return C7(e.url,e.headers)}return n?.options?.method==="HEAD"?new Response(null,{status:200,headers:e.headers}):(e.status>399&&e.headers.delete("content-disposition"),e)}async runPluginPipeline(e){let t,n=new Set;this.log.trace("checking which plugins can handle %c%s with accept %s",e.terminalElement.cid,e.url.pathname,e.accept.map(a=>a.contentType.mediaType).join(", "));let o=this.plugins.filter(a=>!n.has(a.id)).filter(a=>a.canHandle(e));if(o.length===0)return this.log.trace("no plugins found that can handle request; exiting pipeline"),T7(e.resource);this.log.trace("plugins ready to handle request: %s",o.map(a=>a.id).join(", "));let i=!1,s=!1;for(let a of o){this.log("invoking plugin: %s",a.id),n.add(a.id);let c=await a.handle(e);if(this.log("plugin response %s %o",a.id,c),c!=null){t=c,s=!0;break}if(t!=null){this.log.trace("plugin %s produced final response",a.id);break}if(s&&t!=null)break;if(!i){this.log.trace("no context changes and no final response; exiting pipeline.");break}}return t??T7(e.resource,JSON.stringify({error:va(new Error("No verified fetch plugin could handle the request"))}),{headers:{"content-type":"application/json"}})}async start(){await this.helia.start()}async stop(){await this.helia.stop()}};function _j(r,e){return(e==null||e==="")&&(e="*/*"),e.split(",").map(t=>{let n=t.trim().split(";"),o={q:"1"};for(let i=1;i<n.length;i++){let[s,a]=n[i].split("=").map(c=>c.trim());o[s]=a}return{mediaType:`${n[0]}`.trim(),options:o}}).sort((t,n)=>t.options.q===n.options.q?0:t.options.q>n.options.q?-1:1)}var qf,L3=async function(e,t){return qf==null&&(qf=await Tw()),qf(e,t)};L3.start=async function(){await qf?.start()};L3.stop=async function(){await qf?.stop()};async function Tw(r,e){let t;if(!Cj(r)){let n=Ij(r?.dnsResolvers),o=rI();o.dns=n;let i=r?.routers??["https://delegated-ipfs.dev"];for(let c=0;c<i.length;c++)o.services[`delegatedRouting${c}`]=U1({url:i[c]});r?.libp2pConfig!=null&&Object.assign(o,r.libp2pConfig),t=await Rm(o);let s=[ud()],a=[wd(t)];(r?.gateways==null||r.gateways.length>0)&&(s.push(pd({allowInsecure:r?.allowInsecure,allowLocal:r?.allowLocal})),a.push(yd({gateways:r?.gateways??["https://trustless-gateway.link"]}))),r=await tI({libp2p:t,blockBrokers:s,dns:n,routers:a,hashers:r?.hashers}),r.logger.forComponent("helia:verified-fetch").trace("created verified-fetch with libp2p config: %j",o)}return pL(r,e)}async function pL(r,e){let t=new D3(r,e);async function n(o,i){return t.fetch(o,i)}return n.start=t.start.bind(t),n.stop=t.stop.bind(t),n}function Cj(r){return r?.blockstore!=null&&r?.datastore!=null&&r?.gc!=null&&r?.stop!=null&&r?.start!=null}function Ij(r){if(r!=null)return Array.isArray(r)?Gs({resolvers:{".":r}}):Gs({resolvers:r})}return xL(kj);})();
|